refactor
This commit is contained in:
26
.gitignore
vendored
Normal file
26
.gitignore
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
replay_pid*
|
||||||
|
|
||||||
|
.idea
|
4
Plugins[Modified]/Mineplex.Bungee.Mineplexer/plugin.yml
Normal file
4
Plugins[Modified]/Mineplex.Bungee.Mineplexer/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name: Mineplexer
|
||||||
|
main: mineplex.bungee.Mineplexer
|
||||||
|
version: 1
|
||||||
|
author: defek7
|
37
Plugins[Modified]/Mineplex.Bungee.Mineplexer/pom.xml
Normal file
37
Plugins[Modified]/Mineplex.Bungee.Mineplexer/pom.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mineplex</groupId>
|
||||||
|
<artifactId>mineplex-plugin</artifactId>
|
||||||
|
<version>dev-SNAPSHOT</version>
|
||||||
|
<relativePath>../plugin.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>Mineplexer</name>
|
||||||
|
<artifactId>mineplex-bungee-mineplexer</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-cache</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-serverdata</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-proxy</artifactId>
|
||||||
|
<version>1.4.7-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,171 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
|
public class FileUpdater implements Runnable
|
||||||
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
|
private HashMap<String, String> _jarMd5Map = new HashMap<String, String>();
|
||||||
|
|
||||||
|
private boolean _needUpdate;
|
||||||
|
private boolean _enabled = true;
|
||||||
|
private int _timeTilRestart = 5;
|
||||||
|
|
||||||
|
public FileUpdater(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
getPluginMd5s();
|
||||||
|
|
||||||
|
if (new File("IgnoreUpdates.dat").exists())
|
||||||
|
_enabled = false;
|
||||||
|
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 2L, 2L, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkForNewFiles()
|
||||||
|
{
|
||||||
|
if (_needUpdate || !_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean windows = System.getProperty("os.name").startsWith("Windows");
|
||||||
|
|
||||||
|
File updateDir = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update");
|
||||||
|
|
||||||
|
updateDir.mkdirs();
|
||||||
|
|
||||||
|
FilenameFilter statsFilter = new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File paramFile, String paramString)
|
||||||
|
{
|
||||||
|
if (paramString.endsWith("jar"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (File f : updateDir.listFiles(statsFilter))
|
||||||
|
{
|
||||||
|
FileInputStream fis = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_jarMd5Map.containsKey(f.getName()))
|
||||||
|
{
|
||||||
|
fis = new FileInputStream(f);
|
||||||
|
String md5 = DigestUtils.md5Hex(fis);
|
||||||
|
|
||||||
|
if (!md5.equals(_jarMd5Map.get(f.getName())))
|
||||||
|
{
|
||||||
|
System.out.println(f.getName() + " old jar : " + _jarMd5Map.get(f.getName()));
|
||||||
|
System.out.println(f.getName() + " new jar : " + md5);
|
||||||
|
_needUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fis != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getPluginMd5s()
|
||||||
|
{
|
||||||
|
File pluginDir = new File("plugins");
|
||||||
|
|
||||||
|
pluginDir.mkdirs();
|
||||||
|
|
||||||
|
FilenameFilter statsFilter = new FilenameFilter()
|
||||||
|
{
|
||||||
|
public boolean accept(File paramFile, String paramString)
|
||||||
|
{
|
||||||
|
if (paramString.endsWith("jar"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (File f : pluginDir.listFiles(statsFilter))
|
||||||
|
{
|
||||||
|
FileInputStream fis = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fis = new FileInputStream(f);
|
||||||
|
_jarMd5Map.put(f.getName(), DigestUtils.md5Hex(fis));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (fis != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
checkForNewFiles();
|
||||||
|
|
||||||
|
if (_needUpdate)
|
||||||
|
{
|
||||||
|
BungeeCord.getInstance().broadcast(ChatColor.RED + "Connection Node" + ChatColor.DARK_GRAY + ">" + ChatColor.YELLOW + "This connection node will be restarting in " + _timeTilRestart + " minutes.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_timeTilRestart -= 2;
|
||||||
|
|
||||||
|
if (_timeTilRestart < 0 || !_enabled)
|
||||||
|
{
|
||||||
|
BungeeCord.getInstance().stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import mineplex.bungee.lobbyBalancer.LobbyBalancer;
|
||||||
|
import mineplex.bungee.motd.MotdManager;
|
||||||
|
import mineplex.bungee.playerCount.PlayerCount;
|
||||||
|
import mineplex.bungee.playerStats.PlayerStats;
|
||||||
|
import mineplex.bungee.playerTracker.PlayerTracker;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
public class Mineplexer extends Plugin
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
new MotdManager(this);
|
||||||
|
new LobbyBalancer(this);
|
||||||
|
new PlayerCount(this);
|
||||||
|
new FileUpdater(this);
|
||||||
|
new PlayerStats(this);
|
||||||
|
new PlayerTracker(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,131 @@
|
|||||||
|
package mineplex.bungee.lobbyBalancer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.MinecraftServer;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import mineplex.serverdata.servers.ServerRepository;
|
||||||
|
|
||||||
|
public class LobbyBalancer implements Listener, Runnable
|
||||||
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
|
private ServerRepository _repository;
|
||||||
|
|
||||||
|
private final Map<LobbyType, List<MinecraftServer>> _sortedLobbyMap = new EnumMap<>(LobbyType.class);
|
||||||
|
private final Map<LobbyType, Integer> _nextIndexMap = new EnumMap<>(LobbyType.class);
|
||||||
|
private static final LobbySorter LOBBY_SORTER = new LobbySorter();
|
||||||
|
private static final Object _serverLock = new Object();
|
||||||
|
|
||||||
|
public LobbyBalancer(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||||
|
_repository = ServerManager.getServerRepository(region);
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(ServerConnectEvent event)
|
||||||
|
{
|
||||||
|
Arrays.stream(LobbyType.values())
|
||||||
|
.filter(type -> type.getConnectName().equalsIgnoreCase(event.getTarget().getName()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(lobbyType ->
|
||||||
|
{
|
||||||
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
List<MinecraftServer> lobbies = _sortedLobbyMap.get(lobbyType);
|
||||||
|
|
||||||
|
int nextIndex = _nextIndexMap.getOrDefault(lobbyType, 0);
|
||||||
|
if (nextIndex >= lobbies.size())
|
||||||
|
{
|
||||||
|
nextIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MinecraftServer server = lobbies.get(nextIndex);
|
||||||
|
|
||||||
|
event.setTarget(_plugin.getProxy().getServerInfo(server.getName()));
|
||||||
|
server.incrementPlayerCount(1);
|
||||||
|
System.out.println("Sending " + event.getPlayer().getName() + " to " + server.getName() + "(" + server.getPublicAddress() + ")");
|
||||||
|
|
||||||
|
_nextIndexMap.put(lobbyType, ++nextIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
loadServers();
|
||||||
|
|
||||||
|
for (LobbyType type : LobbyType.values())
|
||||||
|
{
|
||||||
|
if (!_plugin.getProxy().getServers().containsKey(type.getConnectName()))
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getServers().put(type.getConnectName(), _plugin.getProxy().constructServerInfo(type.getConnectName(), new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadServers()
|
||||||
|
{
|
||||||
|
Collection<MinecraftServer> servers = _repository.getServerStatuses();
|
||||||
|
|
||||||
|
synchronized (_serverLock)
|
||||||
|
{
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
_sortedLobbyMap.clear();
|
||||||
|
for (LobbyType type : LobbyType.values())
|
||||||
|
{
|
||||||
|
_sortedLobbyMap.put(type, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MinecraftServer server : servers)
|
||||||
|
{
|
||||||
|
if (server.getName() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
InetSocketAddress socketAddress = new InetSocketAddress(server.getPublicAddress(), server.getPort());
|
||||||
|
_plugin.getProxy().getServers().put(server.getName(), _plugin.getProxy().constructServerInfo(server.getName(), socketAddress, "LobbyBalancer", false));
|
||||||
|
|
||||||
|
if (server.getMotd() != null && server.getMotd().contains("Restarting"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Arrays.stream(LobbyType.values())
|
||||||
|
.filter(type -> server.getName().toUpperCase().startsWith(type.getUppercasePrefix()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(type -> _sortedLobbyMap.get(type).add(server));
|
||||||
|
}
|
||||||
|
|
||||||
|
_sortedLobbyMap.values().forEach(lobbies -> Collections.sort(lobbies, LOBBY_SORTER));
|
||||||
|
|
||||||
|
long timeSpentInLock = System.currentTimeMillis() - startTime;
|
||||||
|
|
||||||
|
if (timeSpentInLock > 50)
|
||||||
|
System.out.println("[==] TIMING [==] Locked loading servers for " + timeSpentInLock + "ms");
|
||||||
|
|
||||||
|
_nextIndexMap.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package mineplex.bungee.lobbyBalancer;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import mineplex.serverdata.data.MinecraftServer;
|
||||||
|
|
||||||
|
public class LobbySorter implements Comparator<MinecraftServer>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public int compare(MinecraftServer first, MinecraftServer second)
|
||||||
|
{
|
||||||
|
if (second.getPlayerCount() == 999)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (first.getPlayerCount() == 999)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (first.getPlayerCount() < (first.getMaxPlayerCount() / 2) && second.getPlayerCount() >= (second.getMaxPlayerCount() / 2))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (second.getPlayerCount() < (second.getMaxPlayerCount() / 2) && first.getPlayerCount() >= (first.getMaxPlayerCount() / 2))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (first.getPlayerCount() < (first.getMaxPlayerCount() / 2))
|
||||||
|
{
|
||||||
|
if (first.getPlayerCount() > second.getPlayerCount())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (second.getPlayerCount() > first.getPlayerCount())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (first.getPlayerCount() < second.getPlayerCount())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (second.getPlayerCount() < first.getPlayerCount())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Integer.parseInt(first.getName().split("-")[1]) < Integer.parseInt(second.getName().split("-")[1]))
|
||||||
|
return -1;
|
||||||
|
else if (Integer.parseInt(second.getName().split("-")[1]) < Integer.parseInt(first.getName().split("-")[1]))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package mineplex.bungee.lobbyBalancer;
|
||||||
|
|
||||||
|
public enum LobbyType
|
||||||
|
{
|
||||||
|
NORMAL("Lobby", "LOBBY-", "MainMotd"),
|
||||||
|
CLANS("ClansHub", "CLANSHUB-", "ClansMotd"),
|
||||||
|
BETA("BetaHub","BETAHUB-", "BetaMotd"),
|
||||||
|
;
|
||||||
|
private final String _connectName; // The name of the server the player is connecting to
|
||||||
|
private final String _uppercasePrefix; // The (toUpperCase()) prefix given to servers of this lobby type
|
||||||
|
private final String _redisMotdKey;
|
||||||
|
|
||||||
|
LobbyType(String connectName, String uppercasePrefix, String redisMotdKey)
|
||||||
|
{
|
||||||
|
_connectName = connectName;
|
||||||
|
_uppercasePrefix = uppercasePrefix;
|
||||||
|
_redisMotdKey = redisMotdKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConnectName()
|
||||||
|
{
|
||||||
|
return _connectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUppercasePrefix()
|
||||||
|
{
|
||||||
|
return _uppercasePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRedisMotdKey()
|
||||||
|
{
|
||||||
|
return _redisMotdKey;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package mineplex.bungee.motd;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import mineplex.serverdata.data.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GlobalMotd represents a set of MOTD packaged lines.
|
||||||
|
* @author MrTwiggy
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GlobalMotd implements Data
|
||||||
|
{
|
||||||
|
// The unique name representing this MOTD set
|
||||||
|
private String _name;
|
||||||
|
|
||||||
|
private String _headline;
|
||||||
|
public String getHeadline() { return _headline; }
|
||||||
|
|
||||||
|
// List of lines describing the MOTD
|
||||||
|
private List<String> _motd;
|
||||||
|
public List<String> getMotd() { return _motd; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param name
|
||||||
|
* @param motd
|
||||||
|
*/
|
||||||
|
public GlobalMotd(String name, String headline, List<String> motd)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
_headline = headline;
|
||||||
|
_motd = motd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique identifying ID associated with this {@link GlobalMotd}.
|
||||||
|
*/
|
||||||
|
public String getDataId()
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package mineplex.bungee.motd;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import mineplex.bungee.lobbyBalancer.LobbyType;
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
|
||||||
|
public class MotdManager implements Listener, Runnable
|
||||||
|
{
|
||||||
|
private static final String DEFAULT_HEADLINE = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
|
||||||
|
|
||||||
|
private final DataRepository<GlobalMotd> _repository;
|
||||||
|
private final Random _random = new Random();
|
||||||
|
private final Map<LobbyType, GlobalMotd> motds = new EnumMap<>(LobbyType.class);
|
||||||
|
|
||||||
|
public MotdManager(Plugin plugin)
|
||||||
|
{
|
||||||
|
plugin.getProxy().getScheduler().schedule(plugin, this, 5L, 30L, TimeUnit.SECONDS);
|
||||||
|
plugin.getProxy().getPluginManager().registerListener(plugin, this);
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<GlobalMotd>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
|
||||||
|
Region.ALL, GlobalMotd.class, "globalMotd");
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void serverPing(ProxyPingEvent event)
|
||||||
|
{
|
||||||
|
|
||||||
|
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
||||||
|
Optional<LobbyType> maybeType = Optional.empty();
|
||||||
|
|
||||||
|
if (event.getConnection().getListener() != null)
|
||||||
|
{
|
||||||
|
maybeType = Arrays.stream(LobbyType.values())
|
||||||
|
.filter(type -> event.getConnection().getListener().getDefaultServer().equalsIgnoreCase(type.getConnectName()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
LobbyType lobbyType = maybeType.orElse(LobbyType.NORMAL);
|
||||||
|
GlobalMotd globalMotd = motds.get(lobbyType);
|
||||||
|
|
||||||
|
String motd = DEFAULT_HEADLINE;
|
||||||
|
if (globalMotd != null && globalMotd.getHeadline() != null)
|
||||||
|
{
|
||||||
|
motd = globalMotd.getHeadline() == null ? DEFAULT_HEADLINE : globalMotd.getHeadline();
|
||||||
|
if (globalMotd.getMotd() != null)
|
||||||
|
{
|
||||||
|
motd += "\n" + globalMotd.getMotd().get(_random.nextInt(globalMotd.getMotd().size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
for (LobbyType type : LobbyType.values())
|
||||||
|
{
|
||||||
|
GlobalMotd motd = _repository.getElement(type.getRedisMotdKey());
|
||||||
|
|
||||||
|
if (motd != null)
|
||||||
|
{
|
||||||
|
motds.put(type, motd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
package mineplex.bungee.playerCount;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import mineplex.bungee.status.InternetStatus;
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ConnectionData;
|
||||||
|
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import net.md_5.bungee.api.ServerPing.Players;
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class PlayerCount implements Listener, Runnable
|
||||||
|
{
|
||||||
|
private DataRepository<BungeeServer> _repository;
|
||||||
|
private DataRepository<BungeeServer> _secondRepository;
|
||||||
|
private Region _region;
|
||||||
|
|
||||||
|
private ListenerInfo _listenerInfo;
|
||||||
|
private Plugin _plugin;
|
||||||
|
|
||||||
|
private int _totalPlayers = -1;
|
||||||
|
|
||||||
|
public PlayerCount(Plugin plugin)
|
||||||
|
{
|
||||||
|
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 4L, 4L, TimeUnit.SECONDS);
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
|
for (ListenerInfo info : _plugin.getProxy().getConfigurationAdapter().getListeners())
|
||||||
|
{
|
||||||
|
if (info.getDefaultServer().equalsIgnoreCase("Lobby"))
|
||||||
|
{
|
||||||
|
_listenerInfo = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
if (_region == Region.US)
|
||||||
|
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
else
|
||||||
|
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
BungeeServer snapshot = generateSnapshot();
|
||||||
|
if (snapshot != null)
|
||||||
|
{
|
||||||
|
_repository.addElement(snapshot, 15); // Update with a 15 second expiry on session
|
||||||
|
}
|
||||||
|
|
||||||
|
_totalPlayers = fetchPlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an up-to-date total player count across all active Bungee Servers.
|
||||||
|
*/
|
||||||
|
private int fetchPlayerCount()
|
||||||
|
{
|
||||||
|
int totalPlayers = 0;
|
||||||
|
for (BungeeServer server : _repository.getElements())
|
||||||
|
{
|
||||||
|
totalPlayers += server.getPlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BungeeServer server : _secondRepository.getElements())
|
||||||
|
{
|
||||||
|
totalPlayers += server.getPlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a newly instantiated {@link BungeeServer} snapshot of the current state of this server.
|
||||||
|
*/
|
||||||
|
private BungeeServer generateSnapshot()
|
||||||
|
{
|
||||||
|
if (_listenerInfo == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String name = _listenerInfo.getHost().getAddress().getHostAddress();
|
||||||
|
String host = _listenerInfo.getHost().getAddress().getHostAddress();
|
||||||
|
int port = _listenerInfo.getHost().getPort();
|
||||||
|
boolean connected = InternetStatus.isConnected();
|
||||||
|
int playerCount = _plugin.getProxy().getOnlineCount();
|
||||||
|
return new BungeeServer(name, _region, host, port, playerCount, connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void ServerPing(ProxyPingEvent event)
|
||||||
|
{
|
||||||
|
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
||||||
|
|
||||||
|
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalPlayers + 1, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalPlayers()
|
||||||
|
{
|
||||||
|
return _totalPlayers;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,141 @@
|
|||||||
|
package mineplex.bungee.playerStats;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import mineplex.bungee.playerStats.data.IpInfo;
|
||||||
|
import mineplex.cache.player.PlayerCache;
|
||||||
|
import mineplex.cache.player.PlayerInfo;
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class PlayerStats implements Listener, Runnable
|
||||||
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
|
private PlayerStatsRepository _repository;
|
||||||
|
|
||||||
|
private HashSet<UUID> _retrievingPlayerInfo = new HashSet<UUID>();
|
||||||
|
|
||||||
|
public PlayerStats(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES);
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
|
_repository = new PlayerStatsRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(final PostLoginEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
String address = event.getPlayer().getPendingConnection().getAddress().getAddress().getHostAddress();
|
||||||
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
String name = event.getPlayer().getName();
|
||||||
|
int version = event.getPlayer().getPendingConnection().getVersion();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PlayerInfo playerInfo = null;
|
||||||
|
IpInfo ipInfo = _repository.getIp(address);
|
||||||
|
|
||||||
|
boolean addOrUpdatePlayer = false;
|
||||||
|
|
||||||
|
playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||||
|
|
||||||
|
if (playerInfo == null)
|
||||||
|
{
|
||||||
|
addOrUpdatePlayer = true;
|
||||||
|
_retrievingPlayerInfo.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addOrUpdatePlayer)
|
||||||
|
{
|
||||||
|
if (playerInfo.getVersion() != version)
|
||||||
|
addOrUpdatePlayer = true;
|
||||||
|
else if (!playerInfo.getName().equalsIgnoreCase(name))
|
||||||
|
addOrUpdatePlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addOrUpdatePlayer)
|
||||||
|
{
|
||||||
|
// Just update? what about other properties?
|
||||||
|
PlayerInfo updatedPlayerInfo = _repository.getPlayer(uuid, name, version);
|
||||||
|
|
||||||
|
if (playerInfo != null)
|
||||||
|
{
|
||||||
|
playerInfo.setName(updatedPlayerInfo.getName());
|
||||||
|
playerInfo.setVersion(updatedPlayerInfo.getVersion());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
playerInfo = updatedPlayerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
playerInfo.setSessionId(_repository.updatePlayerStats(playerInfo.getId(), ipInfo.id));
|
||||||
|
playerInfo.updateLoginTime();
|
||||||
|
PlayerCache.getInstance().addPlayer(playerInfo);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_retrievingPlayerInfo.remove(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerDisconnect(final PlayerDisconnectEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = null;
|
||||||
|
|
||||||
|
playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||||
|
|
||||||
|
int timeout = 5;
|
||||||
|
|
||||||
|
while (playerInfo == null && _retrievingPlayerInfo.contains(uuid) && timeout <= 5)
|
||||||
|
{
|
||||||
|
playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||||
|
|
||||||
|
if (playerInfo != null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
System.out.println("ERROR - Player disconnecting and isn't in cache... sleeping");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout++;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(playerInfo.getName() + ":" + playerInfo.getSessionId());
|
||||||
|
_repository.updatePlayerSession(playerInfo.getSessionId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
PlayerCache.getInstance().clean();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,295 @@
|
|||||||
|
package mineplex.bungee.playerStats;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mineplex.bungee.playerStats.data.IpInfo;
|
||||||
|
import mineplex.cache.player.PlayerInfo;
|
||||||
|
import mineplex.serverdata.database.DBPool;
|
||||||
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
public class PlayerStatsRepository extends RepositoryBase
|
||||||
|
{
|
||||||
|
private static String INSERT_PLAYERINFO = "INSERT INTO playerInfo (uuid, name, version) VALUES (?, ?, ?);";
|
||||||
|
private static String SELECT_PLAYERINFO = "SELECT id, name, version FROM playerInfo WHERE uuid = ?;";
|
||||||
|
private static String UPDATE_PLAYERINFO = "UPDATE playerInfo SET name = ?, version = ? WHERE id = ?;";
|
||||||
|
|
||||||
|
private static String INSERT_IPINFO = "INSERT INTO ipInfo (ipAddress) VALUES (?);";
|
||||||
|
private static String SELECT_IPINFO = "SELECT id FROM ipInfo WHERE ipAddress = ?;";
|
||||||
|
|
||||||
|
private static String UPDATE_PLAYERSTATS = "INSERT IGNORE INTO playerIps (playerInfoId, ipInfoId, date) VALUES (?, ?, curdate());"
|
||||||
|
+ "INSERT IGNORE INTO playerUniqueLogins (playerInfoId, day) values(?, curdate());"
|
||||||
|
+ "INSERT IGNORE INTO playerLoginSessions (playerInfoId, loginTime) values(?, now());";
|
||||||
|
|
||||||
|
private static String UPDATE_LOGINSESSION = "UPDATE playerLoginSessions SET timeInGame = TIME_TO_SEC(TIMEDIFF(now(), loginTime)) / 60 WHERE id = ?;";
|
||||||
|
|
||||||
|
public PlayerStatsRepository()
|
||||||
|
{
|
||||||
|
super(DBPool.getPlayerStats());
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerInfo getPlayer(UUID uuid, String name, int version)
|
||||||
|
{
|
||||||
|
PlayerInfo playerInfo = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(SELECT_PLAYERINFO);
|
||||||
|
|
||||||
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
playerInfo = new PlayerInfo(resultSet.getInt(1), uuid, resultSet.getString(2), resultSet.getInt(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
|
||||||
|
if (playerInfo == null)
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS);
|
||||||
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
preparedStatement.setString(2, name);
|
||||||
|
preparedStatement.setInt(3, version);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
resultSet = preparedStatement.getGeneratedKeys();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
id = resultSet.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
playerInfo = new PlayerInfo(id, uuid, name, version);
|
||||||
|
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
else if (!playerInfo.getName().equalsIgnoreCase(name) || playerInfo.getVersion() != version)
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(UPDATE_PLAYERINFO);
|
||||||
|
preparedStatement.setString(1, name);
|
||||||
|
preparedStatement.setInt(2, version);
|
||||||
|
preparedStatement.setInt(3, playerInfo.getId());
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultSet != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IpInfo getIp(String ipAddress)
|
||||||
|
{
|
||||||
|
IpInfo ipInfo = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(SELECT_IPINFO);
|
||||||
|
preparedStatement.setString(1, ipAddress);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
ipInfo = new IpInfo();
|
||||||
|
ipInfo.id = resultSet.getInt(1);
|
||||||
|
ipInfo.ipAddress = ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
|
||||||
|
if (ipInfo == null)
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS);
|
||||||
|
preparedStatement.setString(1, ipAddress);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
resultSet = preparedStatement.getGeneratedKeys();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
id = resultSet.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipInfo = new IpInfo();
|
||||||
|
ipInfo.id = id;
|
||||||
|
ipInfo.ipAddress = ipAddress;
|
||||||
|
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultSet != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int updatePlayerStats(int playerId, int ipId)
|
||||||
|
{
|
||||||
|
Statement statement = null;
|
||||||
|
ResultSet resultSet= null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
statement = connection.createStatement();
|
||||||
|
|
||||||
|
String queryString = UPDATE_PLAYERSTATS;
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", ipId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
|
||||||
|
statement.executeUpdate(queryString, Statement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
|
statement.getMoreResults();
|
||||||
|
statement.getMoreResults();
|
||||||
|
resultSet = statement.getGeneratedKeys();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
return resultSet.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (statement != null)
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (resultSet != null)
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePlayerSession(int loginSessionId)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(UPDATE_LOGINSESSION);
|
||||||
|
preparedStatement.setInt(1, loginSessionId);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package mineplex.bungee.playerStats.data;
|
||||||
|
|
||||||
|
public class IpInfo
|
||||||
|
{
|
||||||
|
public int id;
|
||||||
|
public String ipAddress;
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
|
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||||
|
import mineplex.serverdata.commands.ServerCommand;
|
||||||
|
|
||||||
|
public class PlayerJoinHandler implements CommandCallback
|
||||||
|
{
|
||||||
|
private PlayerTracker _playerTracker;
|
||||||
|
|
||||||
|
public PlayerJoinHandler(PlayerTracker playerTracker)
|
||||||
|
{
|
||||||
|
_playerTracker = playerTracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ServerCommand command)
|
||||||
|
{
|
||||||
|
if (command instanceof PlayerJoinCommand)
|
||||||
|
{
|
||||||
|
PlayerJoinCommand joinCommand = (PlayerJoinCommand)command;
|
||||||
|
_playerTracker.kickPlayerIfOnline(UUID.fromString(joinCommand.getUuid()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||||
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.data.PlayerStatus;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
|
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class PlayerTracker implements Listener
|
||||||
|
{
|
||||||
|
// Default period before status expiry (8 hours)
|
||||||
|
private static final int DEFAULT_STATUS_TIMEOUT = 60 * 60 * 8;
|
||||||
|
|
||||||
|
// Repository storing player status' across network.
|
||||||
|
private DataRepository<PlayerStatus> _repository;
|
||||||
|
|
||||||
|
private Plugin _plugin;
|
||||||
|
|
||||||
|
private final List<UUID> _ignoreKick = Lists.newArrayList();
|
||||||
|
|
||||||
|
public PlayerTracker(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
|
Region.currentRegion(), PlayerStatus.class, "playerStatus");
|
||||||
|
|
||||||
|
ServerCommandManager.getInstance().initializeServer("BUNGEE ENABLE - " + System.currentTimeMillis(), new Gson());
|
||||||
|
ServerCommandManager.getInstance().registerCommandType(mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
|
||||||
|
|
||||||
|
System.out.println("Initialized PlayerTracker.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return _plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(final ServerConnectedEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
PlayerStatus snapshot = new PlayerStatus(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getServer().getInfo().getName());
|
||||||
|
_repository.addElement(snapshot, DEFAULT_STATUS_TIMEOUT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerDisconnect(final PlayerDisconnectEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_repository.removeElement(event.getPlayer().getUniqueId().toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(final PostLoginEvent event)
|
||||||
|
{
|
||||||
|
_ignoreKick.add(event.getPlayer().getUniqueId());
|
||||||
|
PlayerJoinCommand command = new PlayerJoinCommand(event.getPlayer().getUniqueId(), event.getPlayer().getName());
|
||||||
|
command.publish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayerOnline(UUID uuid)
|
||||||
|
{
|
||||||
|
return _plugin.getProxy().getPlayer(uuid) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void kickPlayerIfOnline(UUID uuid)
|
||||||
|
{
|
||||||
|
if (_ignoreKick.remove(uuid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPlayerOnline(uuid))
|
||||||
|
{
|
||||||
|
ProxiedPlayer player = _plugin.getProxy().getPlayer(uuid);
|
||||||
|
|
||||||
|
player.disconnect(new TextComponent("You have logged in from another location."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package mineplex.bungee.status;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
public class InternetStatus implements Runnable
|
||||||
|
{
|
||||||
|
// Current internet connectivity status
|
||||||
|
private static boolean _connected = true;
|
||||||
|
public static boolean isConnected() { return _connected; }
|
||||||
|
|
||||||
|
private Plugin _plugin;
|
||||||
|
|
||||||
|
public InternetStatus(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
System.out.println("Initialized InternetStatus.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_connected = isOnline(); // Update _connected flag.
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOnline()
|
||||||
|
{
|
||||||
|
return testUrl("www.google.com")
|
||||||
|
|| testUrl("www.espn.com")
|
||||||
|
|| testUrl("www.bing.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean testUrl(String url)
|
||||||
|
{
|
||||||
|
boolean reachable = false;
|
||||||
|
|
||||||
|
try (Socket socket = new Socket(url, 80))
|
||||||
|
{
|
||||||
|
reachable = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Meh i don't care
|
||||||
|
}
|
||||||
|
|
||||||
|
return reachable;
|
||||||
|
}
|
||||||
|
}
|
74
Plugins[Modified]/Mineplex.BungeeRotator/pom.xml
Normal file
74
Plugins[Modified]/Mineplex.BungeeRotator/pom.xml
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mineplex</groupId>
|
||||||
|
<artifactId>mineplex-app</artifactId>
|
||||||
|
<version>dev-SNAPSHOT</version>
|
||||||
|
<relativePath>../app.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>BungeeRotator</name>
|
||||||
|
<artifactId>mineplex-bungeerotator</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-serverdata</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>mineplex.bungee.BungeeRotator</Main-Class>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<minimizeJar>true</minimizeJar>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>org.apache.commons:commons-pool2</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>commons-logging:commons-logging</artifact>
|
||||||
|
<includes>
|
||||||
|
<include>**</include>
|
||||||
|
</includes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,308 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import mineplex.bungee.api.ApiDeleteCall;
|
||||||
|
import mineplex.bungee.api.ApiGetCall;
|
||||||
|
import mineplex.bungee.api.ApiPostCall;
|
||||||
|
import mineplex.bungee.api.HttpCallBase;
|
||||||
|
import mineplex.bungee.api.token.ARecord;
|
||||||
|
import mineplex.bungee.api.token.DnsRecord;
|
||||||
|
import mineplex.bungee.api.token.DomainRecords;
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ConnectionData;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
|
||||||
|
|
||||||
|
public class BungeeRotator
|
||||||
|
{
|
||||||
|
private static DataRepository<BungeeServer> _repository;
|
||||||
|
private static DataRepository<BungeeServer> _secondRepository;
|
||||||
|
private static PlayerStatsRepository _ipRepository;
|
||||||
|
//private static ServerRepository _repository = null;
|
||||||
|
|
||||||
|
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||||
|
private static Logger _logger = Logger.getLogger("BungeeRotator");
|
||||||
|
private static boolean _debug = false;
|
||||||
|
|
||||||
|
public static void main(String args[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileHandler fileHandler = new FileHandler("rotator.log", true);
|
||||||
|
fileHandler.setFormatter(new Formatter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record)
|
||||||
|
{
|
||||||
|
return record.getMessage() + "\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_logger.addHandler(fileHandler);
|
||||||
|
_logger.setUseParentHandlers(false);
|
||||||
|
}
|
||||||
|
catch (SecurityException | IOException e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
String username = "mineplex";
|
||||||
|
String password = "gjxcVf%nk.";
|
||||||
|
String accountId = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
UltraAPIClient ultraAPIClient = new UltraAPIClientImpl(username, password);
|
||||||
|
System.out.println(ultraAPIClient.getNeustarNetworkStatus());
|
||||||
|
AccountDetailsList accountDetailsForUser = ultraAPIClient.getAccountDetailsForUser();
|
||||||
|
System.out.println(accountDetailsForUser.getAccountDetailsData().get(0).getAccountID());
|
||||||
|
if (accountId == null) {
|
||||||
|
accountId = accountDetailsForUser.getAccountDetailsData().get(0).getAccountID();
|
||||||
|
}
|
||||||
|
String zoneName = RandomStringUtils.randomAlphanumeric(16).toLowerCase()+".com.";
|
||||||
|
try {
|
||||||
|
//System.out.println(ultraAPIClient.deleteZone(zoneName));
|
||||||
|
} catch (UltraAPIException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
if (e.getCode() != 1801) {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(ultraAPIClient.createPrimaryZone(accountId, zoneName));
|
||||||
|
System.out.println(ultraAPIClient.getSecondaryZonesOfAccount(accountId));
|
||||||
|
System.out.println(ultraAPIClient.createARecord(zoneName, "foo."+zoneName, "1.2.3.4", 86400));
|
||||||
|
//System.out.println(ultraAPIClient.deleteZone(zoneName));
|
||||||
|
} catch (UltraAPIException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
_debug = new File("debug.dat").exists();
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
//_ipRepository = new PlayerStatsRepository();
|
||||||
|
|
||||||
|
BungeeSorter bungeeSorter = new BungeeSorter();
|
||||||
|
int maxRecordCount = 10;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>(_repository.getElements());
|
||||||
|
bungeeServers.addAll(_secondRepository.getElements());
|
||||||
|
|
||||||
|
Collections.sort(bungeeServers, bungeeSorter);
|
||||||
|
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
int totalPlayers = 0;
|
||||||
|
int usPlayers = 0;
|
||||||
|
int euPlayers = 0;
|
||||||
|
|
||||||
|
for (BungeeServer server : bungeeServers)
|
||||||
|
{
|
||||||
|
if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1") || server.getPublicAddress().equalsIgnoreCase("0.0.0.0"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
totalPlayers += server.getPlayerCount();
|
||||||
|
|
||||||
|
if (server.getRegion() == Region.US)
|
||||||
|
usPlayers += server.getPlayerCount();
|
||||||
|
else
|
||||||
|
euPlayers += server.getPlayerCount();
|
||||||
|
|
||||||
|
System.out.println(server.getRegion().toString() + " " + server.getName() + " " + server.getPublicAddress() + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("US Players : " + usPlayers);
|
||||||
|
System.out.println("EU Players : " + euPlayers);
|
||||||
|
System.out.println("Total Players : " + totalPlayers);
|
||||||
|
System.out.println("Count : " + bungeeServers.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HashSet<String> usServers = new HashSet<String>();
|
||||||
|
HashSet<String> euServers = new HashSet<String>();
|
||||||
|
|
||||||
|
|
||||||
|
for (BungeeServer server : bungeeServers)
|
||||||
|
{
|
||||||
|
if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (usServers.size() < maxRecordCount && server.getRegion() == Region.US)
|
||||||
|
{
|
||||||
|
if (usServers.size() >= 2 && server.getPlayerCount() > 900)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
log("SELECTED " + server.getPublicAddress() + " " + (server.getRegion() == Region.US ? "us" : "eu") + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
|
||||||
|
usServers.add(server.getPublicAddress());
|
||||||
|
}
|
||||||
|
else if (euServers.size() < maxRecordCount && server.getRegion() != Region.US)
|
||||||
|
{
|
||||||
|
if (euServers.size() >= 2 && server.getPlayerCount() > 900)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
log("SELECTED " + server.getPublicAddress() + " " + (server.getRegion() == Region.US ? "us" : "eu") + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
|
||||||
|
euServers.add(server.getPublicAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728,
|
||||||
|
"/records", "").Execute(DomainRecords.class);
|
||||||
|
List<DnsRecord> recordsToDelete = new ArrayList<DnsRecord>();
|
||||||
|
List<DnsRecord> recordsToAdd = new ArrayList<DnsRecord>();
|
||||||
|
|
||||||
|
for (DnsRecord record : records.data)
|
||||||
|
{
|
||||||
|
if (record.type.equalsIgnoreCase("A"))
|
||||||
|
{
|
||||||
|
if (record.name.equalsIgnoreCase("us"))
|
||||||
|
{
|
||||||
|
if (usServers.contains(record.value))
|
||||||
|
usServers.remove(record.value);
|
||||||
|
else
|
||||||
|
recordsToDelete.add(record);
|
||||||
|
}
|
||||||
|
else if (record.name.equalsIgnoreCase("eu"))
|
||||||
|
{
|
||||||
|
if (euServers.contains(record.value))
|
||||||
|
euServers.remove(record.value);
|
||||||
|
else
|
||||||
|
recordsToDelete.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String address : usServers)
|
||||||
|
{
|
||||||
|
recordsToAdd.add(new ARecord("us", address, 300));
|
||||||
|
log("Adding server address in DNS : " + "us " + address);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordsToAdd.size() > 0)
|
||||||
|
{
|
||||||
|
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
|
||||||
|
log("Created " + recordsToAdd.size() + " records.");
|
||||||
|
}
|
||||||
|
|
||||||
|
recordsToAdd.clear();
|
||||||
|
|
||||||
|
for (String address : euServers)
|
||||||
|
{
|
||||||
|
recordsToAdd.add(new ARecord("eu", address, 300));
|
||||||
|
log("Adding server address in DNS : " + "eu " + address);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordsToAdd.size() > 0)
|
||||||
|
{
|
||||||
|
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
|
||||||
|
log("Created " + recordsToAdd.size() + " records.");
|
||||||
|
}
|
||||||
|
recordsToAdd.clear();
|
||||||
|
|
||||||
|
|
||||||
|
if (recordsToDelete.size() > 0)
|
||||||
|
{
|
||||||
|
StringBuilder idBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for (DnsRecord record : recordsToDelete)
|
||||||
|
{
|
||||||
|
if (idBuilder.length() != 0)
|
||||||
|
idBuilder.append("&");
|
||||||
|
|
||||||
|
idBuilder.append("ids=" + record.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute();
|
||||||
|
log("Deleted " + recordsToDelete.size() + " records.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_repository.clean();
|
||||||
|
_secondRepository.clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
List<IpInfo> updatedAddresses = new ArrayList<IpInfo>(1000);
|
||||||
|
|
||||||
|
for (IpInfo ipInfo : _ipRepository.getIpAddresses())
|
||||||
|
{
|
||||||
|
IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/" + ipInfo.ipAddress).Execute(IPGeoData.class);
|
||||||
|
ipInfo.countryCode = recor.country_code;
|
||||||
|
ipInfo.countryName = recor.country_name;
|
||||||
|
ipInfo.regionCode = recor.region_code;
|
||||||
|
ipInfo.regionName = recor.region_name;
|
||||||
|
ipInfo.city = recor.city;
|
||||||
|
ipInfo.zipCode = recor.zip_code;
|
||||||
|
ipInfo.timeZone = recor.time_zone;
|
||||||
|
ipInfo.latitude = recor.latitude;
|
||||||
|
ipInfo.longitude = recor.longitude;
|
||||||
|
ipInfo.metroCode = recor.metro_code;
|
||||||
|
|
||||||
|
updatedAddresses.add(ipInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ipRepository.updateIps(updatedAddresses);
|
||||||
|
*/
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(15000);
|
||||||
|
log("Natural Sleep");
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
log("Error doing something : " + ex.getMessage());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(String message)
|
||||||
|
{
|
||||||
|
log(message, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(String message, boolean fileOnly)
|
||||||
|
{
|
||||||
|
_logger.info("[" + _dateFormat.format(new Date()) + "] " + message);
|
||||||
|
|
||||||
|
if (!fileOnly)
|
||||||
|
System.out.println("[" + _dateFormat.format(new Date()) + "] " + message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
|
||||||
|
public class BungeeSorter implements Comparator<BungeeServer>
|
||||||
|
{
|
||||||
|
public int compare(BungeeServer a, BungeeServer b)
|
||||||
|
{
|
||||||
|
if (a.getPlayerCount() < b.getPlayerCount())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (b.getPlayerCount() < a.getPlayerCount())
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
public interface GenericRunnable<T>
|
||||||
|
{
|
||||||
|
void run(T t);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
public class IPGeoData
|
||||||
|
{
|
||||||
|
public String ip;
|
||||||
|
public String country_code;
|
||||||
|
public String country_name;
|
||||||
|
public String region_code;
|
||||||
|
public String region_name;
|
||||||
|
public String city;
|
||||||
|
public String zip_code;
|
||||||
|
public String time_zone;
|
||||||
|
public double latitude;
|
||||||
|
public double longitude;
|
||||||
|
public int metro_code;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
public class IpInfo
|
||||||
|
{
|
||||||
|
public int id;
|
||||||
|
public String ipAddress;
|
||||||
|
public String countryCode;
|
||||||
|
public String countryName;
|
||||||
|
public String regionCode;
|
||||||
|
public String regionName;
|
||||||
|
public String city;
|
||||||
|
public String zipCode;
|
||||||
|
public String timeZone;
|
||||||
|
public double latitude;
|
||||||
|
public double longitude;
|
||||||
|
public int metroCode;
|
||||||
|
}
|
@ -0,0 +1,124 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import mineplex.serverdata.database.DBPool;
|
||||||
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlayerStatsRepository extends RepositoryBase
|
||||||
|
{
|
||||||
|
private static String SELECT_IPINFO = "SELECT id, ipAddress FROM ipInfo WHERE regionName IS NULL LIMIT 1000;";
|
||||||
|
private static String UPDATE_IPINFO = "UPDATE ipInfo SET countryCode = ?, countryName = ?, regionCode = ?, regionName = ?, city = ?, zipCode = ?, timeZone = ?, latitude = ?, longitude = ?, metroCode = ? WHERE id = ?;";
|
||||||
|
|
||||||
|
public PlayerStatsRepository()
|
||||||
|
{
|
||||||
|
super(DBPool.getPlayerStats());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IpInfo> getIpAddresses()
|
||||||
|
{
|
||||||
|
List<IpInfo> ipinfos = new ArrayList<IpInfo>(1000);
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(SELECT_IPINFO);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
IpInfo ipInfo = new IpInfo();
|
||||||
|
ipInfo.id = resultSet.getInt(1);
|
||||||
|
ipInfo.ipAddress = resultSet.getString(2);
|
||||||
|
|
||||||
|
ipinfos.add(ipInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
resultSet.close();
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultSet != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipinfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateIps(List<IpInfo> ips)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try(Connection connection = getConnection())
|
||||||
|
{
|
||||||
|
preparedStatement = connection.prepareStatement(UPDATE_IPINFO);
|
||||||
|
|
||||||
|
for (IpInfo ipInfo : ips)
|
||||||
|
{
|
||||||
|
preparedStatement.setString(1, ipInfo.countryCode);
|
||||||
|
preparedStatement.setString(2, ipInfo.countryName);
|
||||||
|
preparedStatement.setString(3, ipInfo.regionCode);
|
||||||
|
preparedStatement.setString(4, ipInfo.regionName);
|
||||||
|
preparedStatement.setString(5, ipInfo.city);
|
||||||
|
preparedStatement.setString(6, ipInfo.zipCode);
|
||||||
|
preparedStatement.setString(7, ipInfo.timeZone);
|
||||||
|
preparedStatement.setDouble(8, ipInfo.latitude);
|
||||||
|
preparedStatement.setDouble(9, ipInfo.longitude);
|
||||||
|
preparedStatement.setInt(10, ipInfo.metroCode);
|
||||||
|
preparedStatement.setInt(11, ipInfo.id);
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class ProcessRunner extends Thread
|
||||||
|
{
|
||||||
|
private ProcessBuilder _processBuilder;
|
||||||
|
private Process _process;
|
||||||
|
private GenericRunnable<Boolean> _runnable;
|
||||||
|
|
||||||
|
boolean _done = false;
|
||||||
|
Boolean _error = false;
|
||||||
|
|
||||||
|
ProcessRunner(String[] args)
|
||||||
|
{
|
||||||
|
super("ProcessRunner " + args);
|
||||||
|
_processBuilder = new ProcessBuilder(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_process = _processBuilder.start();
|
||||||
|
_process.waitFor();
|
||||||
|
|
||||||
|
BufferedReader reader=new BufferedReader(new InputStreamReader(_process.getInputStream()));
|
||||||
|
String line = reader.readLine();
|
||||||
|
|
||||||
|
while(line != null)
|
||||||
|
{
|
||||||
|
if (line.equals("255"))
|
||||||
|
_error = true;
|
||||||
|
|
||||||
|
line=reader.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_done = true;
|
||||||
|
|
||||||
|
if (_runnable != null)
|
||||||
|
_runnable.run(_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(GenericRunnable<Boolean> runnable)
|
||||||
|
{
|
||||||
|
super.start();
|
||||||
|
|
||||||
|
_runnable = runnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int exitValue() throws IllegalStateException
|
||||||
|
{
|
||||||
|
if (_process != null)
|
||||||
|
{
|
||||||
|
return _process.exitValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException("Process not started yet");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDone()
|
||||||
|
{
|
||||||
|
return _done;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abort()
|
||||||
|
{
|
||||||
|
if (!isDone())
|
||||||
|
{
|
||||||
|
_process.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
|
||||||
|
public class ApiDeleteCall extends DnsMadeEasyApiCallBase
|
||||||
|
{
|
||||||
|
public ApiDeleteCall(String apiUrl, int domainId, String category)
|
||||||
|
{
|
||||||
|
super(apiUrl, domainId, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
HttpDelete request = new HttpDelete(ApiUrl + DomainId + Category);
|
||||||
|
|
||||||
|
execute(request);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class ApiGetCall extends DnsMadeEasyApiCallBase
|
||||||
|
{
|
||||||
|
private String _action;
|
||||||
|
|
||||||
|
public ApiGetCall(String apiUrl, int domainId, String category, String action)
|
||||||
|
{
|
||||||
|
super(apiUrl, domainId, category);
|
||||||
|
|
||||||
|
_action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
HttpGet request = new HttpGet(ApiUrl + DomainId + Category + _action);
|
||||||
|
execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Type returnType)
|
||||||
|
{
|
||||||
|
HttpGet request = new HttpGet(ApiUrl + DomainId + Category + _action);
|
||||||
|
|
||||||
|
String response = execute(request);
|
||||||
|
return new Gson().fromJson(response, returnType);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.message.BasicHeader;
|
||||||
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class ApiPostCall extends DnsMadeEasyApiCallBase
|
||||||
|
{
|
||||||
|
private String _action;
|
||||||
|
|
||||||
|
public ApiPostCall(String apiUrl, int domainId, String category, String action)
|
||||||
|
{
|
||||||
|
super(apiUrl, domainId, category);
|
||||||
|
|
||||||
|
_action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(Object argument)
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing ApiPostCall(Object): \n" + exception.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : exception.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Class<T> returnClass)
|
||||||
|
{
|
||||||
|
return Execute(returnClass, (Object)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Type returnType, Object argument)
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
|
||||||
|
System.out.println(request.getURI().toString());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing ApiPostCall(Type, Object): \n" + exception.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : exception.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = execute(request);
|
||||||
|
System.out.println(response);
|
||||||
|
return new Gson().fromJson(response, returnType);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.message.BasicHeader;
|
||||||
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class ApiPutCall extends DnsMadeEasyApiCallBase
|
||||||
|
{
|
||||||
|
private String _action;
|
||||||
|
|
||||||
|
public ApiPutCall(String apiUrl, int domainId, String category, String action)
|
||||||
|
{
|
||||||
|
super(apiUrl, domainId, category);
|
||||||
|
|
||||||
|
_action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(Object argument)
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPut request = new HttpPut(ApiUrl + DomainId + Category + _action);
|
||||||
|
|
||||||
|
System.out.println(request.getURI().toString());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing ApiPutCall(Object): \n" + exception.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : exception.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(execute(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Class<T> returnClass)
|
||||||
|
{
|
||||||
|
return Execute(returnClass, (Object)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Type returnType, Object argument)
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPut request = new HttpPut(ApiUrl + DomainId + Category + _action);
|
||||||
|
System.out.println(request.getURI().toString());
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing ApiPutCall(Type, Object): \n" + exception.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : exception.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = execute(request);
|
||||||
|
System.out.println(response);
|
||||||
|
return new Gson().fromJson(response, returnType);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
import org.apache.http.params.BasicHttpParams;
|
||||||
|
import org.apache.http.params.HttpConnectionParams;
|
||||||
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
||||||
|
public abstract class DnsMadeEasyApiCallBase
|
||||||
|
{
|
||||||
|
public static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
|
||||||
|
|
||||||
|
protected String ApiUrl = "https://api.dnsmadeeasy.com/V2.0/dns/managed/";
|
||||||
|
protected int DomainId = 962728;
|
||||||
|
protected String Category = "/records/";
|
||||||
|
|
||||||
|
public DnsMadeEasyApiCallBase(String apiUrl, int domainId, String category)
|
||||||
|
{
|
||||||
|
ApiUrl = apiUrl;
|
||||||
|
DomainId = domainId;
|
||||||
|
Category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String execute(HttpRequestBase request)
|
||||||
|
{
|
||||||
|
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
|
||||||
|
connectionManager.setMaxTotal(200);
|
||||||
|
connectionManager.setDefaultMaxPerRoute(20);
|
||||||
|
|
||||||
|
HttpParams params = new BasicHttpParams();
|
||||||
|
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(connectionManager, params);
|
||||||
|
InputStream in = null;
|
||||||
|
String response = "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String timeStamp = getServerTime();
|
||||||
|
SecretKeySpec keySpec = new SecretKeySpec("9041bc01-5cbc-49cf-ae09-a23b98350c62".getBytes(), "HmacSHA1");
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA1");
|
||||||
|
mac.init(keySpec);
|
||||||
|
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
||||||
|
Hex.encodeHexString(hashBytes);
|
||||||
|
|
||||||
|
request.addHeader("x-dnsme-apiKey", "2039c697-6ca9-412f-abda-0aef659a382a");
|
||||||
|
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
||||||
|
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
||||||
|
request.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
HttpResponse httpResponse = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (httpResponse != null)
|
||||||
|
{
|
||||||
|
in = httpResponse.getEntity().getContent();
|
||||||
|
response = convertStreamToString(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("DnsMadeEasyApiCall Error:");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getServerTime()
|
||||||
|
{
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||||
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
return dateFormat.format(calendar.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String convertStreamToString(InputStream is)
|
||||||
|
{
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while ((line = reader.readLine()) != null)
|
||||||
|
{
|
||||||
|
sb.append(line + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,122 @@
|
|||||||
|
package mineplex.bungee.api;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class HttpCallBase
|
||||||
|
{
|
||||||
|
private String _url;
|
||||||
|
|
||||||
|
public HttpCallBase(String url)
|
||||||
|
{
|
||||||
|
_url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Type returnType)
|
||||||
|
{
|
||||||
|
HttpGet request = new HttpGet(_url);
|
||||||
|
|
||||||
|
String response = execute(request);
|
||||||
|
System.out.println(response);
|
||||||
|
return new Gson().fromJson(response, returnType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String execute(HttpRequestBase request)
|
||||||
|
{
|
||||||
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
|
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||||
|
|
||||||
|
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||||
|
connectionManager.setMaxTotal(200);
|
||||||
|
connectionManager.setDefaultMaxPerRoute(20);
|
||||||
|
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
String response = "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
request.addHeader("Content-Type", "application/json");
|
||||||
|
HttpResponse httpResponse = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (httpResponse != null)
|
||||||
|
{
|
||||||
|
in = httpResponse.getEntity().getContent();
|
||||||
|
response = convertStreamToString(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("HttpCall Error:\n" + ex.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String convertStreamToString(InputStream is)
|
||||||
|
{
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while ((line = reader.readLine()) != null)
|
||||||
|
{
|
||||||
|
sb.append(line + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package mineplex.bungee.api.token;
|
||||||
|
|
||||||
|
public class ARecord extends DnsRecord
|
||||||
|
{
|
||||||
|
public ARecord(String recordName, String ip, int recordTtl)
|
||||||
|
{
|
||||||
|
name = recordName;
|
||||||
|
value = ip;
|
||||||
|
ttl = recordTtl;
|
||||||
|
|
||||||
|
type = "A";
|
||||||
|
gtdLocation = "DEFAULT";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package mineplex.bungee.api.token;
|
||||||
|
|
||||||
|
public class CNameRecord extends DnsRecord
|
||||||
|
{
|
||||||
|
public CNameRecord(String recordName, String ip, int recordTtl)
|
||||||
|
{
|
||||||
|
name = recordName;
|
||||||
|
value = ip;
|
||||||
|
ttl = recordTtl;
|
||||||
|
|
||||||
|
type = "CNAME";
|
||||||
|
gtdLocation = "DEFAULT";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package mineplex.bungee.api.token;
|
||||||
|
|
||||||
|
public class DnsRecord
|
||||||
|
{
|
||||||
|
public int id;
|
||||||
|
public String name;
|
||||||
|
public String type;
|
||||||
|
public String value;
|
||||||
|
public String gtdLocation = "DEFAULT";
|
||||||
|
public int ttl;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package mineplex.bungee.api.token;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DomainRecords
|
||||||
|
{
|
||||||
|
public List<DnsRecord> data;
|
||||||
|
public int page;
|
||||||
|
public int totalPage;
|
||||||
|
public int totalRecords;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
public class AccountTask
|
||||||
|
{
|
||||||
|
public int Id;
|
||||||
|
public String Task;
|
||||||
|
public String UUID;
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
|
|
||||||
|
public class AsyncJsonWebCall extends JsonWebCall
|
||||||
|
{
|
||||||
|
public AsyncJsonWebCall(String url)
|
||||||
|
{
|
||||||
|
super(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
AsyncJsonWebCall.super.Execute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(final Object argument)
|
||||||
|
{
|
||||||
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
AsyncJsonWebCall.super.Execute(argument);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void Execute(final Class<T> callbackClass, final Callback<T> callback)
|
||||||
|
{
|
||||||
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
AsyncJsonWebCall.super.Execute(callbackClass, callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void Execute(final Class<T> callbackClass, final Callback<T> callback, final Object argument)
|
||||||
|
{
|
||||||
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
AsyncJsonWebCall.super.Execute(callbackClass, callback, argument);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncThread.start();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,204 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class ChestConverter
|
||||||
|
{
|
||||||
|
private static ChestConverterRepository _repository = null;
|
||||||
|
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||||
|
|
||||||
|
private static Logger _logger = Logger.getLogger("Converter");
|
||||||
|
|
||||||
|
private static String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?allowMultiQueries=true";
|
||||||
|
private static String _userName = "MilitaryPolice";
|
||||||
|
private static String _password = "CUPr6Wuw2Rus$qap";
|
||||||
|
|
||||||
|
private static Connection _connection;
|
||||||
|
|
||||||
|
public static void main (String args[])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileHandler fileHandler = new FileHandler("converter.log", true);
|
||||||
|
fileHandler.setFormatter(new Formatter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String format(LogRecord record)
|
||||||
|
{
|
||||||
|
return record.getMessage() + "\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_logger.addHandler(fileHandler);
|
||||||
|
_logger.setUseParentHandlers(false);
|
||||||
|
}
|
||||||
|
catch (SecurityException | IOException e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
int limit = 50000;
|
||||||
|
HashSet<AccountStat> accountStats = new HashSet<AccountStat>();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
accountStats.clear();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Statement statement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
statement = _connection.createStatement();
|
||||||
|
|
||||||
|
statement.execute("SELECT accountId, statId, value FROM Account.accountStats LIMIT " + limit + ";");
|
||||||
|
|
||||||
|
ResultSet resultSet = statement.getResultSet();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
accountStats.add(new AccountStat(resultSet.getInt(1), resultSet.getInt(2), resultSet.getInt(3)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (statement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountStats.size() == 0)
|
||||||
|
{
|
||||||
|
System.out.println("No accounts.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparedStatement updateStatement = null;
|
||||||
|
PreparedStatement insertStatement = null;
|
||||||
|
Statement deleteStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
_connection.setAutoCommit(true);
|
||||||
|
updateStatement = _connection.prepareStatement("UPDATE accountStat SET value = value + ? WHERE accountId = ? AND statId = ? AND value < ?;");
|
||||||
|
|
||||||
|
for (AccountStat stat : accountStats)
|
||||||
|
{
|
||||||
|
updateStatement.setLong(1, stat.value);
|
||||||
|
updateStatement.setInt(2, stat.accountId);
|
||||||
|
updateStatement.setInt(3, stat.statId);
|
||||||
|
updateStatement.setLong(4, stat.value);
|
||||||
|
|
||||||
|
updateStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] rowsAffected = updateStatement.executeBatch();
|
||||||
|
_connection.setAutoCommit(false);
|
||||||
|
int i = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
log("Updated rows - " + limit);
|
||||||
|
|
||||||
|
insertStatement = _connection.prepareStatement("INSERT IGNORE accountStat(accountId, statId, value) VALUES (?, ?, ?);");
|
||||||
|
|
||||||
|
for (AccountStat stat : accountStats)
|
||||||
|
{
|
||||||
|
if (rowsAffected[i] < 1)
|
||||||
|
{
|
||||||
|
insertStatement.setInt(1, stat.accountId);
|
||||||
|
insertStatement.setInt(2, stat.statId);
|
||||||
|
insertStatement.setLong(3, stat.value);
|
||||||
|
|
||||||
|
insertStatement.addBatch();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
insertStatement.executeBatch();
|
||||||
|
log("Inserted rows - " + count);
|
||||||
|
|
||||||
|
deleteStatement = _connection.createStatement();
|
||||||
|
deleteStatement.executeUpdate("DELETE FROM accountStats LIMIT " + limit + ";");
|
||||||
|
|
||||||
|
_connection.commit();
|
||||||
|
|
||||||
|
log("Deleted rows - " + limit);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (statement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.info(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(String message)
|
||||||
|
{
|
||||||
|
System.out.println("[" + _dateFormat.format(new Date()) + "] " + message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,174 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
public class ChestConverterRepository
|
||||||
|
{
|
||||||
|
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?allowMultiQueries=true";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
|
private static String ADD_ACCOUNT_TASK = "INSERT INTO accountTasks (accountId, taskId) VALUES (?, ?);";
|
||||||
|
private static String RETRIEVE_TASKS = "SELECT id, name FROM tasks;";
|
||||||
|
|
||||||
|
private static Connection _connection;
|
||||||
|
|
||||||
|
public ChestConverterRepository()
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Integer> getTaskList()
|
||||||
|
{
|
||||||
|
HashMap<String, Integer> tasks = new HashMap<String, Integer>();
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_TASKS);
|
||||||
|
preparedStatement.execute();
|
||||||
|
|
||||||
|
ResultSet resultSet = preparedStatement.getResultSet();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
tasks.put(resultSet.getString(2), resultSet.getInt(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AccountTask> getTasks(int lastId, int count) throws Exception
|
||||||
|
{
|
||||||
|
return new JsonWebCall("http://accounts.mineplex.com/PlayerAccount/GetTasksByCount").Execute(new com.google.gson.reflect.TypeToken<List<AccountTask>>(){}.getType(), new SearchConf(lastId, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementClients(HashMap<String, List<Integer>> playerList)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
Statement statement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
statement = _connection.createStatement();
|
||||||
|
HashMap<Integer, List<Integer>> playerIdList = new HashMap<Integer, List<Integer>>();
|
||||||
|
String queryString = "";
|
||||||
|
for (Entry<String, List<Integer>> entry : playerList.entrySet())
|
||||||
|
{
|
||||||
|
queryString += "SELECT id FROM accounts WHERE accounts.uuid = '" + entry.getKey() + "' LIMIT 1;";
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.execute(queryString);
|
||||||
|
statement.getUpdateCount();
|
||||||
|
|
||||||
|
for (Entry<String, List<Integer>> entry : playerList.entrySet())
|
||||||
|
{
|
||||||
|
ResultSet resultSet = statement.getResultSet();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
for (Integer taskId : entry.getValue())
|
||||||
|
{
|
||||||
|
if (!playerIdList.containsKey(resultSet.getInt(1)))
|
||||||
|
playerIdList.put(resultSet.getInt(1), new ArrayList<Integer>());
|
||||||
|
|
||||||
|
playerIdList.get(resultSet.getInt(1)).add(taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
statement.getMoreResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(ADD_ACCOUNT_TASK);
|
||||||
|
System.out.println("adding to mysql db.");
|
||||||
|
for (Entry<Integer, List<Integer>> entry : playerIdList.entrySet())
|
||||||
|
{
|
||||||
|
for (Integer taskId : entry.getValue())
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, entry.getKey());
|
||||||
|
preparedStatement.setInt(2, taskId);
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
public interface GenericRunnable<T>
|
||||||
|
{
|
||||||
|
void run(T t);
|
||||||
|
}
|
@ -0,0 +1,349 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.common.util.UtilSystem;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||||
|
import org.apache.http.message.BasicHeader;
|
||||||
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
public class JsonWebCall
|
||||||
|
{
|
||||||
|
private String _url;
|
||||||
|
private PoolingClientConnectionManager _connectionManager;
|
||||||
|
|
||||||
|
public JsonWebCall(String url)
|
||||||
|
{
|
||||||
|
_url = url;
|
||||||
|
|
||||||
|
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||||
|
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||||
|
|
||||||
|
_connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||||
|
_connectionManager.setMaxTotal(200);
|
||||||
|
_connectionManager.setDefaultMaxPerRoute(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ExecuteReturnStream(Object argument)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponse response;
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(_url);
|
||||||
|
|
||||||
|
if (argument != null)
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
in = response.getEntity().getContent();
|
||||||
|
result = convertStreamToString(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||||
|
System.out.println("Result: \n" + result);
|
||||||
|
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
Execute((Object)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(Object argument)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(_url);
|
||||||
|
|
||||||
|
if (argument != null)
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.execute(request);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage());
|
||||||
|
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Class<T> returnClass)
|
||||||
|
{
|
||||||
|
return Execute(returnClass, (Object)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Type returnType, Object argument) throws Exception
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
T returnData = null;
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponse response;
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(_url);
|
||||||
|
|
||||||
|
if (argument != null)
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
in = response.getEntity().getContent();
|
||||||
|
|
||||||
|
result = convertStreamToString(in);
|
||||||
|
returnData = new Gson().fromJson(result, returnType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T Execute(Class<T> returnClass, Object argument)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
T returnData = null;
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponse response;
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(_url);
|
||||||
|
|
||||||
|
if (argument != null)
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (response != null)
|
||||||
|
{
|
||||||
|
in = response.getEntity().getContent();
|
||||||
|
|
||||||
|
result = convertStreamToString(in);
|
||||||
|
returnData = new Gson().fromJson(result, returnClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||||
|
System.out.println("Result: \n" + result);
|
||||||
|
|
||||||
|
for (StackTraceElement trace : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
System.out.println(trace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void Execute(Class<T> callbackClass, Callback<T> callback)
|
||||||
|
{
|
||||||
|
Execute(callbackClass, callback, (Object)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void Execute(Class<T> callbackClass, Callback<T> callback, Object argument)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||||
|
InputStream in = null;
|
||||||
|
String result = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponse response;
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
HttpPost request = new HttpPost(_url);
|
||||||
|
|
||||||
|
if (argument != null)
|
||||||
|
{
|
||||||
|
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||||
|
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||||
|
request.setEntity(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
response = httpClient.execute(request);
|
||||||
|
|
||||||
|
if (response != null && callback != null)
|
||||||
|
{
|
||||||
|
in = response.getEntity().getContent();
|
||||||
|
|
||||||
|
result = convertStreamToString(in);
|
||||||
|
callback.run(new Gson().fromJson(result, callbackClass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||||
|
UtilSystem.printStackTrace(ex.getStackTrace());
|
||||||
|
System.out.println("Result: \n" + result);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.getConnectionManager().shutdown();
|
||||||
|
|
||||||
|
if (in != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String convertStreamToString(InputStream is)
|
||||||
|
{
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
String line = null;
|
||||||
|
try {
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
sb.append(line + "\n");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
public class SearchConf
|
||||||
|
{
|
||||||
|
public SearchConf(int idIndex, int count)
|
||||||
|
{
|
||||||
|
IdIndex = idIndex;
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int IdIndex;
|
||||||
|
public int Count;
|
||||||
|
}
|
4
Plugins[Modified]/Mineplex.ClansGenerator/plugin.yml
Normal file
4
Plugins[Modified]/Mineplex.ClansGenerator/plugin.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name: ClansGenerator
|
||||||
|
main: mineplex.clansgenerator.ClansGenerator
|
||||||
|
version: 1.0
|
||||||
|
author: Alex
|
23
Plugins[Modified]/Mineplex.ClansGenerator/pom.xml
Normal file
23
Plugins[Modified]/Mineplex.ClansGenerator/pom.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mineplex</groupId>
|
||||||
|
<artifactId>mineplex-plugin</artifactId>
|
||||||
|
<version>dev-SNAPSHOT</version>
|
||||||
|
<relativePath>../plugin.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>ClansGenerator</name>
|
||||||
|
<artifactId>mineplex-clansgenerator</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-core-common</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,198 @@
|
|||||||
|
package mineplex.clansgenerator;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
|
||||||
|
import org.bukkit.event.world.ChunkPopulateEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.spigotmc.WatchdogThread;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.BiomeBase;
|
||||||
|
|
||||||
|
public class ClansGenerator extends JavaPlugin implements Runnable, Listener
|
||||||
|
{
|
||||||
|
private static final int MIN_X = -100;
|
||||||
|
private static final int MIN_Z = -100;
|
||||||
|
private static final int MAX_X = 100;
|
||||||
|
private static final int MAX_Z = 100;
|
||||||
|
|
||||||
|
private File _root;
|
||||||
|
private File _outputDir;
|
||||||
|
private boolean _debug = false;
|
||||||
|
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
_root = new File(".");
|
||||||
|
if (!_root.exists())
|
||||||
|
{
|
||||||
|
getLogger().severe("Root folder does not exist. Aborting");
|
||||||
|
getServer().shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_outputDir = new File(_root, "output");
|
||||||
|
if (new File(_root, "DEBUG.dat").exists())
|
||||||
|
{
|
||||||
|
_debug = true;
|
||||||
|
}
|
||||||
|
if (!_outputDir.exists())
|
||||||
|
{
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
getLogger().info("Creating map output directory!");
|
||||||
|
}
|
||||||
|
_outputDir.mkdir();
|
||||||
|
}
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.OCEAN.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.PLAINS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.DESERT.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.EXTREME_HILLS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.FOREST.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.TAIGA.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.SWAMPLAND.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.RIVER.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.HELL.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.SKY.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.FROZEN_OCEAN.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.FROZEN_RIVER.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.ICE_PLAINS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.ICE_MOUNTAINS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MUSHROOM_ISLAND.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MUSHROOM_SHORE.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.BEACH.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.DESERT_HILLS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.FOREST_HILLS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.TAIGA_HILLS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.SMALL_MOUNTAINS.id] = BiomeBase.PLAINS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.JUNGLE.id] = BiomeBase.EXTREME_HILLS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.JUNGLE_HILLS.id] = BiomeBase.EXTREME_HILLS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.JUNGLE_EDGE.id] = BiomeBase.EXTREME_HILLS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.DEEP_OCEAN.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.STONE_BEACH.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.COLD_BEACH.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.BIRCH_FOREST.id] = BiomeBase.BIRCH_FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.BIRCH_FOREST_HILLS.id] = BiomeBase.BIRCH_FOREST_HILLS;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.ROOFED_FOREST.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.COLD_TAIGA.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.COLD_TAIGA_HILLS.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MEGA_TAIGA.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MEGA_TAIGA_HILLS.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.EXTREME_HILLS_PLUS.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.SAVANNA.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.SAVANNA_PLATEAU.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MESA.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MESA_PLATEAU_F.id] = BiomeBase.FOREST;
|
||||||
|
BiomeBase.getBiomes()[BiomeBase.MESA_PLATEAU.id] = BiomeBase.FOREST;
|
||||||
|
WatchdogThread.doStop();
|
||||||
|
getServer().getScheduler().runTaskTimer(this, this, 20L, 100L);
|
||||||
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@EventHandler
|
||||||
|
public void onPopulate(ChunkPopulateEvent event)
|
||||||
|
{
|
||||||
|
Block block;
|
||||||
|
for (int x = 0; x < 16; x++)
|
||||||
|
{
|
||||||
|
for (int y = 1; y < 128; y++)
|
||||||
|
{
|
||||||
|
for (int z = 0; z < 16; z++)
|
||||||
|
{
|
||||||
|
block = event.getChunk().getBlock(x, y, z);
|
||||||
|
if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST || block.getType() == Material.MOB_SPAWNER)
|
||||||
|
{
|
||||||
|
block.setType(Material.AIR);
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
getLogger().info("Removing dungeon pieces");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (block.getType() == Material.LAVA)
|
||||||
|
{
|
||||||
|
byte data = block.getData();
|
||||||
|
block.setTypeIdAndData(Material.WATER.getId(), data, false);
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
getLogger().info("Removing lava");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (block.getType() == Material.STATIONARY_LAVA)
|
||||||
|
{
|
||||||
|
byte data = block.getData();
|
||||||
|
block.setTypeIdAndData(Material.STATIONARY_WATER.getId(), data, false);
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
getLogger().info("Removing lava");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(AsyncPlayerPreLoginEvent event)
|
||||||
|
{
|
||||||
|
event.setLoginResult(Result.KICK_OTHER);
|
||||||
|
event.setKickMessage("Shoo, go away");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
int nextFileId = 0;
|
||||||
|
for (int existingFiles = 0; new File(_outputDir, "Clans_Map_" + existingFiles).exists(); existingFiles++)
|
||||||
|
{
|
||||||
|
nextFileId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogger().info("Generating world id " + nextFileId);
|
||||||
|
World world = (new WorldCreator("Clans_Map_" + nextFileId)).environment(Environment.NORMAL).generateStructures(false).seed(ThreadLocalRandom.current().nextLong()).createWorld();
|
||||||
|
world.setKeepSpawnInMemory(false);
|
||||||
|
for (int x = MIN_X; x <= MAX_X; x++)
|
||||||
|
{
|
||||||
|
getLogger().info("Generating chunks for x coord " + x);
|
||||||
|
for (int z = MIN_Z; z <= MAX_Z; z++)
|
||||||
|
{
|
||||||
|
world.getChunkAt(x, z).load(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = MIN_X; x <= MAX_X; x++)
|
||||||
|
{
|
||||||
|
getLogger().info("Unloading chunks for x coord " + x);
|
||||||
|
for (int z = MIN_Z; z <= MAX_Z; z++)
|
||||||
|
{
|
||||||
|
world.getChunkAt(x, z).unload(true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogger().info("Unloading and saving world");
|
||||||
|
Bukkit.unloadWorld(world, true);
|
||||||
|
getLogger().info("Finished unloading and saving world");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileUtils.moveDirectoryToDirectory(new File(_root, "Clans_Map_" + nextFileId), _outputDir, false);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
getLogger().info("Finished generating world id " + nextFileId);
|
||||||
|
getServer().shutdown();
|
||||||
|
}
|
||||||
|
}
|
23
Plugins[Modified]/Mineplex.ClansQueue.Common/pom.xml
Normal file
23
Plugins[Modified]/Mineplex.ClansQueue.Common/pom.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mineplex</groupId>
|
||||||
|
<artifactId>mineplex-parent</artifactId>
|
||||||
|
<version>dev-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>ClansQueue-Common</name>
|
||||||
|
<artifactId>mineplex-clansqueue-common</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-serverdata</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
public class ClansQueueMessage
|
||||||
|
{
|
||||||
|
protected String Origin;
|
||||||
|
protected String BodyClass;
|
||||||
|
protected String BodySerialized;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Utility;
|
||||||
|
|
||||||
|
public abstract class ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public final String toString()
|
||||||
|
{
|
||||||
|
return Utility.serialize(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Utility;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.JedisPubSub;
|
||||||
|
|
||||||
|
public class ClansQueueMessenger
|
||||||
|
{
|
||||||
|
private static final String CHANNEL_NAME_BASE = "ClansQueueMessageChannel:";
|
||||||
|
|
||||||
|
private static final Map<String, ClansQueueMessenger> _messengers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private final String _identifier;
|
||||||
|
private final JedisPool _readPool;
|
||||||
|
private final JedisPool _writePool;
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
private final Map<String, Class> _bodyTypes = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
private final Map<String, List<BiConsumer>> _listeners = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
|
||||||
|
private ClansQueueMessenger(String identifier)
|
||||||
|
{
|
||||||
|
_identifier = identifier;
|
||||||
|
|
||||||
|
_writePool = Utility.generatePool(ServerManager.getMasterConnection());
|
||||||
|
_readPool = Utility.generatePool(ServerManager.getSlaveConnection());
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize()
|
||||||
|
{
|
||||||
|
new Thread("Clans Queue Messenger: " + _identifier)
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try (Jedis jedis = _readPool.getResource())
|
||||||
|
{
|
||||||
|
jedis.subscribe(new ClansQueueMessageListener(ClansQueueMessenger.this), CHANNEL_NAME_BASE + "ALL", CHANNEL_NAME_BASE + _identifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends ClansQueueMessageBody> void registerListener(Class<T> messageType, BiConsumer<T, String> callback)
|
||||||
|
{
|
||||||
|
_bodyTypes.putIfAbsent(messageType.getName(), messageType);
|
||||||
|
_listeners.computeIfAbsent(messageType.getName(), (type) -> new ArrayList<>()).add(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transmitMessage(ClansQueueMessageBody message)
|
||||||
|
{
|
||||||
|
transmitMessage(message, "ALL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void transmitMessage(ClansQueueMessageBody message, String target)
|
||||||
|
{
|
||||||
|
ClansQueueMessage msg = new ClansQueueMessage();
|
||||||
|
msg.Origin = _identifier;
|
||||||
|
msg.BodyClass = message.getClass().getName();
|
||||||
|
msg.BodySerialized = message.toString();
|
||||||
|
|
||||||
|
final String toSend = Utility.serialize(msg);
|
||||||
|
|
||||||
|
new Thread(() ->
|
||||||
|
{
|
||||||
|
try (Jedis jedis = _writePool.getResource())
|
||||||
|
{
|
||||||
|
jedis.publish(CHANNEL_NAME_BASE + target, toSend);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends ClansQueueMessageBody> void receiveMessage(ClansQueueMessage message)
|
||||||
|
{
|
||||||
|
if (_listeners.containsKey(message.BodyClass) && _bodyTypes.containsKey(message.BodyClass))
|
||||||
|
{
|
||||||
|
T body = Utility.deserialize(message.BodySerialized, (Class<T>)_bodyTypes.get(message.BodyClass));
|
||||||
|
_listeners.get(message.BodyClass).forEach(listener -> listener.accept(body, message.Origin));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ClansQueueMessageListener extends JedisPubSub
|
||||||
|
{
|
||||||
|
private final ClansQueueMessenger _manager;
|
||||||
|
|
||||||
|
private ClansQueueMessageListener(ClansQueueMessenger manager)
|
||||||
|
{
|
||||||
|
_manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(String channelName, String message)
|
||||||
|
{
|
||||||
|
ClansQueueMessage msg = Utility.deserialize(message, ClansQueueMessage.class);
|
||||||
|
_manager.receiveMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClansQueueMessenger getMessenger(String identifier)
|
||||||
|
{
|
||||||
|
return _messengers.computeIfAbsent(identifier, (id) -> new ClansQueueMessenger(id));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
public class EnclosedInteger
|
||||||
|
{
|
||||||
|
private int _value;
|
||||||
|
|
||||||
|
public EnclosedInteger(int value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnclosedInteger()
|
||||||
|
{
|
||||||
|
this(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAndIncrement()
|
||||||
|
{
|
||||||
|
return _value++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int incrementAndGet()
|
||||||
|
{
|
||||||
|
return ++_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(int newValue)
|
||||||
|
{
|
||||||
|
_value = newValue;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class QueueConstant
|
||||||
|
{
|
||||||
|
public static final String SERVICE_MESSENGER_IDENTIFIER = "Queue System";
|
||||||
|
public static final int BYPASS_QUEUE_WEIGHT = -1;
|
||||||
|
public static final int MAX_TRANSFERS_PER_UPDATE = 5;
|
||||||
|
public static final int MAXIMUM_WEIGHT_FROM_INCREASE = 6;
|
||||||
|
public static final long TIME_TO_INCREASE_WEIGHT = TimeUnit.MINUTES.toMillis(10);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.mineplex.clansqueue.common;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class SortableLinkedList<T extends Comparable<T>> extends LinkedList<T>
|
||||||
|
{
|
||||||
|
public void sort()
|
||||||
|
{
|
||||||
|
sort(Comparator.naturalOrder());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class ClansServerStatusMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
public int OpenSlots;
|
||||||
|
public boolean Online;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class PlayerJoinQueueCallbackMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public UUID PlayerUUID;
|
||||||
|
public String TargetServer;
|
||||||
|
public int Position;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class PlayerJoinQueueMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public UUID PlayerUUID;
|
||||||
|
public String TargetServer;
|
||||||
|
public int PlayerPriority;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class PlayerLeaveQueueMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public UUID PlayerUUID;
|
||||||
|
public String TargetServer;
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class PlayerSendToServerMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public UUID PlayerUUID;
|
||||||
|
public String TargetServer;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class QueueDeleteMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class QueuePauseBroadcastMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
public boolean Paused;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class QueuePauseUpdateMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
public boolean Paused;
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class QueueStatusMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public final List<QueueSnapshot> Snapshots = new ArrayList<>();
|
||||||
|
|
||||||
|
public static class QueueSnapshot
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
public Map<UUID, Integer> Queue;
|
||||||
|
public boolean Paused;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class ServerOfflineMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.mineplex.clansqueue.common.messages;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessageBody;
|
||||||
|
|
||||||
|
public class ServerOnlineMessage extends ClansQueueMessageBody
|
||||||
|
{
|
||||||
|
public String ServerName;
|
||||||
|
}
|
48
Plugins[Modified]/Mineplex.ClansQueue/pom.xml
Normal file
48
Plugins[Modified]/Mineplex.ClansQueue/pom.xml
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mineplex</groupId>
|
||||||
|
<artifactId>mineplex-plugin</artifactId>
|
||||||
|
<version>dev-SNAPSHOT</version>
|
||||||
|
<relativePath>../plugin.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<name>ClansQueue</name>
|
||||||
|
<artifactId>mineplex-clansqueue</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>mineplex-clansqueue-common</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<minimizeJar>false</minimizeJar>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.mineplex.clansqueue.service.QueueService</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.mineplex.clansqueue.service;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessenger;
|
||||||
|
import com.mineplex.clansqueue.common.QueueConstant;
|
||||||
|
import com.mineplex.clansqueue.common.messages.ClansServerStatusMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.PlayerJoinQueueMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.PlayerLeaveQueueMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.QueuePauseUpdateMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.ServerOfflineMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.ServerOnlineMessage;
|
||||||
|
import com.mineplex.clansqueue.service.commands.CommandSystem;
|
||||||
|
import com.mineplex.clansqueue.service.commands.ConsoleCommand;
|
||||||
|
import com.mineplex.clansqueue.service.queue.ClansQueueManager;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
|
||||||
|
public class QueueService
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
QueueService service = new QueueService(new File("eu.dat").exists());
|
||||||
|
service.start();
|
||||||
|
while (service.isRunning()) {}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Region _region;
|
||||||
|
private boolean _running = false;
|
||||||
|
private final Map<String, ConsoleCommand> _commandMap = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
private final CommandSystem _commandSystem;
|
||||||
|
private final ClansQueueManager _queueManager;
|
||||||
|
|
||||||
|
private QueueService(boolean eu)
|
||||||
|
{
|
||||||
|
if (eu)
|
||||||
|
{
|
||||||
|
_region = Region.EU;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_region = Region.US;
|
||||||
|
}
|
||||||
|
_commandSystem = new CommandSystem(this, _commandMap);
|
||||||
|
_queueManager = new ClansQueueManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void start()
|
||||||
|
{
|
||||||
|
System.out.println("[Queue Service] Enabling on region " + getRegion().name());
|
||||||
|
_running = true;
|
||||||
|
_commandSystem.start();
|
||||||
|
|
||||||
|
ClansQueueMessenger messenger = ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER);
|
||||||
|
messenger.registerListener(ServerOnlineMessage.class, (online, origin) -> _queueManager.handleServerEnable(online.ServerName));
|
||||||
|
messenger.registerListener(ServerOfflineMessage.class, (offline, origin) -> _queueManager.handleServerDisable(offline.ServerName));
|
||||||
|
messenger.registerListener(QueuePauseUpdateMessage.class, (pause, origin) -> _queueManager.handleQueuePause(pause.ServerName, pause.Paused));
|
||||||
|
messenger.registerListener(PlayerJoinQueueMessage.class, (join, origin) -> _queueManager.joinQueue(join.TargetServer, origin, join.PlayerUUID, join.PlayerPriority));
|
||||||
|
messenger.registerListener(PlayerLeaveQueueMessage.class, (leave, origin) -> _queueManager.leaveQueue(leave.TargetServer, leave.PlayerUUID));
|
||||||
|
messenger.registerListener(ClansServerStatusMessage.class, (status, origin) -> _queueManager.handleServerUpdate(status.ServerName, status.OpenSlots, status.Online));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClansQueueManager getQueueManager()
|
||||||
|
{
|
||||||
|
return _queueManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isRunning()
|
||||||
|
{
|
||||||
|
return _running;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Region getRegion()
|
||||||
|
{
|
||||||
|
return _region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommand(ConsoleCommand command)
|
||||||
|
{
|
||||||
|
_commandMap.put(command.getCommand().toLowerCase(), command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void shutdown()
|
||||||
|
{
|
||||||
|
System.out.println("[Queue Service] Shutting down...");
|
||||||
|
_queueManager.stop();
|
||||||
|
_running = false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
|
||||||
|
public class CommandSystem extends Thread
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
private final Map<String, ConsoleCommand> _commands;
|
||||||
|
|
||||||
|
public CommandSystem(QueueService service, Map<String, ConsoleCommand> commands)
|
||||||
|
{
|
||||||
|
super("Command System");
|
||||||
|
_service = service;
|
||||||
|
_commands = commands;
|
||||||
|
|
||||||
|
_service.registerCommand(new HelpCommand(_commands));
|
||||||
|
_service.registerCommand(new StopCommand(_service));
|
||||||
|
_service.registerCommand(new DeleteQueueCommand(_service));
|
||||||
|
_service.registerCommand(new ListQueuesCommand(_service));
|
||||||
|
_service.registerCommand(new PauseQueueCommand(_service));
|
||||||
|
_service.registerCommand(new UnpauseQueueCommand(_service));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean matches(String key, String input)
|
||||||
|
{
|
||||||
|
if (key.equalsIgnoreCase(input))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (input.toLowerCase().startsWith(key + " "))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
try (Scanner scanner = new Scanner(System.in))
|
||||||
|
{
|
||||||
|
while (_service.isRunning())
|
||||||
|
{
|
||||||
|
String input = scanner.nextLine();
|
||||||
|
if (input.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Optional<ConsoleCommand> opt = _commands.entrySet().stream().filter(entry -> matches(entry.getKey(), input)).map(Map.Entry::getValue).findAny();
|
||||||
|
if (opt.isPresent())
|
||||||
|
{
|
||||||
|
opt.get().call(input);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Command '" + input.split(" ")[0] + "' was not found. Run 'help' for a list of commands.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
public abstract class ConsoleCommand
|
||||||
|
{
|
||||||
|
private final String _command;
|
||||||
|
private final String _usageText;
|
||||||
|
private StringBuilder _outputBuilder;
|
||||||
|
|
||||||
|
public ConsoleCommand(String command, String usageText)
|
||||||
|
{
|
||||||
|
_command = command;
|
||||||
|
_usageText = usageText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommand()
|
||||||
|
{
|
||||||
|
return _command;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsageText()
|
||||||
|
{
|
||||||
|
return _usageText;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void addOutput(String text)
|
||||||
|
{
|
||||||
|
if (_outputBuilder == null)
|
||||||
|
{
|
||||||
|
_outputBuilder = new StringBuilder();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_outputBuilder.append("\n");
|
||||||
|
}
|
||||||
|
_outputBuilder.append(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void sendOutput()
|
||||||
|
{
|
||||||
|
System.out.println(_outputBuilder.toString());
|
||||||
|
_outputBuilder = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void call(String input)
|
||||||
|
{
|
||||||
|
String parsing = input.trim();
|
||||||
|
if (parsing.length() > getCommand().length() + 2)
|
||||||
|
{
|
||||||
|
String[] args = parsing.substring(getCommand().length() + 1).split(" ");
|
||||||
|
use(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
use(new String[] {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void use(String[] arguments);
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
import com.mineplex.clansqueue.service.queue.ClansServer;
|
||||||
|
|
||||||
|
public class DeleteQueueCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
|
||||||
|
public DeleteQueueCommand(QueueService service)
|
||||||
|
{
|
||||||
|
super("delete", "Deletes an existing server and queue");
|
||||||
|
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments.length < 1)
|
||||||
|
{
|
||||||
|
addOutput("Usage: delete <Server>");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClansServer server = _service.getQueueManager().getLoadedServer(arguments[0]);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
addOutput("Server '" + arguments[0] + "' was not found. Run 'list' for a list of servers.");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_service.getQueueManager().deleteServer(server);
|
||||||
|
addOutput("Server and queue deleted.");
|
||||||
|
sendOutput();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HelpCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final Map<String, ConsoleCommand> _commands;
|
||||||
|
|
||||||
|
public HelpCommand(Map<String, ConsoleCommand> commands)
|
||||||
|
{
|
||||||
|
super("help", "Lists commands and their usage");
|
||||||
|
|
||||||
|
_commands = commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments.length < 1)
|
||||||
|
{
|
||||||
|
addOutput("Commands:");
|
||||||
|
_commands.values().forEach(command ->
|
||||||
|
{
|
||||||
|
addOutput(command.getCommand() + " : " + command.getUsageText());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_commands.containsKey(arguments[0].toLowerCase()))
|
||||||
|
{
|
||||||
|
ConsoleCommand cmd = _commands.get(arguments[0].toLowerCase());
|
||||||
|
addOutput(cmd.getCommand() + " : " + cmd.getUsageText());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addOutput("Command '" + arguments[0] + "' was not found. Run 'help' for a list of commands.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendOutput();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
import com.mineplex.clansqueue.service.queue.ClansServer;
|
||||||
|
|
||||||
|
public class ListQueuesCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
|
||||||
|
public ListQueuesCommand(QueueService service)
|
||||||
|
{
|
||||||
|
super("list", "Lists existing servers");
|
||||||
|
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
StringBuilder servers = new StringBuilder("Servers: [");
|
||||||
|
servers.append(_service.getQueueManager().getLoadedServers().stream().map(ClansServer::getName).collect(Collectors.joining(", ")));
|
||||||
|
servers.append(']');
|
||||||
|
|
||||||
|
addOutput(servers.toString());
|
||||||
|
sendOutput();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
import com.mineplex.clansqueue.service.queue.ClansServer;
|
||||||
|
|
||||||
|
public class PauseQueueCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
|
||||||
|
public PauseQueueCommand(QueueService service)
|
||||||
|
{
|
||||||
|
super("pause", "Pauses an existing queue");
|
||||||
|
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments.length < 1)
|
||||||
|
{
|
||||||
|
addOutput("Usage: pause <Server>");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClansServer server = _service.getQueueManager().getLoadedServer(arguments[0]);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
addOutput("Server '" + arguments[0] + "' was not found. Run 'list' for a list of servers.");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_service.getQueueManager().handleQueuePause(server.getName(), true);
|
||||||
|
addOutput("Queue paused.");
|
||||||
|
sendOutput();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
|
||||||
|
public class StopCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
|
||||||
|
public StopCommand(QueueService service)
|
||||||
|
{
|
||||||
|
super("stop", "Stops the Queue Service");
|
||||||
|
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
_service.shutdown();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.mineplex.clansqueue.service.commands;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
import com.mineplex.clansqueue.service.queue.ClansServer;
|
||||||
|
|
||||||
|
public class UnpauseQueueCommand extends ConsoleCommand
|
||||||
|
{
|
||||||
|
private final QueueService _service;
|
||||||
|
|
||||||
|
public UnpauseQueueCommand(QueueService service)
|
||||||
|
{
|
||||||
|
super("unpause", "Resumes an existing queue");
|
||||||
|
|
||||||
|
_service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void use(String[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments.length < 1)
|
||||||
|
{
|
||||||
|
addOutput("Usage: unpause <Server>");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ClansServer server = _service.getQueueManager().getLoadedServer(arguments[0]);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
addOutput("Server '" + arguments[0] + "' was not found. Run 'list' for a list of servers.");
|
||||||
|
sendOutput();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_service.getQueueManager().handleQueuePause(server.getName(), false);
|
||||||
|
addOutput("Queue unpaused.");
|
||||||
|
sendOutput();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,198 @@
|
|||||||
|
package com.mineplex.clansqueue.service.queue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.ClansQueueMessenger;
|
||||||
|
import com.mineplex.clansqueue.common.QueueConstant;
|
||||||
|
import com.mineplex.clansqueue.common.messages.PlayerJoinQueueCallbackMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.PlayerSendToServerMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.QueueDeleteMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.QueuePauseBroadcastMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.QueueStatusMessage;
|
||||||
|
import com.mineplex.clansqueue.common.messages.QueueStatusMessage.QueueSnapshot;
|
||||||
|
import com.mineplex.clansqueue.service.QueueService;
|
||||||
|
|
||||||
|
public class ClansQueueManager
|
||||||
|
{
|
||||||
|
private final Map<String, ClansServer> _servers = new HashMap<>();
|
||||||
|
private final Map<ClansServer, ServerQueue> _queues = new HashMap<>();
|
||||||
|
private final ScheduledFuture<?> _updater;
|
||||||
|
|
||||||
|
public ClansQueueManager(QueueService service)
|
||||||
|
{
|
||||||
|
_updater = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (service.isRunning())
|
||||||
|
{
|
||||||
|
updateQueues();
|
||||||
|
}
|
||||||
|
}, 0, 5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueueStatusMessage buildStatusMessage(Collection<ServerQueue> queues)
|
||||||
|
{
|
||||||
|
QueueStatusMessage message = new QueueStatusMessage();
|
||||||
|
|
||||||
|
queues.forEach(queue ->
|
||||||
|
{
|
||||||
|
QueueSnapshot snapshot = new QueueSnapshot();
|
||||||
|
snapshot.Paused = queue.isPaused();
|
||||||
|
snapshot.ServerName = queue.getServer().getName();
|
||||||
|
snapshot.Queue = new HashMap<>();
|
||||||
|
queue.getPlayers().values().forEach(player -> snapshot.Queue.put(player.PlayerUUID, player.Position));
|
||||||
|
|
||||||
|
message.Snapshots.add(snapshot);
|
||||||
|
});
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void updateQueues()
|
||||||
|
{
|
||||||
|
System.out.println("Updating queues");
|
||||||
|
Collection<ServerQueue> queues = _queues.values();
|
||||||
|
|
||||||
|
queues.forEach(q ->
|
||||||
|
{
|
||||||
|
q.updatePositions(Math.min(q.getServer().getOpenSlots(), QueueConstant.MAX_TRANSFERS_PER_UPDATE));
|
||||||
|
if (q.getServer().isOnline())
|
||||||
|
{
|
||||||
|
q.getNextSend().entrySet().forEach(entry ->
|
||||||
|
{
|
||||||
|
PlayerSendToServerMessage message = new PlayerSendToServerMessage();
|
||||||
|
message.PlayerUUID = entry.getKey();
|
||||||
|
message.TargetServer = q.getServer().getName();
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message, entry.getValue());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QueueStatusMessage message = buildStatusMessage(queues);
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized ClansServer getLoadedServer(String serverName)
|
||||||
|
{
|
||||||
|
return _servers.get(serverName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized Collection<ClansServer> getLoadedServers()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableCollection(_servers.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void deleteServer(ClansServer server)
|
||||||
|
{
|
||||||
|
_servers.remove(server.getName());
|
||||||
|
_queues.remove(server);
|
||||||
|
QueueDeleteMessage message = new QueueDeleteMessage();
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void handleServerEnable(String serverName)
|
||||||
|
{
|
||||||
|
_servers.computeIfAbsent(serverName, (name) ->
|
||||||
|
{
|
||||||
|
ClansServer server = new ClansServer(name);
|
||||||
|
|
||||||
|
_queues.put(server, new ServerQueue(server));
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}).setOnline(true);
|
||||||
|
|
||||||
|
System.out.println("Clans server " + serverName + " enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void handleServerDisable(String serverName)
|
||||||
|
{
|
||||||
|
_servers.computeIfAbsent(serverName, (name) ->
|
||||||
|
{
|
||||||
|
ClansServer server = new ClansServer(name);
|
||||||
|
|
||||||
|
_queues.put(server, new ServerQueue(server));
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}).setOnline(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void handleServerUpdate(String serverName, int openSlots, boolean online)
|
||||||
|
{
|
||||||
|
ClansServer server = _servers.computeIfAbsent(serverName, (name) ->
|
||||||
|
{
|
||||||
|
ClansServer s = new ClansServer(name);
|
||||||
|
|
||||||
|
_queues.put(s, new ServerQueue(s));
|
||||||
|
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
server.setOpenSlots(openSlots);
|
||||||
|
server.setOnline(online);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void handleQueuePause(String serverName, boolean pause)
|
||||||
|
{
|
||||||
|
ClansServer server = _servers.get(serverName);
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
_queues.get(server).setPaused(pause);
|
||||||
|
System.out.println("Clans server " + serverName + " queue pause: " + pause);
|
||||||
|
QueuePauseBroadcastMessage message = new QueuePauseBroadcastMessage();
|
||||||
|
message.ServerName = serverName;
|
||||||
|
message.Paused = pause;
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void joinQueue(String serverName, String currentServer, UUID uuid, int weight)
|
||||||
|
{
|
||||||
|
ClansServer server = _servers.get(serverName);
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
ServerQueue queue = _queues.get(server);
|
||||||
|
if (weight == QueueConstant.BYPASS_QUEUE_WEIGHT)
|
||||||
|
{
|
||||||
|
queue.addBypasser(uuid, currentServer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
queue.addPlayer(uuid, currentServer, weight, player ->
|
||||||
|
{
|
||||||
|
PlayerJoinQueueCallbackMessage message = new PlayerJoinQueueCallbackMessage();
|
||||||
|
message.PlayerUUID = uuid;
|
||||||
|
message.TargetServer = serverName;
|
||||||
|
message.Position = player.Position;
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message, currentServer);
|
||||||
|
QueueStatusMessage update = buildStatusMessage(Arrays.asList(queue));
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(update);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void leaveQueue(String serverName, UUID uuid)
|
||||||
|
{
|
||||||
|
ClansServer server = _servers.get(serverName);
|
||||||
|
if (server != null)
|
||||||
|
{
|
||||||
|
ServerQueue queue = _queues.get(server);
|
||||||
|
queue.removePlayer(uuid, () ->
|
||||||
|
{
|
||||||
|
QueueStatusMessage message = buildStatusMessage(Arrays.asList(queue));
|
||||||
|
ClansQueueMessenger.getMessenger(QueueConstant.SERVICE_MESSENGER_IDENTIFIER).transmitMessage(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
_updater.cancel(true);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.mineplex.clansqueue.service.queue;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
|
public class ClansServer
|
||||||
|
{
|
||||||
|
private final String _serverName;
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
|
private boolean _online = false;
|
||||||
|
|
||||||
|
@GuardedBy("this")
|
||||||
|
private int _openSlots = 0;
|
||||||
|
|
||||||
|
public ClansServer(String serverName)
|
||||||
|
{
|
||||||
|
_serverName = serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return _serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isOnline()
|
||||||
|
{
|
||||||
|
return _online;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setOnline(boolean online)
|
||||||
|
{
|
||||||
|
_online = online;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int getOpenSlots()
|
||||||
|
{
|
||||||
|
return _openSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setOpenSlots(int openSlots)
|
||||||
|
{
|
||||||
|
_openSlots = openSlots;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return _serverName.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (o == null || !getClass().isInstance(o))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((ClansServer)o)._serverName.equals(_serverName);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
package com.mineplex.clansqueue.service.queue;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.mineplex.clansqueue.common.QueueConstant;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
|
public class QueuePlayer implements Comparable<QueuePlayer>
|
||||||
|
{
|
||||||
|
public final UUID PlayerUUID;
|
||||||
|
public final String CurrentServer;
|
||||||
|
public final long EntryTime;
|
||||||
|
public int Weight;
|
||||||
|
public long LastWeightIncrease;
|
||||||
|
public int Position;
|
||||||
|
|
||||||
|
public QueuePlayer(UUID uuid, String currentServer, int weight)
|
||||||
|
{
|
||||||
|
PlayerUUID = uuid;
|
||||||
|
CurrentServer = currentServer;
|
||||||
|
EntryTime = System.currentTimeMillis();
|
||||||
|
Weight = weight;
|
||||||
|
LastWeightIncrease = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateWeight()
|
||||||
|
{
|
||||||
|
if (Weight < QueueConstant.MAXIMUM_WEIGHT_FROM_INCREASE && (LastWeightIncrease + QueueConstant.TIME_TO_INCREASE_WEIGHT) < System.currentTimeMillis())
|
||||||
|
{
|
||||||
|
Weight++;
|
||||||
|
LastWeightIncrease = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableQueuePlayer immutable()
|
||||||
|
{
|
||||||
|
return new ImmutableQueuePlayer(PlayerUUID, CurrentServer, Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return PlayerUUID.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (o == null || !getClass().isInstance(o))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((QueuePlayer)o).PlayerUUID.equals(PlayerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(QueuePlayer player)
|
||||||
|
{
|
||||||
|
Preconditions.checkNotNull(player);
|
||||||
|
|
||||||
|
updateWeight();
|
||||||
|
player.updateWeight();
|
||||||
|
|
||||||
|
if (Weight == player.Weight)
|
||||||
|
{
|
||||||
|
return Long.compare(EntryTime, player.EntryTime);
|
||||||
|
}
|
||||||
|
else if (Weight > player.Weight)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
public static class ImmutableQueuePlayer
|
||||||
|
{
|
||||||
|
public final UUID PlayerUUID;
|
||||||
|
public final String CurrentServer;
|
||||||
|
public final int Position;
|
||||||
|
|
||||||
|
private ImmutableQueuePlayer(UUID uuid, String server, int position)
|
||||||
|
{
|
||||||
|
PlayerUUID = uuid;
|
||||||
|
CurrentServer = server;
|
||||||
|
Position = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,180 @@
|
|||||||
|
package com.mineplex.clansqueue.service.queue;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
import com.mineplex.clansqueue.common.EnclosedInteger;
|
||||||
|
import com.mineplex.clansqueue.common.SortableLinkedList;
|
||||||
|
import com.mineplex.clansqueue.service.queue.QueuePlayer.ImmutableQueuePlayer;
|
||||||
|
|
||||||
|
@ThreadSafe
|
||||||
|
public class ServerQueue
|
||||||
|
{
|
||||||
|
private final ClansServer _server;
|
||||||
|
|
||||||
|
@GuardedBy("_sendLock")
|
||||||
|
private final Map<UUID, String> _sending = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
@GuardedBy("_bypassLock")
|
||||||
|
private final Map<UUID, String> _bypassing = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
@GuardedBy("_queueLock")
|
||||||
|
private final SortableLinkedList<QueuePlayer> _queued = new SortableLinkedList<>();
|
||||||
|
|
||||||
|
private final Object _bypassLock = new Object();
|
||||||
|
private final Object _queueLock = new Object();
|
||||||
|
private final Object _sendLock = new Object();
|
||||||
|
private final Object _pauseLock = new Object();
|
||||||
|
|
||||||
|
@GuardedBy("_pauseLock")
|
||||||
|
private boolean _paused = false;
|
||||||
|
|
||||||
|
public ServerQueue(ClansServer server)
|
||||||
|
{
|
||||||
|
_server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sortQueue()
|
||||||
|
{
|
||||||
|
synchronized (_queueLock)
|
||||||
|
{
|
||||||
|
_queued.sort();
|
||||||
|
EnclosedInteger position = new EnclosedInteger(1);
|
||||||
|
_queued.forEach(qp ->
|
||||||
|
{
|
||||||
|
qp.Position = position.getAndIncrement();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClansServer getServer()
|
||||||
|
{
|
||||||
|
return _server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPaused()
|
||||||
|
{
|
||||||
|
if (!_server.isOnline())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (_pauseLock)
|
||||||
|
{
|
||||||
|
return _paused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<UUID, String> getNextSend()
|
||||||
|
{
|
||||||
|
synchronized (_sendLock)
|
||||||
|
{
|
||||||
|
Map<UUID, String> sending = new LinkedHashMap<>();
|
||||||
|
sending.putAll(_sending);
|
||||||
|
_sending.clear();
|
||||||
|
return sending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<UUID, ImmutableQueuePlayer> getPlayers()
|
||||||
|
{
|
||||||
|
synchronized (_queueLock)
|
||||||
|
{
|
||||||
|
Map<UUID, ImmutableQueuePlayer> players = new LinkedHashMap<>();
|
||||||
|
sortQueue();
|
||||||
|
_queued.forEach(qp -> players.put(qp.PlayerUUID, qp.immutable()));
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBypasser(UUID uuid, String currentServer)
|
||||||
|
{
|
||||||
|
synchronized (_bypassLock)
|
||||||
|
{
|
||||||
|
_bypassing.put(uuid, currentServer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPlayer(UUID uuid, String currentServer, int weight, Consumer<QueuePlayer> callback)
|
||||||
|
{
|
||||||
|
synchronized (_queueLock)
|
||||||
|
{
|
||||||
|
QueuePlayer player = new QueuePlayer(uuid, currentServer, weight);
|
||||||
|
_queued.add(player);
|
||||||
|
|
||||||
|
sortQueue();
|
||||||
|
|
||||||
|
if (callback != null)
|
||||||
|
{
|
||||||
|
callback.accept(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayer(UUID uuid, Runnable after)
|
||||||
|
{
|
||||||
|
synchronized (_queueLock)
|
||||||
|
{
|
||||||
|
_queued.removeIf(player -> player.PlayerUUID.equals(uuid));
|
||||||
|
|
||||||
|
sortQueue();
|
||||||
|
|
||||||
|
if (after != null)
|
||||||
|
{
|
||||||
|
after.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaused(boolean paused)
|
||||||
|
{
|
||||||
|
synchronized (_pauseLock)
|
||||||
|
{
|
||||||
|
_paused = paused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePositions(int openPlayerSlots)
|
||||||
|
{
|
||||||
|
Map<UUID, String> send = new LinkedHashMap<>();
|
||||||
|
if (_server.isOnline())
|
||||||
|
{
|
||||||
|
synchronized (_bypassLock)
|
||||||
|
{
|
||||||
|
send.putAll(_bypassing);
|
||||||
|
_bypassing.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
synchronized (_queueLock)
|
||||||
|
{
|
||||||
|
if (!isPaused() && openPlayerSlots > 0)
|
||||||
|
{
|
||||||
|
sortQueue();
|
||||||
|
while (send.size() < openPlayerSlots)
|
||||||
|
{
|
||||||
|
QueuePlayer player = _queued.poll();
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
send.put(player.PlayerUUID, player.CurrentServer);
|
||||||
|
}
|
||||||
|
sortQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (send.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
synchronized (_sendLock)
|
||||||
|
{
|
||||||
|
_sending.putAll(send);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,14 +13,8 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>23.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.labalityowo</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -12,7 +13,7 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.labalityowo</groupId>
|
<groupId>com.mineplex</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -35,7 +36,6 @@
|
|||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>${project.basedir}</directory>
|
|
||||||
<includes>
|
<includes>
|
||||||
<include>ascii.png</include>
|
<include>ascii.png</include>
|
||||||
</includes>
|
</includes>
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
package mineplex.core.common;
|
package mineplex.core.common;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import com.mojang.util.UUIDTypeAdapter;
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Constants
|
public class Constants
|
||||||
{
|
{
|
||||||
public static final String WEB_ADDRESS = "http://127.0.0.1:1000/";
|
public static final String WEB_ADDRESS = "http://accounts.mineplex.com/";
|
||||||
public static final String WEB_CONFIG_KEY = "webServer";
|
public static final String WEB_CONFIG_KEY = "webServer";
|
||||||
|
|
||||||
public static Gson GSON;
|
public static Gson GSON;
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package mineplex.core.common.api;
|
package mineplex.core.common.api;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
public class ApiHost
|
public class ApiHost
|
||||||
{
|
{
|
||||||
private static final String API_HOST_FILE = "api-config.dat";
|
private static final String API_HOST_FILE = "api-config.dat";
|
||||||
@ -22,7 +25,6 @@ public class ApiHost
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
File configFile = new File(API_HOST_FILE);
|
File configFile = new File(API_HOST_FILE);
|
||||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
@ -38,13 +40,6 @@ public class ApiHost
|
|||||||
|
|
||||||
API_HOST_MAP.put(key, new ApiHost(ip, port));
|
API_HOST_MAP.put(key, new ApiHost(ip, port));
|
||||||
}
|
}
|
||||||
Manually putting datas
|
|
||||||
*/
|
|
||||||
API_HOST_MAP.put("AMPLIFIERS", new ApiHost("127.0.0.1", 1000));
|
|
||||||
API_HOST_MAP.put("ANTISPAM", new ApiHost("127.0.0.1", 1000));
|
|
||||||
API_HOST_MAP.put("ENDERCHEST", new ApiHost("127.0.0.1", 1000));
|
|
||||||
API_HOST_MAP.put("BANNER", new ApiHost("127.0.0.1", 1000));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +105,9 @@ public class MultiBlockUpdaterAgent
|
|||||||
{
|
{
|
||||||
for(Player p : players)
|
for(Player p : players)
|
||||||
{
|
{
|
||||||
int protocol = UtilPlayer.getProtocol(p);
|
//TODO: Multi-protocol support
|
||||||
|
//int protocol = UtilPlayer.getProtocol(p);
|
||||||
|
//UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(protocol, c, true, 65535));
|
||||||
UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(c, true, 65535));
|
UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(c, true, 65535));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package mineplex.core.common.util;
|
package mineplex.core.common.util;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityTameableAnimal;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import net.minecraft.server.v1_8_R3.EntityTameableAnimal;
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftTameableAnimal;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftTameableAnimal;
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
import org.bukkit.entity.Tameable;
|
import org.bukkit.entity.Tameable;
|
||||||
|
@ -1073,6 +1073,11 @@ public class UtilEnt
|
|||||||
public static void registerEntityType(Class<? extends net.minecraft.server.v1_8_R3.Entity> customClass, EntityType entityType, String name)
|
public static void registerEntityType(Class<? extends net.minecraft.server.v1_8_R3.Entity> customClass, EntityType entityType, String name)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//TODO: Balloon | Custom entity(?)
|
||||||
|
//For now: we have no way of registering these, well.. as i know, im not a spigot dev
|
||||||
|
//EntityTypes.getNameToClassMap().remove(name);
|
||||||
|
//EntityTypes.getIdToClassMap().remove((int) entityType.getTypeId());
|
||||||
|
//EntityTypes.register(customClass, name, (int) entityType.getTypeId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spawnEntity(net.minecraft.server.v1_8_R3.Entity entity, Location location)
|
public static void spawnEntity(net.minecraft.server.v1_8_R3.Entity entity, Location location)
|
||||||
|
@ -26,7 +26,6 @@ import net.minecraft.server.v1_8_R3.EntityPlayer;
|
|||||||
import net.minecraft.server.v1_8_R3.EntityTracker;
|
import net.minecraft.server.v1_8_R3.EntityTracker;
|
||||||
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||||
import net.minecraft.server.v1_8_R3.Packet;
|
import net.minecraft.server.v1_8_R3.Packet;
|
||||||
|
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedSoundEffect;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedSoundEffect;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldBorder;
|
||||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||||
@ -51,6 +50,10 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
import org.bukkit.util.BlockIterator;
|
import org.bukkit.util.BlockIterator;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
//TODO: Multi-protocol support
|
||||||
|
//import com.mineplex.ProtocolVersion;
|
||||||
|
//import net.minecraft.server.v1_8_R3.PacketPlayOutCustomSoundEffect;
|
||||||
|
|
||||||
import mineplex.core.common.MinecraftVersion;
|
import mineplex.core.common.MinecraftVersion;
|
||||||
|
|
||||||
public class UtilPlayer
|
public class UtilPlayer
|
||||||
@ -1168,6 +1171,18 @@ public class UtilPlayer
|
|||||||
int protocol = getProtocol(player);
|
int protocol = getProtocol(player);
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
packet = new PacketPlayOutNamedSoundEffect(sound.getAudioPath(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), 20, 1);
|
packet = new PacketPlayOutNamedSoundEffect(sound.getAudioPath(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), 20, 1);
|
||||||
|
//TODO: Multi-protocol support
|
||||||
|
/*
|
||||||
|
if (protocol >= ProtocolVersion.v1_12)
|
||||||
|
{
|
||||||
|
packet = new PacketPlayOutCustomSoundEffect(sound.getAudioPath(), location.getX(), location.getY(), location.getZ(), 20, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
packet = new PacketPlayOutNamedSoundEffect(sound.getAudioPath(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), 20, 1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
sendPacket(player, packet);
|
sendPacket(player, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1200,6 +1215,7 @@ public class UtilPlayer
|
|||||||
|
|
||||||
public static int getProtocol(Player player)
|
public static int getProtocol(Player player)
|
||||||
{
|
{
|
||||||
|
//return ((CraftPlayer) player).getHandle().getProtocol();
|
||||||
return ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion();
|
return ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,17 +59,11 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.labalityowo</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>noop</directory>
|
|
||||||
<includes>
|
<includes>
|
||||||
<include>version.properties</include>
|
<include>version.properties</include>
|
||||||
</includes>
|
</includes>
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
package mineplex.core;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInArmAnimation;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInBlockDig;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInEntityAction;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInFlying;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInHeldItemSlot;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInRightClick;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutCloseWindow;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import mineplex.core.packethandler.IPacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Why do we need this you ask?
|
||||||
|
* <p>
|
||||||
|
* In 1.8.x, Mojang added Twitch integration, and in standard Mojang fashion completely broke inventory handling.
|
||||||
|
* <p>
|
||||||
|
* Specifically, you are able to close an inventory and not actually trigger an InventoryCloseEvent. This kinda breaks
|
||||||
|
* literally anything relying on that event.
|
||||||
|
* <p>
|
||||||
|
* So we just add lots of strict checks to make sure they can't do much without closing the inventory
|
||||||
|
*/
|
||||||
|
@ReflectivelyCreateMiniPlugin
|
||||||
|
public class TwitchIntegrationFix extends MiniPlugin implements IPacketHandler
|
||||||
|
{
|
||||||
|
private final Map<UUID, Location> _inventoryOpenedAt = new HashMap<>();
|
||||||
|
private final Map<UUID, Long> _inventoryOpenedAtTime = new HashMap<>();
|
||||||
|
|
||||||
|
private TwitchIntegrationFix()
|
||||||
|
{
|
||||||
|
super("Twitch Integration Fix");
|
||||||
|
|
||||||
|
require(PacketHandler.class).addPacketHandler(this, true,
|
||||||
|
PacketPlayOutOpenWindow.class,
|
||||||
|
PacketPlayOutCloseWindow.class,
|
||||||
|
PacketPlayInRightClick.class,
|
||||||
|
PacketPlayInBlockPlace.class,
|
||||||
|
PacketPlayInArmAnimation.class,
|
||||||
|
PacketPlayInBlockDig.class,
|
||||||
|
PacketPlayInHeldItemSlot.class,
|
||||||
|
PacketPlayInUseEntity.class,
|
||||||
|
PacketPlayInFlying.PacketPlayInPosition.class,
|
||||||
|
PacketPlayInFlying.PacketPlayInPositionLook.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
_inventoryOpenedAt.remove(event.getPlayer().getUniqueId());
|
||||||
|
_inventoryOpenedAtTime.remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(PacketInfo packetInfo)
|
||||||
|
{
|
||||||
|
EntityPlayer entityPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
||||||
|
//TODO: No idea what this is tbh, im just commenting out if someone can figure this out
|
||||||
|
/*
|
||||||
|
if (packetInfo.getPacket() instanceof PacketPlayOutOpenWindow)
|
||||||
|
{
|
||||||
|
_inventoryOpenedAt.put(packetInfo.getPlayer().getUniqueId(), packetInfo.getPlayer().getLocation());
|
||||||
|
_inventoryOpenedAtTime.put(packetInfo.getPlayer().getUniqueId(), entityPlayer.playerConnection.networkManager.packetCount);
|
||||||
|
}
|
||||||
|
else if (packetInfo.getPacket() instanceof PacketPlayOutCloseWindow)
|
||||||
|
{
|
||||||
|
_inventoryOpenedAt.remove(packetInfo.getPlayer().getUniqueId());
|
||||||
|
_inventoryOpenedAtTime.remove(packetInfo.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
else if (packetInfo.getPacket() instanceof PacketPlayInRightClick ||
|
||||||
|
packetInfo.getPacket() instanceof PacketPlayInBlockPlace ||
|
||||||
|
packetInfo.getPacket() instanceof PacketPlayInArmAnimation ||
|
||||||
|
packetInfo.getPacket() instanceof PacketPlayInBlockDig ||
|
||||||
|
packetInfo.getPacket() instanceof PacketPlayInHeldItemSlot ||
|
||||||
|
packetInfo.getPacket() instanceof PacketPlayInUseEntity
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Impossible to do while inventory is open
|
||||||
|
if (entityPlayer.activeContainer != entityPlayer.defaultContainer && _inventoryOpenedAtTime.containsKey(packetInfo.getPlayer().getUniqueId()))
|
||||||
|
{
|
||||||
|
long openedTime = _inventoryOpenedAtTime.get(packetInfo.getPlayer().getUniqueId());
|
||||||
|
if (entityPlayer.playerConnection.networkManager.packetCount - openedTime > 5)
|
||||||
|
{
|
||||||
|
System.out.println("Impossible packet: " + packetInfo.getPacket().getClass());
|
||||||
|
packetInfo.getPlayer().closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else*/ if (packetInfo.getPacket() instanceof PacketPlayInFlying)
|
||||||
|
{
|
||||||
|
if (entityPlayer.activeContainer != entityPlayer.defaultContainer)
|
||||||
|
{
|
||||||
|
if (_inventoryOpenedAt.containsKey(packetInfo.getPlayer().getUniqueId()))
|
||||||
|
{
|
||||||
|
Location openedAt = _inventoryOpenedAt.get(packetInfo.getPlayer().getUniqueId());
|
||||||
|
if (!packetInfo.getPlayer().getWorld().equals(openedAt.getWorld()))
|
||||||
|
{
|
||||||
|
packetInfo.getPlayer().closeInventory();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double distance = packetInfo.getPlayer().getLocation().distanceSquared(openedAt);
|
||||||
|
// You get a 9 block radius before you're considered too far away
|
||||||
|
if (distance > 9 * 9)
|
||||||
|
{
|
||||||
|
packetInfo.getPlayer().closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +1,24 @@
|
|||||||
package mineplex.core.account;
|
package mineplex.core.account;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import java.sql.SQLException;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import java.util.ArrayList;
|
||||||
import com.google.common.collect.Sets;
|
import java.util.HashMap;
|
||||||
import com.google.gson.Gson;
|
import java.util.HashSet;
|
||||||
import mineplex.cache.player.PlayerCache;
|
import java.util.Iterator;
|
||||||
import mineplex.cache.player.PlayerInfo;
|
import java.util.List;
|
||||||
import mineplex.core.MiniPlugin;
|
import java.util.Map;
|
||||||
import mineplex.core.account.command.RanksCommand;
|
import java.util.Map.Entry;
|
||||||
import mineplex.core.account.event.ClientUnloadEvent;
|
import java.util.Set;
|
||||||
import mineplex.core.account.event.ClientWebResponseEvent;
|
import java.util.UUID;
|
||||||
import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import java.util.concurrent.TimeUnit;
|
||||||
import mineplex.core.account.permissions.PermissionGroupHelper;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import mineplex.core.account.redis.*;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import mineplex.core.account.repository.AccountRepository;
|
import java.util.function.BiConsumer;
|
||||||
import mineplex.core.account.repository.token.ClientToken;
|
import java.util.function.Consumer;
|
||||||
import mineplex.core.common.Pair;
|
import java.util.regex.Pattern;
|
||||||
import mineplex.core.common.timing.TimingManager;
|
|
||||||
import mineplex.core.common.util.*;
|
|
||||||
import mineplex.core.updater.UpdateType;
|
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
|
||||||
import mineplex.core.utils.UtilGameProfile;
|
|
||||||
import mineplex.core.utils.UtilScheduler;
|
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -36,17 +30,43 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import com.google.common.cache.Cache;
|
||||||
import java.util.*;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import java.util.Map.Entry;
|
import com.google.common.collect.Sets;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import com.google.gson.Gson;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import mineplex.cache.player.PlayerCache;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import mineplex.cache.player.PlayerInfo;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import mineplex.core.MiniPlugin;
|
||||||
import java.util.function.BiConsumer;
|
import mineplex.core.account.command.RanksCommand;
|
||||||
import java.util.function.Consumer;
|
import mineplex.core.account.event.ClientUnloadEvent;
|
||||||
import java.util.regex.Pattern;
|
import mineplex.core.account.event.ClientWebResponseEvent;
|
||||||
|
import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent;
|
||||||
|
import mineplex.core.account.permissions.Permission;
|
||||||
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
|
import mineplex.core.account.permissions.PermissionGroupHelper;
|
||||||
|
import mineplex.core.account.redis.AddPermissionGroup;
|
||||||
|
import mineplex.core.account.redis.AddPermissionGroupHandler;
|
||||||
|
import mineplex.core.account.redis.ClearGroups;
|
||||||
|
import mineplex.core.account.redis.ClearGroupsHandler;
|
||||||
|
import mineplex.core.account.redis.PrimaryGroupUpdate;
|
||||||
|
import mineplex.core.account.redis.PrimaryGroupUpdateHandler;
|
||||||
|
import mineplex.core.account.redis.RemovePermissionGroup;
|
||||||
|
import mineplex.core.account.redis.RemovePermissionGroupHandler;
|
||||||
|
import mineplex.core.account.repository.AccountRepository;
|
||||||
|
import mineplex.core.account.repository.token.ClientToken;
|
||||||
|
import mineplex.core.common.Pair;
|
||||||
|
import mineplex.core.common.timing.TimingManager;
|
||||||
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.common.util.UtilTasks;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.core.utils.UtilGameProfile;
|
||||||
|
import mineplex.core.utils.UtilScheduler;
|
||||||
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
|
|
||||||
public class CoreClientManager extends MiniPlugin
|
public class CoreClientManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
@ -307,9 +327,9 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
client.setAccountId(result.getLeft());
|
client.setAccountId(result.getLeft());
|
||||||
if (result.getRight().getLeft() == null)
|
if (result.getRight().getLeft() == null)
|
||||||
{
|
{
|
||||||
//PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
||||||
client.setPrimaryGroup(PermissionGroup.PLAYER);
|
client.setPrimaryGroup(newGroup);
|
||||||
_repository.setPrimaryGroup(client.getAccountId(), PermissionGroup.PLAYER, null);
|
_repository.setPrimaryGroup(client.getAccountId(), newGroup, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -387,9 +407,9 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
client.setAccountId(result.getLeft());
|
client.setAccountId(result.getLeft());
|
||||||
if (result.getRight().getLeft() == null)
|
if (result.getRight().getLeft() == null)
|
||||||
{
|
{
|
||||||
//PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
||||||
client.setPrimaryGroup(PermissionGroup.PLAYER);
|
client.setPrimaryGroup(newGroup);
|
||||||
_repository.setPrimaryGroup(client.getAccountId(), PermissionGroup.PLAYER, null);
|
_repository.setPrimaryGroup(client.getAccountId(), newGroup, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -465,12 +485,11 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
Pair<Integer, Pair<PermissionGroup, Set<PermissionGroup>>> result = _repository.login(_loginProcessors, uuid, client.getName());
|
Pair<Integer, Pair<PermissionGroup, Set<PermissionGroup>>> result = _repository.login(_loginProcessors, uuid, client.getName());
|
||||||
|
|
||||||
client.setAccountId(result.getLeft());
|
client.setAccountId(result.getLeft());
|
||||||
|
|
||||||
if (result.getRight().getLeft() == null)
|
if (result.getRight().getLeft() == null)
|
||||||
{
|
{
|
||||||
//PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(token.Rank);
|
||||||
client.setPrimaryGroup(PermissionGroup.PLAYER);
|
client.setPrimaryGroup(newGroup);
|
||||||
_repository.setPrimaryGroup(client.getAccountId(), PermissionGroup.PLAYER, null);
|
_repository.setPrimaryGroup(client.getAccountId(), newGroup, null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -567,12 +586,10 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
|
|
||||||
if (client.getRawPrimaryGroup() == null)
|
if (client.getRawPrimaryGroup() == null)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
String mssqlRank = token.Rank;
|
String mssqlRank = token.Rank;
|
||||||
PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(mssqlRank);
|
PermissionGroup newGroup = PermissionGroupHelper.getGroupFromLegacy(mssqlRank);
|
||||||
*/
|
client.setPrimaryGroup(newGroup);
|
||||||
client.setPrimaryGroup(PermissionGroup.PLAYER);
|
_repository.setPrimaryGroup(client.getAccountId(), newGroup, null);
|
||||||
_repository.setPrimaryGroup(client.getAccountId(), PermissionGroup.PLAYER, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TimingManager.start(client.getName() + " Event.");
|
TimingManager.start(client.getName() + " Event.");
|
||||||
@ -586,7 +603,6 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
|
PlayerCache.getInstance().updateAccountId(uuid, client.getAccountId());
|
||||||
}
|
}
|
||||||
System.out.println(client.getPrimaryGroup().toString());
|
|
||||||
|
|
||||||
return !CLIENT_LOGIN_LOCKS.containsKey(client.getName());
|
return !CLIENT_LOGIN_LOCKS.containsKey(client.getName());
|
||||||
}
|
}
|
||||||
@ -873,7 +889,6 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
|
|
||||||
public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
|
public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
|
||||||
{
|
{
|
||||||
System.out.println("Query of processor " + processor.getName() + " " + processor.getQuery(1, "1", "1") + "\n");
|
|
||||||
_loginProcessors.add(processor);
|
_loginProcessors.add(processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,26 @@
|
|||||||
package mineplex.core.account.repository;
|
package mineplex.core.account.repository;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import mineplex.cache.player.PlayerCache;
|
import mineplex.cache.player.PlayerCache;
|
||||||
import mineplex.core.account.ILoginProcessor;
|
import mineplex.core.account.ILoginProcessor;
|
||||||
import mineplex.core.account.event.GroupAddEvent;
|
import mineplex.core.account.event.GroupAddEvent;
|
||||||
@ -15,15 +35,6 @@ import mineplex.core.database.MinecraftRepository;
|
|||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.column.ColumnInt;
|
import mineplex.serverdata.database.column.ColumnInt;
|
||||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class AccountRepository extends MinecraftRepository
|
public class AccountRepository extends MinecraftRepository
|
||||||
{
|
{
|
||||||
@ -119,7 +130,6 @@ public class AccountRepository extends MinecraftRepository
|
|||||||
// We can use a parallel stream because they will be in the correct order when we collect
|
// We can use a parallel stream because they will be in the correct order when we collect
|
||||||
loginString += loginProcessors.parallelStream().map(processor -> processor.getQuery(finalId, uuidString, name)).collect(Collectors.joining());
|
loginString += loginProcessors.parallelStream().map(processor -> processor.getQuery(finalId, uuidString, name)).collect(Collectors.joining());
|
||||||
|
|
||||||
|
|
||||||
statement.execute(loginString);
|
statement.execute(loginString);
|
||||||
|
|
||||||
System.out.println("EXECUTE COMPLETE - " + accountId);
|
System.out.println("EXECUTE COMPLETE - " + accountId);
|
||||||
@ -165,6 +175,7 @@ public class AccountRepository extends MinecraftRepository
|
|||||||
token.Name = name;
|
token.Name = name;
|
||||||
token.Uuid = uuid.toString();
|
token.Uuid = uuid.toString();
|
||||||
token.IpAddress = ipAddress;
|
token.IpAddress = ipAddress;
|
||||||
|
|
||||||
return handleSyncMSSQLCallStream("PlayerAccount/Login", token);
|
return handleSyncMSSQLCallStream("PlayerAccount/Login", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,24 @@
|
|||||||
package mineplex.core.bonuses;
|
package mineplex.core.bonuses;
|
||||||
|
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.sql.Types;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jooq.DSLContext;
|
||||||
|
import org.jooq.Record2;
|
||||||
|
import org.jooq.SQLDialect;
|
||||||
|
import org.jooq.TableField;
|
||||||
|
import org.jooq.impl.DSL;
|
||||||
|
|
||||||
import mineplex.core.common.Pair;
|
import mineplex.core.common.Pair;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
@ -10,17 +29,6 @@ import mineplex.database.tables.records.BonusRecord;
|
|||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
import mineplex.serverdata.database.ResultSetCallable;
|
import mineplex.serverdata.database.ResultSetCallable;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.jooq.DSLContext;
|
|
||||||
import org.jooq.Record2;
|
|
||||||
import org.jooq.SQLDialect;
|
|
||||||
import org.jooq.TableField;
|
|
||||||
import org.jooq.impl.DSL;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
public class BonusRepository extends RepositoryBase
|
public class BonusRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package mineplex.core.boosters;
|
package mineplex.core.boosters;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import mineplex.core.common.api.ApiEndpoint;
|
import mineplex.core.common.api.ApiEndpoint;
|
||||||
import mineplex.core.common.api.ApiFieldNamingStrategy;
|
import mineplex.core.common.api.ApiFieldNamingStrategy;
|
||||||
import mineplex.core.common.api.ApiHost;
|
import mineplex.core.common.api.ApiHost;
|
||||||
|
import mineplex.core.common.api.ApiResponse;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,6 +25,7 @@ public class BoosterRepository extends ApiEndpoint
|
|||||||
public BoosterRepository()
|
public BoosterRepository()
|
||||||
{
|
{
|
||||||
super(ApiHost.getAmplifierService(), "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
|
super(ApiHost.getAmplifierService(), "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
|
||||||
|
// .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
|
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,31 @@
|
|||||||
package mineplex.core.chat;
|
package mineplex.core.chat;
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import mineplex.core.account.CoreClient;
|
import javax.net.ssl.SSLContext;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import java.io.BufferedReader;
|
||||||
import mineplex.core.chat.command.*;
|
import java.io.DataOutputStream;
|
||||||
import mineplex.core.chat.event.FormatPlayerChatEvent;
|
import java.io.IOException;
|
||||||
import mineplex.core.chat.format.ChatFormatComponent;
|
import java.io.InputStreamReader;
|
||||||
import mineplex.core.common.util.*;
|
import java.net.URL;
|
||||||
import mineplex.core.incognito.IncognitoManager;
|
import java.nio.charset.Charset;
|
||||||
import mineplex.core.preferences.Preference;
|
import java.security.cert.X509Certificate;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import java.util.ArrayList;
|
||||||
import mineplex.core.preferences.UserPreferences;
|
import java.util.Arrays;
|
||||||
import mineplex.core.recharge.Recharge;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -30,17 +38,29 @@ import org.json.simple.JSONArray;
|
|||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import mineplex.core.MiniPlugin;
|
||||||
import java.io.BufferedReader;
|
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||||
import java.io.DataOutputStream;
|
import mineplex.core.account.CoreClient;
|
||||||
import java.io.IOException;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import java.io.InputStreamReader;
|
import mineplex.core.account.permissions.Permission;
|
||||||
import java.net.URL;
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
import java.nio.charset.Charset;
|
import mineplex.core.chat.command.BroadcastCommand;
|
||||||
import java.security.cert.X509Certificate;
|
import mineplex.core.chat.command.ChatSlowCommand;
|
||||||
import java.util.*;
|
import mineplex.core.chat.command.HelpCommand;
|
||||||
import java.util.Map.Entry;
|
import mineplex.core.chat.command.ListEmotesCommand;
|
||||||
import java.util.stream.Collectors;
|
import mineplex.core.chat.command.SilenceCommand;
|
||||||
|
import mineplex.core.chat.event.FormatPlayerChatEvent;
|
||||||
|
import mineplex.core.chat.format.ChatFormatComponent;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.common.util.UtilText;
|
||||||
|
import mineplex.core.common.util.UtilTime;
|
||||||
|
import mineplex.core.incognito.IncognitoManager;
|
||||||
|
import mineplex.core.preferences.Preference;
|
||||||
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
|
import mineplex.core.preferences.UserPreferences;
|
||||||
|
import mineplex.core.recharge.Recharge;
|
||||||
|
|
||||||
@ReflectivelyCreateMiniPlugin
|
@ReflectivelyCreateMiniPlugin
|
||||||
public class Chat extends MiniPlugin
|
public class Chat extends MiniPlugin
|
||||||
@ -864,7 +884,7 @@ public class Chat extends MiniPlugin
|
|||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
|
|
||||||
message = decapsifyIfNecessary(event.getPlayer(), message);
|
message = decapsifyIfNecessary(event.getPlayer(), message);
|
||||||
//message = filterMessage(event.getPlayer(), true, message);
|
message = filterMessage(event.getPlayer(), true, message);
|
||||||
|
|
||||||
event.setMessage(message);
|
event.setMessage(message);
|
||||||
}
|
}
|
||||||
@ -884,7 +904,6 @@ public class Chat extends MiniPlugin
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
@ -900,8 +919,6 @@ public class Chat extends MiniPlugin
|
|||||||
sign.update();
|
sign.update();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package mineplex.core.command;
|
package mineplex.core.command;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import java.lang.reflect.Field;
|
||||||
import mineplex.core.Managers;
|
import java.util.ArrayList;
|
||||||
import mineplex.core.account.CoreClient;
|
import java.util.Arrays;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import java.util.HashMap;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import java.util.HashSet;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import java.util.List;
|
||||||
import mineplex.core.common.util.*;
|
import java.util.Map;
|
||||||
import mineplex.core.packethandler.IPacketHandler;
|
import java.util.Set;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import java.util.UUID;
|
||||||
import mineplex.core.packethandler.PacketInfo;
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||||
import mineplex.core.recharge.Recharge;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete;
|
import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete;
|
||||||
|
//import net.minecraft.server.v1_8_R3.PacketPlayOutDeclareCommands;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
|
||||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -23,9 +25,24 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import com.google.common.collect.Lists;
|
||||||
import java.util.*;
|
//import com.mineplex.ProtocolVersion;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
|
||||||
|
import mineplex.core.Managers;
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.account.permissions.Permission;
|
||||||
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilPlayerBase;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.packethandler.IPacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketInfo;
|
||||||
|
import mineplex.core.recharge.Recharge;
|
||||||
|
|
||||||
public class CommandCenter implements Listener, IPacketHandler
|
public class CommandCenter implements Listener, IPacketHandler
|
||||||
{
|
{
|
||||||
@ -200,9 +217,8 @@ public class CommandCenter implements Listener, IPacketHandler
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
int protocol = UtilPlayer.getProtocol(event.getPlayer());
|
|
||||||
/*
|
/*
|
||||||
TODO: Protocol Support
|
int protocol = UtilPlayer.getProtocol(event.getPlayer());
|
||||||
if (protocol >= ProtocolVersion.v1_13)
|
if (protocol >= ProtocolVersion.v1_13)
|
||||||
{
|
{
|
||||||
List<String> commands = getCommands(event.getPlayer());
|
List<String> commands = getCommands(event.getPlayer());
|
||||||
@ -217,14 +233,12 @@ public class CommandCenter implements Listener, IPacketHandler
|
|||||||
if (packetInfo.getPacket() instanceof PacketPlayInTabComplete)
|
if (packetInfo.getPacket() instanceof PacketPlayInTabComplete)
|
||||||
{
|
{
|
||||||
EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
||||||
|
//TODO: Multi-protocol support
|
||||||
/*
|
/*
|
||||||
|
|
||||||
TODO: ProtocolSupport
|
|
||||||
if (nmsPlayer.getProtocol() >= ProtocolVersion.v1_13)
|
if (nmsPlayer.getProtocol() >= ProtocolVersion.v1_13)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PacketPlayInTabComplete packet = (PacketPlayInTabComplete) packetInfo.getPacket();
|
PacketPlayInTabComplete packet = (PacketPlayInTabComplete) packetInfo.getPacket();
|
||||||
|
@ -186,8 +186,8 @@ public class CosmeticManager extends MiniPlugin
|
|||||||
|
|
||||||
public void setInterfaceSlot(int i)
|
public void setInterfaceSlot(int i)
|
||||||
{
|
{
|
||||||
System.out.println(_gadgetManager.toString());
|
|
||||||
_interfaceSlot = i;
|
_interfaceSlot = i;
|
||||||
|
|
||||||
_gadgetManager.setActiveItemSlot(i-1);
|
_gadgetManager.setActiveItemSlot(i-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,45 @@
|
|||||||
package mineplex.core.disguise;
|
package mineplex.core.disguise;
|
||||||
|
|
||||||
import com.mineplex.spigot.ChunkAddEntityEvent;
|
import java.lang.reflect.Field;
|
||||||
import mineplex.core.MiniPlugin;
|
import java.util.ArrayList;
|
||||||
import mineplex.core.PlayerSelector;
|
import java.util.HashMap;
|
||||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
import java.util.HashSet;
|
||||||
import mineplex.core.common.util.*;
|
import java.util.Iterator;
|
||||||
import mineplex.core.disguise.disguises.*;
|
import java.util.LinkedList;
|
||||||
import mineplex.core.packethandler.IPacketHandler;
|
import java.util.List;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import java.util.Map;
|
||||||
import mineplex.core.packethandler.PacketInfo;
|
import java.util.Set;
|
||||||
import mineplex.core.packethandler.PacketVerifier;
|
import java.util.UUID;
|
||||||
import mineplex.core.updater.UpdateType;
|
import java.util.function.Predicate;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
|
||||||
import net.minecraft.server.v1_8_R3.*;
|
import net.minecraft.server.v1_8_R3.BlockBed;
|
||||||
|
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_8_R3.Blocks;
|
||||||
|
import net.minecraft.server.v1_8_R3.Chunk;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||||
|
import net.minecraft.server.v1_8_R3.EnumDirection;
|
||||||
|
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||||
|
import net.minecraft.server.v1_8_R3.Packet;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutBed;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutEntityLook;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutEntityLook;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMove;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMove;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityVelocity;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutMapChunk;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutUpdateAttributes;
|
||||||
|
//import net.minecraft.server.v1_8_R3.PacketPlayOutVehicleMove;
|
||||||
|
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||||
|
import net.minecraft.server.v1_8_R3.WorldSettings;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -34,8 +58,29 @@ import org.bukkit.scoreboard.NameTagVisibility;
|
|||||||
import org.bukkit.scoreboard.Scoreboard;
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import java.util.*;
|
import com.mineplex.spigot.ChunkAddEntityEvent;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
import mineplex.core.MiniPlugin;
|
||||||
|
import mineplex.core.PlayerSelector;
|
||||||
|
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.common.util.UtilEnt;
|
||||||
|
import mineplex.core.common.util.UtilLambda;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.common.util.UtilTasks;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseBase;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseBlock;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseInsentient;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseLiving;
|
||||||
|
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseSquid;
|
||||||
|
import mineplex.core.packethandler.IPacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
|
import mineplex.core.packethandler.PacketInfo;
|
||||||
|
import mineplex.core.packethandler.PacketVerifier;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* notes: rabbit jump has been removed (PacketPlayOutEntityStatus) because it didn't work for 1.9+ anyways
|
* notes: rabbit jump has been removed (PacketPlayOutEntityStatus) because it didn't work for 1.9+ anyways
|
||||||
@ -352,6 +397,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
final Packet packet = packetInfo.getPacket();
|
final Packet packet = packetInfo.getPacket();
|
||||||
final Player owner = packetInfo.getPlayer();
|
final Player owner = packetInfo.getPlayer();
|
||||||
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
||||||
|
//final int protocol = ((CraftPlayer) owner).getHandle().getProtocol();
|
||||||
final int protocol = ((CraftPlayer) owner).getHandle().playerConnection.networkManager.getVersion();
|
final int protocol = ((CraftPlayer) owner).getHandle().playerConnection.networkManager.getVersion();
|
||||||
|
|
||||||
if (packet instanceof PacketPlayOutPlayerInfo)
|
if (packet instanceof PacketPlayOutPlayerInfo)
|
||||||
@ -653,6 +699,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
if (disguise.getEntity() == nmsPlayer)
|
if (disguise.getEntity() == nmsPlayer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
//int protocol = nmsPlayer.getProtocol();
|
||||||
int protocol = nmsPlayer.playerConnection.networkManager.getVersion();
|
int protocol = nmsPlayer.playerConnection.networkManager.getVersion();
|
||||||
UtilPlayer.sendPacket(player, disguise.modifyMetaPacket(protocol, disguise.getMetadataPacket()));
|
UtilPlayer.sendPacket(player, disguise.modifyMetaPacket(protocol, disguise.getMetadataPacket()));
|
||||||
}
|
}
|
||||||
@ -777,9 +824,14 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
List<Packet> packets = new ArrayList<>();
|
List<Packet> packets = new ArrayList<>();
|
||||||
|
|
||||||
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
|
EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
|
||||||
|
//int protocol = nmsPlayer.getProtocol();
|
||||||
int protocol = nmsPlayer.playerConnection.networkManager.getVersion();
|
int protocol = nmsPlayer.playerConnection.networkManager.getVersion();
|
||||||
|
|
||||||
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
|
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
|
||||||
|
//TODO: Multi-protocol support
|
||||||
|
/*
|
||||||
|
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff');
|
||||||
|
|
||||||
|
*/
|
||||||
chunk.a = BED_POS_NORTH[0] >> 4;
|
chunk.a = BED_POS_NORTH[0] >> 4;
|
||||||
chunk.b = BED_POS_NORTH[2] >> 4;
|
chunk.b = BED_POS_NORTH[2] >> 4;
|
||||||
|
|
||||||
@ -830,6 +882,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
double d2 = posZ + (targetZ - posZ) / (double) partitions;
|
double d2 = posZ + (targetZ - posZ) / (double) partitions;
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Protocol support
|
||||||
|
//PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff');
|
||||||
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
|
PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff');
|
||||||
chunk.a = (int) Math.floor(d0) >> 4;
|
chunk.a = (int) Math.floor(d0) >> 4;
|
||||||
chunk.b = (int) Math.floor(d2) >> 4;
|
chunk.b = (int) Math.floor(d2) >> 4;
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
import mineplex.core.common.DummyEntity;
|
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R3.*;
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -15,6 +7,16 @@ import java.util.List;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.*;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import mineplex.core.common.DummyEntity;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
|
||||||
public abstract class DisguiseBase
|
public abstract class DisguiseBase
|
||||||
{
|
{
|
||||||
private WeakReference<Entity> _entity = new WeakReference<>(null);
|
private WeakReference<Entity> _entity = new WeakReference<>(null);
|
||||||
@ -87,6 +89,7 @@ public abstract class DisguiseBase
|
|||||||
|
|
||||||
for (EntityPlayer player : tracker.get(getEntity().getId()).trackedPlayers)
|
for (EntityPlayer player : tracker.get(getEntity().getId()).trackedPlayers)
|
||||||
{
|
{
|
||||||
|
//int protocol = player.getProtocol();
|
||||||
int protocol = player.playerConnection.networkManager.getVersion();
|
int protocol = player.playerConnection.networkManager.getVersion();
|
||||||
if (!protocolPredicate.test(protocol))
|
if (!protocolPredicate.test(protocol))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
import java.util.ArrayList;
|
||||||
import net.minecraft.server.v1_8_R3.Packet;
|
import java.util.Iterator;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
import java.util.List;
|
||||||
|
|
||||||
|
//import com.mineplex.MetadataRewriter;
|
||||||
|
//import com.mineplex.ProtocolVersion;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.*;
|
||||||
|
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
|
||||||
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public abstract class DisguiseCreature extends DisguiseInsentient
|
public abstract class DisguiseCreature extends DisguiseInsentient
|
||||||
@ -78,8 +85,8 @@ public abstract class DisguiseCreature extends DisguiseInsentient
|
|||||||
@Override
|
@Override
|
||||||
public Packet modifySpawnPacket(int protocol, Packet packet)
|
public Packet modifySpawnPacket(int protocol, Packet packet)
|
||||||
{
|
{
|
||||||
|
//TODO: Multi-protocol support
|
||||||
/*
|
/*
|
||||||
TODO: Protocol Support/Prob Never since i dont have their MetadataWriter
|
|
||||||
if (protocol >= ProtocolVersion.v1_10_PRE)
|
if (protocol >= ProtocolVersion.v1_10_PRE)
|
||||||
{
|
{
|
||||||
PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket();
|
PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket();
|
||||||
@ -126,7 +133,6 @@ public abstract class DisguiseCreature extends DisguiseInsentient
|
|||||||
newSpawn.m = meta;
|
newSpawn.m = meta;
|
||||||
return newSpawn;
|
return newSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return packet;
|
return packet;
|
||||||
@ -142,9 +148,8 @@ public abstract class DisguiseCreature extends DisguiseInsentient
|
|||||||
@Override
|
@Override
|
||||||
public Packet modifyMetaPacket(int protocol, Packet packet)
|
public Packet modifyMetaPacket(int protocol, Packet packet)
|
||||||
{
|
{
|
||||||
|
//TODO: Multi-protocol support
|
||||||
/*
|
/*
|
||||||
|
|
||||||
TODO: Again Protocol Support/Prob never since i dont have their metadatawriter
|
|
||||||
if (protocol >= ProtocolVersion.v1_10_PRE)
|
if (protocol >= ProtocolVersion.v1_10_PRE)
|
||||||
{
|
{
|
||||||
PacketPlayOutEntityMetadata newMeta = new PacketPlayOutEntityMetadata();
|
PacketPlayOutEntityMetadata newMeta = new PacketPlayOutEntityMetadata();
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import net.minecraft.server.v1_8_R3.*;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_8_R3.Block;
|
||||||
|
import net.minecraft.server.v1_8_R3.Blocks;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityEnderman;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityLiving;
|
||||||
|
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||||
|
import net.minecraft.server.v1_8_R3.MobEffect;
|
||||||
|
import net.minecraft.server.v1_8_R3.MobEffectList;
|
||||||
|
import net.minecraft.server.v1_8_R3.PotionBrewer;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public class DisguiseEnderman extends DisguiseMonster
|
public class DisguiseEnderman extends DisguiseMonster
|
||||||
{
|
{
|
||||||
public DisguiseEnderman(org.bukkit.entity.Entity entity)
|
public DisguiseEnderman(org.bukkit.entity.Entity entity)
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
//import com.mineplex.ProtocolVersion;
|
||||||
|
|
||||||
import net.minecraft.server.v1_8_R3.Packet;
|
import net.minecraft.server.v1_8_R3.Packet;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
@ -19,12 +24,13 @@ public abstract class DisguiseMutable extends DisguiseCreature
|
|||||||
{
|
{
|
||||||
// if (!_spawnedIn)
|
// if (!_spawnedIn)
|
||||||
// return;
|
// return;
|
||||||
|
//TODO: Multi-protocol support
|
||||||
|
//Basically sends to players that are > 1.11 but impossible
|
||||||
/*
|
/*
|
||||||
Predicate<Integer> pred = v -> v >= ProtocolVersion.v1_11;
|
Predicate<Integer> pred = v -> v >= ProtocolVersion.v1_11;
|
||||||
sendToWatchers(pred, this::getDestroyPacket);
|
sendToWatchers(pred, this::getDestroyPacket);
|
||||||
sendToWatchers(pred, this::getSpawnPacket);
|
sendToWatchers(pred, this::getSpawnPacket);
|
||||||
sendToWatchers(pred, this::getMetadataPacket);
|
sendToWatchers(pred, this::getMetadataPacket);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityTameableAnimal;
|
import net.minecraft.server.v1_8_R3.EntityTameableAnimal;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public abstract class DisguiseTameableAnimal extends DisguiseAnimal
|
public abstract class DisguiseTameableAnimal extends DisguiseAnimal
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user