Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex into ResourcePack
Conflicts: Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java
This commit is contained in:
commit
9f8fe3bf78
@ -17,8 +17,8 @@
|
|||||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-pool2-2.2.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-pool2-2.2.jar" path-in-jar="/" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jedis-2.4.2.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jedis-2.4.2.jar" path-in-jar="/" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/gson-2.2.1.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/gson-2.2.1.jar" path-in-jar="/" />
|
||||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.4.2.jar" path-in-jar="/" />
|
|
||||||
<element id="module-output" name="Mineplex.Database" />
|
<element id="module-output" name="Mineplex.Database" />
|
||||||
|
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.5.2.jar" path-in-jar="/" />
|
||||||
</root>
|
</root>
|
||||||
</artifact>
|
</artifact>
|
||||||
</component>
|
</component>
|
@ -14,6 +14,7 @@
|
|||||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.BungeeSigns/Mineplex.Minecraft.BungeeSigns.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.BungeeSigns/Mineplex.Minecraft.BungeeSigns.iml" group="Bungee" />
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.BungeeSigns/Mineplex.Minecraft.BungeeSigns.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.BungeeSigns/Mineplex.Minecraft.BungeeSigns.iml" group="Bungee" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" group="Game" />
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" group="Game" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" group="Game" />
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" group="Game" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" filepath="$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" filepath="$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" group="Core" />
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" filepath="$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" group="Core" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" filepath="$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" group="Core" />
|
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" filepath="$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" group="Core" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" filepath="$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" group="Game" />
|
<module fileurl="file://$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" filepath="$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" group="Game" />
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
<fileset dir="../Mineplex.EnjinTranslator">
|
<fileset dir="../Mineplex.EnjinTranslator">
|
||||||
<include name="*.yml"/>
|
<include name="*.yml"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="../Mineplex.ServerData/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<zipfileset src="../Libraries/jooq-3.5.2.jar" />
|
<zipfileset src="../Libraries/jooq-3.5.2.jar" />
|
||||||
<zipfileset src="../Libraries/httpclient-4.2.jar" />
|
<zipfileset src="../Libraries/httpclient-4.2.jar" />
|
||||||
|
@ -224,6 +224,10 @@
|
|||||||
<include name="**/*.class"/>
|
<include name="**/*.class"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
|
||||||
|
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||||
<zipfileset src="../Libraries/commons-io-2.4.jar" />
|
<zipfileset src="../Libraries/commons-io-2.4.jar" />
|
||||||
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
|
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
|
||||||
@ -264,6 +268,9 @@
|
|||||||
<fileset dir="../Mineplex.BungeeRotator/bin">
|
<fileset dir="../Mineplex.BungeeRotator/bin">
|
||||||
<include name="**/*.class"/>
|
<include name="**/*.class"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="../Mineplex.ServerData/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<zipfileset src="../Libraries/mysql.zip" />
|
<zipfileset src="../Libraries/mysql.zip" />
|
||||||
|
|
||||||
@ -276,10 +283,14 @@
|
|||||||
<zipfileset src="../Libraries/httpcore-4.2.jar" />
|
<zipfileset src="../Libraries/httpcore-4.2.jar" />
|
||||||
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
||||||
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/jooq-3.5.2.jar" />
|
||||||
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
||||||
<zipfileset src="../Libraries/javax.mail.jar" />
|
|
||||||
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
||||||
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-dbcp2-2.0.1.jar" />
|
||||||
|
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-dbcp2-2.0.1.jar" />
|
||||||
</jar>
|
</jar>
|
||||||
<copy file="../bin/BungeeRotator.jar" todir="../../Testing/BungeeRotator/"/>
|
<copy file="../bin/BungeeRotator.jar" todir="../../Testing/BungeeRotator/"/>
|
||||||
</target>
|
</target>
|
||||||
@ -314,6 +325,33 @@
|
|||||||
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
||||||
</jar>
|
</jar>
|
||||||
<copy file="../bin/ServerMonitor.jar" todir="../../Testing/ServerMonitor/"/>
|
<copy file="../bin/ServerMonitor.jar" todir="../../Testing/ServerMonitor/"/>
|
||||||
|
</target>
|
||||||
|
<target name ="ChestConverter" description="ChestConverter">
|
||||||
|
<jar jarfile="../bin/ChestConverter.jar">
|
||||||
|
<fileset dir="../Mineplex.Core.Common/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="../Mineplex.ChestConverter/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<zipfileset src="../Libraries/mysql.zip" />
|
||||||
|
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class"
|
||||||
|
value="mineplex.chestConverter.ChestConverter"/>
|
||||||
|
</manifest>
|
||||||
|
|
||||||
|
<zipfileset src="../Libraries/httpclient-4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/httpcore-4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
||||||
|
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||||
|
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
||||||
|
</jar>
|
||||||
|
<copy file="../bin/ChestConverter.jar" todir="../../Testing/ChestConverter/"/>
|
||||||
</target>
|
</target>
|
||||||
<target name ="Queuer" description="Queuer">
|
<target name ="Queuer" description="Queuer">
|
||||||
<jar jarfile="../bin/Queuer.jar">
|
<jar jarfile="../bin/Queuer.jar">
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package net.minecraft.server.v1_7_R4;
|
package net.minecraft.server.v1_7_R4;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.scoreboard.CraftScoreboard;
|
import org.bukkit.craftbukkit.v1_7_R4.scoreboard.CraftScoreboard;
|
||||||
@ -16,6 +17,11 @@ import net.minecraft.util.com.mojang.authlib.properties.Property;
|
|||||||
import net.minecraft.util.com.mojang.authlib.properties.PropertyMap;
|
import net.minecraft.util.com.mojang.authlib.properties.PropertyMap;
|
||||||
|
|
||||||
public class PacketPlayOutPlayerInfo extends Packet {
|
public class PacketPlayOutPlayerInfo extends Packet {
|
||||||
|
|
||||||
|
public static final String NOTCH_SKIN = "eyJ0aW1lc3RhbXAiOjE0Mjc4MjgyMzMwNDUsInByb2ZpbGVJZCI6IjA2OWE3OWY0NDRlOTQ3MjZhNWJlZmNhOTBlMzhhYWY1IiwicHJvZmlsZU5hbWUiOiJOb3RjaCIsImlzUHVibGljIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTExNmU2OWE4NDVlMjI3ZjdjYTFmZGRlOGMzNTdjOGM4MjFlYmQ0YmE2MTkzODJlYTRhMWY4N2Q0YWU5NCJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvM2Y2ODhlMGU2OTliM2Q5ZmU0NDhiNWJiNTBhM2EyODhmOWM1ODk3NjJiM2RhZTgzMDg4NDIxMjJkY2I4MSJ9fX0=";
|
||||||
|
public static final String NOTCH_SIGNATURE = "WrBmNqkpkjh6VJY26jOOMNS6oSOPi0MTm9WWc0t4EMUHchUbTd6/1sT2O2zz2s7xwmCeUxuIhvRREa+1bIPzIIbXJLjhxiBWMdTJbQhv6zBb1U2SZb7eb5cYrFTD6rvxy0rOarScxCBdeOXpr1coxrvN8a6VkgLhc/dGhFx0ZmORxELBLFiCNi+4WE//MI+KioAq84Gdf0ltT9ZLWdlHNFV2ynBgcx2MfNTA2lrpdKEUVOYD7xhPoOdHa5d1hzdDxbYPGDgM0FzYjzNUlBx8SLvHEpyBB7XyOsIGnfqrS0ltIDTq82wgLrEwDRncuQN18w6IiQbNK06MZBDyNnIp79mmUYvRj+Zl0dPBrZok2q2uQ08hZ87ufU3jhjY39kr+iEaPYMvfWaBxt3ALjopsZRCGSlEukMzITjeYxhfVKuQ0fhWKRfwWn/Jv2de2h+i+t7nulvN3MV3rJVrS6OXsx87p/vm9biU7Hs07T8VSGONfkxXmsgYEtY6m2egU5pmqFnsKM0MwwnZJ7Sxz2EjiPikoGzJzpv4ncj3rhelIKJKjDk9jSAz7nPzc8/UdOiTrfy4ezr3jFVAVatiKr+kS/HNXHWiCFdufhpG4DVCrSkwkFBJw030pJ6ICVhpuYq5yOswQB5QOp0JDWc2Rdth7SVmvxthSCL9G2ksfm+v7sKw=";
|
||||||
|
|
||||||
|
|
||||||
public static final int ADD_PLAYER = 0;
|
public static final int ADD_PLAYER = 0;
|
||||||
public static final int UPDATE_GAMEMODE = 1;
|
public static final int UPDATE_GAMEMODE = 1;
|
||||||
public static final int UPDATE_LATENCY = 2;
|
public static final int UPDATE_LATENCY = 2;
|
||||||
@ -38,6 +44,7 @@ public class PacketPlayOutPlayerInfo extends Packet {
|
|||||||
packet.player = player.getProfile();
|
packet.player = player.getProfile();
|
||||||
packet.ping = player.ping;
|
packet.ping = player.ping;
|
||||||
packet.gamemode = player.playerInteractManager.getGameMode().getId();
|
packet.gamemode = player.playerInteractManager.getGameMode().getId();
|
||||||
|
|
||||||
packet._tabName = getFormattedName(player);
|
packet._tabName = getFormattedName(player);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
@ -87,6 +94,9 @@ public class PacketPlayOutPlayerInfo extends Packet {
|
|||||||
|
|
||||||
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
||||||
if(packetdataserializer.version >= 20) {
|
if(packetdataserializer.version >= 20) {
|
||||||
|
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
|
||||||
packetdataserializer.b(this.action);
|
packetdataserializer.b(this.action);
|
||||||
packetdataserializer.b(1);
|
packetdataserializer.b(1);
|
||||||
packetdataserializer.writeUUID(this.player.getId());
|
packetdataserializer.writeUUID(this.player.getId());
|
||||||
@ -94,16 +104,41 @@ public class PacketPlayOutPlayerInfo extends Packet {
|
|||||||
case 0:
|
case 0:
|
||||||
packetdataserializer.a(this.player.getName());
|
packetdataserializer.a(this.player.getName());
|
||||||
PropertyMap properties = this.player.getProperties();
|
PropertyMap properties = this.player.getProperties();
|
||||||
|
|
||||||
|
// April Fools
|
||||||
|
if (isAprilFools() && properties.size() == 0)
|
||||||
|
{
|
||||||
|
// add texture if no textures exist
|
||||||
|
properties.put("textures", new Property("textures", NOTCH_SKIN, NOTCH_SIGNATURE));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
packetdataserializer.b(properties.size());
|
packetdataserializer.b(properties.size());
|
||||||
Iterator var3 = properties.values().iterator();
|
Iterator var3 = properties.values().iterator();
|
||||||
|
|
||||||
while(var3.hasNext()) {
|
while(var3.hasNext()) {
|
||||||
Property property = (Property)var3.next();
|
Property property = (Property)var3.next();
|
||||||
packetdataserializer.a(property.getName());
|
|
||||||
packetdataserializer.a(property.getValue());
|
// April Fools
|
||||||
packetdataserializer.writeBoolean(property.hasSignature());
|
if (isAprilFools() && property.getName().equalsIgnoreCase("textures"))
|
||||||
if(property.hasSignature()) {
|
{
|
||||||
packetdataserializer.a(property.getSignature());
|
System.out.println("Applying notch texture for : " + property.getName());
|
||||||
|
System.out.println("Skin: " + property.getValue());
|
||||||
|
System.out.println("Signature: " + property.getSignature());
|
||||||
|
packetdataserializer.a(property.getName());
|
||||||
|
packetdataserializer.a(NOTCH_SKIN);
|
||||||
|
packetdataserializer.writeBoolean(true);
|
||||||
|
packetdataserializer.a(NOTCH_SIGNATURE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
packetdataserializer.a(property.getName());
|
||||||
|
packetdataserializer.a(property.getValue());
|
||||||
|
|
||||||
|
packetdataserializer.writeBoolean(property.hasSignature());
|
||||||
|
if(property.hasSignature()) {
|
||||||
|
packetdataserializer.a(property.getSignature());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +184,8 @@ public class PacketPlayOutPlayerInfo extends Packet {
|
|||||||
{
|
{
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
|
|
||||||
|
if (isAprilFools()) name = "Notch";
|
||||||
|
|
||||||
CraftScoreboard scoreboard = player.getBukkitEntity().getScoreboard();
|
CraftScoreboard scoreboard = player.getBukkitEntity().getScoreboard();
|
||||||
if (scoreboard != null)
|
if (scoreboard != null)
|
||||||
{
|
{
|
||||||
@ -159,4 +196,12 @@ public class PacketPlayOutPlayerInfo extends Packet {
|
|||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAprilFools()
|
||||||
|
{
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
|
||||||
|
// return true;
|
||||||
|
return c.get(Calendar.MONTH) == Calendar.APRIL && c.get(Calendar.DAY_OF_MONTH) == 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
BIN
Plugins/Libraries/jackson-annotations-2.5.0.jar
Normal file
BIN
Plugins/Libraries/jackson-annotations-2.5.0.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/jackson-core-2.5.1.jar
Normal file
BIN
Plugins/Libraries/jackson-core-2.5.1.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/jackson-databind-2.5.1.jar
Normal file
BIN
Plugins/Libraries/jackson-databind-2.5.1.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/jersey-apache-client-1.19.jar
Normal file
BIN
Plugins/Libraries/jersey-apache-client-1.19.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/jersey-bundle-1.17.jar
Normal file
BIN
Plugins/Libraries/jersey-bundle-1.17.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/jersey-multipart-1.19.jar
Normal file
BIN
Plugins/Libraries/jersey-multipart-1.19.jar
Normal file
Binary file not shown.
BIN
Plugins/Libraries/slf4j-api-1.7.10.jar
Normal file
BIN
Plugins/Libraries/slf4j-api-1.7.10.jar
Normal file
Binary file not shown.
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -13,5 +13,6 @@
|
|||||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
<orderEntry type="library" name="httpcore" level="project" />
|
<orderEntry type="library" name="httpcore" level="project" />
|
||||||
<orderEntry type="library" name="httpclient" level="project" />
|
<orderEntry type="library" name="httpclient" level="project" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.PlayerCache" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,6 +1,5 @@
|
|||||||
package mineplex.bungee;
|
package mineplex.bungee;
|
||||||
|
|
||||||
import mineplex.bungee.account.AccountManager;
|
|
||||||
import mineplex.bungee.lobbyBalancer.LobbyBalancer;
|
import mineplex.bungee.lobbyBalancer.LobbyBalancer;
|
||||||
import mineplex.bungee.motd.MotdManager;
|
import mineplex.bungee.motd.MotdManager;
|
||||||
import mineplex.bungee.playerCount.PlayerCount;
|
import mineplex.bungee.playerCount.PlayerCount;
|
||||||
@ -19,8 +18,7 @@ public class Mineplexer extends Plugin
|
|||||||
PlayerCount playerCount = new PlayerCount(this);
|
PlayerCount playerCount = new PlayerCount(this);
|
||||||
new FileUpdater(this);
|
new FileUpdater(this);
|
||||||
new PlayerStats(this);
|
new PlayerStats(this);
|
||||||
new InternetStatus(this);
|
//new InternetStatus(this);
|
||||||
new PlayerTracker(this);
|
new PlayerTracker(this);
|
||||||
new AccountManager(this, playerCount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import mineplex.bungee.playerCount.PlayerCount;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
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 AccountManager implements Listener, Runnable
|
|
||||||
{
|
|
||||||
private Plugin _plugin;
|
|
||||||
private PlayerCount _playerCount;
|
|
||||||
private int _playerCap = -1;
|
|
||||||
private AccountManagerRepository _repository;
|
|
||||||
|
|
||||||
private Gson _gson = new Gson();
|
|
||||||
|
|
||||||
public AccountManager(Plugin plugin, PlayerCount playerCount)
|
|
||||||
{
|
|
||||||
_plugin = plugin;
|
|
||||||
_playerCount = playerCount;
|
|
||||||
|
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
|
||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 10L, 10L, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
_repository = new AccountManagerRepository();
|
|
||||||
_repository.initialize();
|
|
||||||
_playerCap = _repository.retrievePlayerCap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void login(LoginEvent event)
|
|
||||||
{
|
|
||||||
if (_playerCap == -1 || _playerCount.getTotalPlayers() <= _playerCap)
|
|
||||||
return;
|
|
||||||
|
|
||||||
String response = getClient(event.getConnection().getName(), event.getConnection().getUniqueId(), event.getConnection().getAddress().toString());
|
|
||||||
|
|
||||||
ClientToken token = _gson.fromJson(response, ClientToken.class);
|
|
||||||
|
|
||||||
if (token.Rank.equalsIgnoreCase("ALL"))
|
|
||||||
{
|
|
||||||
event.setCancelled(true);
|
|
||||||
event.setCancelReason("§fDue to server issues, we have added a §cplayer limit§f.\n"
|
|
||||||
+ "§fWe hope to have this resolved soon, §nplease be ptient§r.\n"
|
|
||||||
+ "§fPlayers with Ranks can still join the server!\n\n"
|
|
||||||
+ "§fPurchase Ranks at §awww.mineplex.com/shop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getClient(String name, UUID uuid, String ipAddress)
|
|
||||||
{
|
|
||||||
LoginToken token = new LoginToken();
|
|
||||||
token.Name = name;
|
|
||||||
token.Uuid = uuid.toString();
|
|
||||||
token.IpAddress = ipAddress;
|
|
||||||
|
|
||||||
return new JsonWebCall("http://accounts.mineplex.com/PlayerAccount/Login").ExecuteReturnStream(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_playerCap = _repository.retrievePlayerCap();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class AccountManagerRepository
|
|
||||||
{
|
|
||||||
private Connection _connection = null;
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS playerCap (id INT NOT NULL AUTO_INCREMENT, playerCap INT, PRIMARY KEY (id));";
|
|
||||||
private static String RETRIEVE_PLAYERCAP = "SELECT playerCap FROM playerCap;";
|
|
||||||
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Initialized AccountManager.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int retrievePlayerCap()
|
|
||||||
{
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERCAP);
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
return resultSet.getInt(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 -1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class AccountToken
|
|
||||||
{
|
|
||||||
public int AccountId;
|
|
||||||
public String Name;
|
|
||||||
public RankToken Rank;
|
|
||||||
|
|
||||||
public int LoginCount;
|
|
||||||
public long LastLogin;
|
|
||||||
public long TotalPlayingTime;
|
|
||||||
public HashSet<String> IpAdddresses = new HashSet<String>();
|
|
||||||
|
|
||||||
public boolean Banned;
|
|
||||||
public String Reason;
|
|
||||||
|
|
||||||
public int BlueGems;
|
|
||||||
public int GreenGems;
|
|
||||||
public List<Integer> SalesPackageIds;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
public interface Callback<T>
|
|
||||||
{
|
|
||||||
public void run(T data);
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
public class ClientToken
|
|
||||||
{
|
|
||||||
public int AccountId;
|
|
||||||
public String Name;
|
|
||||||
public String Rank;
|
|
||||||
public boolean RankPerm;
|
|
||||||
public String RankExpire;
|
|
||||||
public int EconomyBalance;
|
|
||||||
|
|
||||||
public AccountToken AccountToken;
|
|
||||||
public long LastLogin;
|
|
||||||
}
|
|
@ -1,355 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
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.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)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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> 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());
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
public class LoginToken
|
|
||||||
{
|
|
||||||
public String Name;
|
|
||||||
public String IpAddress = "0.0.0.0";
|
|
||||||
public String MacAddress = "00-00-00-00-00-00-00-00";
|
|
||||||
public String Uuid;
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package mineplex.bungee.account;
|
|
||||||
|
|
||||||
public class RankToken
|
|
||||||
{
|
|
||||||
public int RankId;
|
|
||||||
|
|
||||||
public String Name;
|
|
||||||
}
|
|
@ -8,10 +8,11 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import mineplex.serverdata.MinecraftServer;
|
|
||||||
import mineplex.serverdata.Region;
|
import mineplex.serverdata.Region;
|
||||||
import mineplex.serverdata.ServerManager;
|
import mineplex.serverdata.data.MinecraftServer;
|
||||||
import mineplex.serverdata.ServerRepository;
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import mineplex.serverdata.servers.ServerRepository;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
@ -37,7 +38,7 @@ public class LobbyBalancer implements Listener, Runnable
|
|||||||
loadLobbyServers();
|
loadLobbyServers();
|
||||||
|
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 150L, 150L, TimeUnit.MILLISECONDS);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 250L, 250L, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -2,7 +2,7 @@ package mineplex.bungee.lobbyBalancer;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
import mineplex.serverdata.MinecraftServer;
|
import mineplex.serverdata.data.MinecraftServer;
|
||||||
|
|
||||||
public class LobbySorter implements Comparator<MinecraftServer>
|
public class LobbySorter implements Comparator<MinecraftServer>
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,189 +0,0 @@
|
|||||||
package mineplex.bungee.motd;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.Favicon;
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
||||||
import net.md_5.bungee.connection.CustomMotd;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.protocol.packet.PingPacket;
|
|
||||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
|
||||||
|
|
||||||
public class Motd implements CustomMotd
|
|
||||||
{
|
|
||||||
private static final int MAX_TICKS = 30;
|
|
||||||
private static final char SNOWFLAKE = '❅';
|
|
||||||
private static final String SNOWMAN = ChatColor.WHITE + "☃" + ChatColor.RESET;
|
|
||||||
private static final String LEFT_SWORD = "§b§l§m §8§l§m[ §r";
|
|
||||||
private static final String RIGHT_SWORD = "§8§l§m ]§b§l§m §r";
|
|
||||||
private static final ChatColor[] COLOR_ROTATION =
|
|
||||||
{ChatColor.RED, ChatColor.LIGHT_PURPLE, ChatColor.GOLD, ChatColor.BLUE, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.AQUA};
|
|
||||||
private static List<Favicon> ICON_FRAMES;
|
|
||||||
|
|
||||||
private MotdManager _manager;
|
|
||||||
private ScheduledFuture _task;
|
|
||||||
private int _ticks = 0;
|
|
||||||
|
|
||||||
public Motd(MotdManager manager)
|
|
||||||
{
|
|
||||||
_manager = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handlePing(final ProxyPingEvent pingResult, final InitialHandler initialHandler)
|
|
||||||
{
|
|
||||||
BungeeCord.getInstance().getConnectionThrottle().unthrottle(initialHandler.getAddress().getAddress());
|
|
||||||
final Gson gson = initialHandler.getHandshake().getProtocolVersion() == 4?BungeeCord.getInstance().gsonLegacy:BungeeCord.getInstance().gson;
|
|
||||||
|
|
||||||
_task = initialHandler.getChannelWrapper().getHandle().eventLoop().scheduleAtFixedRate(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (initialHandler.getChannelWrapper().getHandle().isOpen() && _ticks <= MAX_TICKS)
|
|
||||||
{
|
|
||||||
ServerPing ping = pingResult.getResponse();
|
|
||||||
|
|
||||||
String desc = getDesc();
|
|
||||||
ping.setDescription(desc);
|
|
||||||
|
|
||||||
Favicon icon = getIcon();
|
|
||||||
if (icon != null)
|
|
||||||
ping.setFavicon(icon);
|
|
||||||
|
|
||||||
initialHandler.unsafe().sendPacket(new StatusResponse(gson.toJson(ping)));
|
|
||||||
_ticks++;
|
|
||||||
|
|
||||||
if (_ticks > MAX_TICKS)
|
|
||||||
{
|
|
||||||
PingPacket packet = initialHandler.getPingPacket();
|
|
||||||
if (packet != null)
|
|
||||||
{
|
|
||||||
initialHandler.unsafe().sendPacket(packet);
|
|
||||||
initialHandler.setPingPacket(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (initialHandler.getChannelWrapper().getHandle().isOpen())
|
|
||||||
initialHandler.getChannelWrapper().getHandle().close();
|
|
||||||
_task.cancel(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 0, 200, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDesc()
|
|
||||||
{
|
|
||||||
int insetSpaces = 8;
|
|
||||||
int maxSpaces = 6;
|
|
||||||
|
|
||||||
ChatColor mineplexColor = COLOR_ROTATION[_ticks % COLOR_ROTATION.length];
|
|
||||||
int spaceLeftCount;
|
|
||||||
int spaceNumber = _ticks % (maxSpaces*2);
|
|
||||||
if (spaceNumber > maxSpaces)
|
|
||||||
spaceLeftCount = 2*maxSpaces - spaceNumber;
|
|
||||||
else
|
|
||||||
spaceLeftCount = spaceNumber;
|
|
||||||
|
|
||||||
String spacesLeft = getRepeatedCharacters(' ', spaceLeftCount);
|
|
||||||
String spacesRight = getRepeatedCharacters(' ', maxSpaces - spaceLeftCount);
|
|
||||||
String insets = getRepeatedCharacters(' ', insetSpaces);
|
|
||||||
String desc = insets + spacesLeft + LEFT_SWORD + spacesRight + getMineplex(mineplexColor) + spacesRight + RIGHT_SWORD + spacesLeft;
|
|
||||||
|
|
||||||
List<String> lines = _manager.getMotdLines();
|
|
||||||
if (lines != null && lines.size() > 0)
|
|
||||||
{
|
|
||||||
int index = _ticks / (MAX_TICKS / (lines.size()-1));
|
|
||||||
String currentLine = index >= lines.size() ? lines.get(lines.size() - 1) : lines.get(index);
|
|
||||||
desc += "\n" + currentLine;
|
|
||||||
}
|
|
||||||
|
|
||||||
return desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Favicon getIcon()
|
|
||||||
{
|
|
||||||
Favicon icon = null;
|
|
||||||
|
|
||||||
if (ICON_FRAMES.size() > 0)
|
|
||||||
{
|
|
||||||
icon = ICON_FRAMES.get(_ticks % ICON_FRAMES.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMineplex(ChatColor color)
|
|
||||||
{
|
|
||||||
return " " + color + ChatColor.BOLD.toString() + "Mineplex" + ChatColor.RESET + ChatColor.WHITE + ChatColor.BOLD + " Games" + ChatColor.RESET + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRepeatedCharacters(char c, int count)
|
|
||||||
{
|
|
||||||
char[] spaces = new char[count];
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
spaces[i] = c;
|
|
||||||
}
|
|
||||||
return new String(spaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Comparator<File> FILE_NUMBER_COMPARATOR = new Comparator<File>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public int compare(File f1, File f2)
|
|
||||||
{
|
|
||||||
int compareValue = 0;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int i1 = Integer.parseInt(f1.getName().substring(0, f1.getName().indexOf('.')));
|
|
||||||
int i2 = Integer.parseInt(f2.getName().substring(0, f2.getName().indexOf('.')));
|
|
||||||
return i1 - i2;
|
|
||||||
}
|
|
||||||
catch (Exception e) {}
|
|
||||||
|
|
||||||
return compareValue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
// Load icon animations
|
|
||||||
ICON_FRAMES = new ArrayList<Favicon>();
|
|
||||||
|
|
||||||
File iconFolder = new File("server-icon");
|
|
||||||
if (iconFolder.exists() && iconFolder.isDirectory())
|
|
||||||
{
|
|
||||||
File[] files = iconFolder.listFiles();
|
|
||||||
Arrays.sort(files, FILE_NUMBER_COMPARATOR);
|
|
||||||
for (int i = 0; i < files.length; i++)
|
|
||||||
{
|
|
||||||
File file = files[i];
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedImage image = ImageIO.read(file);
|
|
||||||
Favicon favicon = Favicon.create(image);
|
|
||||||
ICON_FRAMES.add(favicon);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// Just ignore extra files
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,26 @@
|
|||||||
package mineplex.bungee.motd;
|
package mineplex.bungee.motd;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.connection.CustomMotd;
|
|
||||||
import net.md_5.bungee.connection.CustomMotdFactory;
|
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class MotdManager implements Listener, Runnable, CustomMotdFactory
|
public class MotdManager implements Listener, Runnable
|
||||||
{
|
{
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
private MotdRepository _repository;
|
|
||||||
|
private DataRepository<GlobalMotd> _repository;
|
||||||
|
|
||||||
private String firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
|
private Random _random = new Random();
|
||||||
|
private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
|
||||||
private List<String> _motdLines;
|
private List<String> _motdLines;
|
||||||
|
|
||||||
public MotdManager(Plugin plugin)
|
public MotdManager(Plugin plugin)
|
||||||
@ -26,8 +30,9 @@ public class MotdManager implements Listener, Runnable, CustomMotdFactory
|
|||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS);
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
_repository = new MotdRepository();
|
_repository = new RedisDataRepository<GlobalMotd>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
_repository.initialize();
|
Region.ALL, GlobalMotd.class, "globalMotd");
|
||||||
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -35,36 +40,56 @@ public class MotdManager implements Listener, Runnable, CustomMotdFactory
|
|||||||
{
|
{
|
||||||
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
||||||
|
|
||||||
String motd = firstLine;
|
String motd = _firstLine;
|
||||||
if (_motdLines != null && _motdLines.size() > 0)
|
if (_motdLines != null && _motdLines.size() > 0)
|
||||||
motd += "\n" + _motdLines.get(0);
|
{
|
||||||
|
motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size()));
|
||||||
|
}
|
||||||
|
|
||||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_motdLines = _repository.retrieveMotd();
|
// Add in default MOTD listing to database
|
||||||
|
/*
|
||||||
|
if (!_repository.elementExists("MainMotd"))
|
||||||
|
{
|
||||||
|
_repository.removeElement("MainMotd");
|
||||||
|
|
||||||
|
List<String> lines = new ArrayList<String>();
|
||||||
|
lines.add(" §a§lDouble Gems for 1.8 Players!");
|
||||||
|
lines.add(" §e§lChampions Update §a§lBalance Patch");
|
||||||
|
lines.add(" §6§lSpecial Egg Baskets!");
|
||||||
|
lines.add(" §e§lBunny Morph §a§lLimited Time!");
|
||||||
|
lines.add(" §d§lHero Sale §a§l33% Off");
|
||||||
|
lines.add(" §a§lDouble Gems for 1.8 Players!");
|
||||||
|
|
||||||
|
updateMainMotd(" §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r", lines);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (_repository.retrieveMotdAnimated())
|
GlobalMotd motd = _repository.getElement("MainMotd");
|
||||||
|
|
||||||
|
if (motd != null)
|
||||||
{
|
{
|
||||||
InitialHandler.setCustomMotdFactory(this);
|
_motdLines = motd.getMotd();
|
||||||
}
|
_firstLine = motd.getHeadline();
|
||||||
else
|
|
||||||
{
|
|
||||||
InitialHandler.setCustomMotdFactory(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the main {@link GlobalMotd} determining the MOTD for Bungee instances.
|
||||||
|
* @param motdLines - the lines to update the MOTD to.
|
||||||
|
*/
|
||||||
|
public void updateMainMotd(String headline, List<String> motdLines)
|
||||||
|
{
|
||||||
|
_repository.addElement(new GlobalMotd("MainMotd", headline, motdLines));
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getMotdLines()
|
public List<String> getMotdLines()
|
||||||
{
|
{
|
||||||
return _motdLines;
|
return _motdLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CustomMotd makeMotd()
|
|
||||||
{
|
|
||||||
return new Motd(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,171 +0,0 @@
|
|||||||
package mineplex.bungee.motd;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
public class MotdRepository
|
|
||||||
{
|
|
||||||
private Connection _connection = null;
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeMotd (id INT NOT NULL AUTO_INCREMENT, motd VARCHAR(256), PRIMARY KEY (id));";
|
|
||||||
private static String RETRIEVE_MOTD = "SELECT motd FROM BungeeMotd;";
|
|
||||||
private static String RETRIEVE_ANIMATED = "SELECT value FROM bungeeSettings WHERE id='animatedMotd'";
|
|
||||||
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Initialized MOTD.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> retrieveMotd()
|
|
||||||
{
|
|
||||||
// String motd = "§b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r §c§l§m§kZ§6§l§m§kZ§e§l§m§kZ§a§l§m§kZ§b§l§m§kZ§r §f§lPLAY NOW§r §b§l§m§kZ§a§l§m§kZ§e§l§m§kZ§6§l§m§kZ§c§l§m§kZ";
|
|
||||||
ArrayList<String> lines = new ArrayList<String>();
|
|
||||||
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "New Game" + ChatColor.RED + ChatColor.BOLD + " Christmas Chaos");
|
|
||||||
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "Winter Sale" + ChatColor.BLUE + ChatColor.BOLD + " 33% Off Everything");
|
|
||||||
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "New Game" + ChatColor.RED + ChatColor.BOLD + " Christmas Chaos");
|
|
||||||
// return lines;
|
|
||||||
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_MOTD);
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
lines.add(resultSet.getString(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean retrieveMotdAnimated()
|
|
||||||
{
|
|
||||||
boolean enabled = false;
|
|
||||||
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_ANIMATED);
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
enabled = resultSet.getBoolean(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 enabled;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,16 @@
|
|||||||
package mineplex.bungee.playerCount;
|
package mineplex.bungee.playerCount;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.ServerManager;
|
||||||
|
import mineplex.serverdata.servers.ServerRepository;
|
||||||
import net.md_5.bungee.api.ServerPing.Players;
|
import net.md_5.bungee.api.ServerPing.Players;
|
||||||
import net.md_5.bungee.api.config.ListenerInfo;
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
@ -11,31 +20,64 @@ import net.md_5.bungee.event.EventHandler;
|
|||||||
|
|
||||||
public class PlayerCount implements Listener, Runnable
|
public class PlayerCount implements Listener, Runnable
|
||||||
{
|
{
|
||||||
|
private DataRepository<BungeeServer> _repository;
|
||||||
|
private UUID _uuid;
|
||||||
|
private Region _region;
|
||||||
|
|
||||||
|
private ListenerInfo _listenerInfo;
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
private PlayerCountRepository _repository;
|
|
||||||
|
|
||||||
private int _totalPlayers = -1;
|
private int _totalPlayers = -1;
|
||||||
|
|
||||||
public PlayerCount(Plugin plugin)
|
public PlayerCount(Plugin plugin)
|
||||||
{
|
{
|
||||||
|
_uuid = UUID.randomUUID();
|
||||||
|
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
|
||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
|
_listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
|
||||||
|
|
||||||
_repository = new PlayerCountRepository(listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort(), listenerInfo.getMaxPlayers());
|
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
_repository.initialize();
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.updatePlayerCountInDatabase(_plugin.getProxy().getOnlineCount());
|
|
||||||
|
BungeeServer snapshot = generateSnapshot();
|
||||||
|
_repository.addElement(snapshot, 15); // Update with a 15 second expiry on session
|
||||||
|
|
||||||
PlayerTotalData playerTotalData = _repository.retrievePlayerCount();
|
_totalPlayers = fetchPlayerCount();
|
||||||
|
}
|
||||||
_totalPlayers = playerTotalData.CurrentPlayers;
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a newly instantiated {@link BungeeServer} snapshot of the current state of this server.
|
||||||
|
*/
|
||||||
|
private BungeeServer generateSnapshot()
|
||||||
|
{
|
||||||
|
String name = _uuid.toString(); // Use random UUID for unique id name.
|
||||||
|
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
|
@EventHandler
|
||||||
|
@ -1,257 +0,0 @@
|
|||||||
package mineplex.bungee.playerCount;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class PlayerCountRepository
|
|
||||||
{
|
|
||||||
private Connection _connection = null;
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeServers (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(256), updated LONG, players INT, maxPlayers INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
|
||||||
private static String INSERT_PLAYER_COUNT = "INSERT INTO BungeeServers(address, updated, players, maxPlayers, ram, maxRam) values(?, now(), ?, ?, ?, ?);";
|
|
||||||
private static String UPDATE_PLAYER_COUNT = "UPDATE BungeeServers SET updated = now(), players = ?, maxPlayers = ?, ram = ?, maxRam = ? WHERE id = ?;";
|
|
||||||
private static String RETRIEVE_ID = "SELECT id FROM BungeeServers WHERE address = ?;";
|
|
||||||
private static String RETRIEVE_PLAYER_COUNT = "SELECT SUM(players) AS playerCount, SUM(maxPlayers) AS maxPlayerCount FROM BungeeServers WHERE TIME_TO_SEC(TIMEDIFF(now(), BungeeServers.updated)) < 10;";
|
|
||||||
|
|
||||||
private int _id = -1;
|
|
||||||
private String _address;
|
|
||||||
private int _maxPlayers = 0;
|
|
||||||
|
|
||||||
public PlayerCountRepository(String address, int maxPlayers)
|
|
||||||
{
|
|
||||||
_address = address;
|
|
||||||
_maxPlayers = maxPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
PreparedStatement preparedStatementRetrieve = null;
|
|
||||||
PreparedStatement preparedStatementInsert = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
|
|
||||||
|
|
||||||
// Retrieve id
|
|
||||||
preparedStatementRetrieve = _connection.prepareStatement(RETRIEVE_ID);
|
|
||||||
preparedStatementRetrieve.setString(1, _address);
|
|
||||||
resultSet = preparedStatementRetrieve.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
_id = resultSet.getInt("id");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert if not there
|
|
||||||
if (_id == -1)
|
|
||||||
{
|
|
||||||
preparedStatementInsert = _connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
preparedStatementInsert.setString(1, _address);
|
|
||||||
preparedStatementInsert.setInt(2, 0);
|
|
||||||
preparedStatementInsert.setInt(3, _maxPlayers);
|
|
||||||
preparedStatementInsert.setInt(4, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
|
|
||||||
preparedStatementInsert.setInt(5, (int) (Runtime.getRuntime().maxMemory() / 1048576));
|
|
||||||
|
|
||||||
int affectedRows = preparedStatementInsert.executeUpdate();
|
|
||||||
|
|
||||||
if (affectedRows == 0)
|
|
||||||
{
|
|
||||||
throw new SQLException("Creating bungee server failed, no rows affected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
resultSet.close();
|
|
||||||
resultSet = preparedStatementInsert.getGeneratedKeys();
|
|
||||||
|
|
||||||
if (resultSet.next())
|
|
||||||
{
|
|
||||||
_id = resultSet.getInt(1);
|
|
||||||
System.out.println("id = " + _id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preparedStatementRetrieve != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatementRetrieve.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preparedStatementInsert != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatementInsert.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultSet != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Initialized PlayerCount.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updatePlayerCountInDatabase(int players)
|
|
||||||
{
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
preparedStatement.setInt(1, players);
|
|
||||||
preparedStatement.setInt(2, _maxPlayers);
|
|
||||||
preparedStatement.setInt(3, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
|
|
||||||
preparedStatement.setInt(4, (int) (Runtime.getRuntime().maxMemory() / 1048576));
|
|
||||||
preparedStatement.setInt(5, _id);
|
|
||||||
|
|
||||||
int affectedRows = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (affectedRows == 0)
|
|
||||||
{
|
|
||||||
throw new SQLException("Updating bungee server player count failed, no rows affected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatePlayerCountInDatabase(players);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerTotalData retrievePlayerCount()
|
|
||||||
{
|
|
||||||
PlayerTotalData playerData = new PlayerTotalData();
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
playerData.CurrentPlayers = resultSet.getInt(1);
|
|
||||||
playerData.MaxPlayers = resultSet.getInt(2);
|
|
||||||
return playerData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 playerData;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package mineplex.bungee.playerCount;
|
|
||||||
|
|
||||||
public class PlayerTotalData
|
|
||||||
{
|
|
||||||
public int CurrentPlayers;
|
|
||||||
public int MaxPlayers;
|
|
||||||
}
|
|
@ -1,19 +1,32 @@
|
|||||||
package mineplex.bungee.playerStats;
|
package mineplex.bungee.playerStats;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import mineplex.bungee.playerStats.data.IpInfo;
|
||||||
|
import mineplex.playerCache.PlayerCache;
|
||||||
|
import mineplex.playerCache.PlayerInfo;
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class PlayerStats implements Listener
|
public class PlayerStats implements Listener, Runnable
|
||||||
{
|
{
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
private PlayerStatsRepository _repository;
|
private PlayerStatsRepository _repository;
|
||||||
|
|
||||||
|
private PlayerCache _playerCache = new PlayerCache();
|
||||||
|
private HashSet<UUID> _retrievingPlayerInfo = new HashSet<UUID>();
|
||||||
|
|
||||||
public PlayerStats(Plugin plugin)
|
public PlayerStats(Plugin plugin)
|
||||||
{
|
{
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
|
||||||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES);
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
_repository = new PlayerStatsRepository();
|
_repository = new PlayerStatsRepository();
|
||||||
@ -27,8 +40,104 @@ public class PlayerStats implements Listener
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.addPlayer(event.getPlayer().getName());
|
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.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;
|
||||||
|
|
||||||
|
_playerCache.addPlayer(playerInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
playerInfo.setSessionId(_repository.updatePlayerStats(playerInfo.getId(), ipInfo.id));
|
||||||
|
}
|
||||||
|
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.getPlayer(uuid);
|
||||||
|
|
||||||
|
int timeout = 5;
|
||||||
|
|
||||||
|
while (playerInfo == null && _retrievingPlayerInfo.contains(uuid) && timeout <= 5)
|
||||||
|
{
|
||||||
|
playerInfo = _playerCache.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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_repository.updatePlayerSession(playerInfo.getSessionId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_playerCache.clean();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,89 +3,111 @@ package mineplex.bungee.playerStats;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mineplex.bungee.playerStats.data.IpInfo;
|
||||||
|
import mineplex.playerCache.PlayerInfo;
|
||||||
|
|
||||||
public class PlayerStatsRepository
|
public class PlayerStatsRepository
|
||||||
{
|
{
|
||||||
private Connection _connection = null;
|
private Connection _connection = null;
|
||||||
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true";
|
||||||
private String _userName = "root";
|
private String _userName = "root";
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS DailyUnique (id INT NOT NULL AUTO_INCREMENT, day VARCHAR(100), playerName VARCHAR(20), PRIMARY KEY (id), UNIQUE KEY unique_player_per_day (day, playerName));";
|
private static String INSERT_PLAYERINFO = "INSERT INTO playerInfo (uuid, name, version) VALUES (?, ?, ?);";
|
||||||
private static String INSERT_PLAYER = "INSERT INTO DailyUnique (day, playerName) values(curdate(), ?) ON DUPLICATE KEY UPDATE playerName=playerName;";
|
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 CREATE_VER_TABLE = "CREATE TABLE IF NOT EXISTS PlayerVersion (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), version VARCHAR(40), PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));";
|
private static String UPDATE_LOGINSESSION = "UPDATE playerLoginSessions SET timeInGame = TIME_TO_SEC(TIMEDIFF(now(), loginTime)) / 60 WHERE id = ?;";
|
||||||
private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?) ON DUPLICATE KEY UPDATE version=version;";
|
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_connection == null || _connection.isClosed())
|
if (_connection == null || _connection.isClosed())
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
|
|
||||||
preparedStatement.close();
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_VER_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Initialized PlayerStats.");
|
System.out.println("Initialized PlayerStats.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addPlayer(String playerName)
|
public PlayerInfo getPlayer(UUID uuid, String name, int version)
|
||||||
{
|
{
|
||||||
|
PlayerInfo playerInfo = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_connection == null || _connection.isClosed())
|
if (_connection == null || _connection.isClosed())
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(INSERT_PLAYER, Statement.RETURN_GENERATED_KEYS);
|
preparedStatement = _connection.prepareStatement(SELECT_PLAYERINFO);
|
||||||
|
|
||||||
preparedStatement.setString(1, playerName);
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
int affectedRows = preparedStatement.executeUpdate();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
if (affectedRows == 0)
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
throw new SQLException("Adding unique player record failed, no rows affected.");
|
playerInfo = new PlayerInfo(resultSet.getInt(1), uuid, resultSet.getString(2), resultSet.getInt(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -100,46 +122,183 @@ public class PlayerStatsRepository
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resultSet != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return playerInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addPlayerVersion(String playerName, String version)
|
public IpInfo getIp(String ipAddress)
|
||||||
{
|
{
|
||||||
|
IpInfo ipInfo = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
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
|
try
|
||||||
{
|
{
|
||||||
if (_connection == null || _connection.isClosed())
|
if (_connection == null || _connection.isClosed())
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS);
|
statement = _connection.createStatement();
|
||||||
|
|
||||||
|
String queryString = UPDATE_PLAYERSTATS;
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", ipId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
queryString = queryString.replaceFirst("\\?", playerId + "");
|
||||||
|
|
||||||
preparedStatement.setString(1, playerName);
|
statement.executeUpdate(queryString, Statement.RETURN_GENERATED_KEYS);
|
||||||
preparedStatement.setString(2, version);
|
|
||||||
|
|
||||||
int affectedRows = preparedStatement.executeUpdate();
|
statement.getMoreResults();
|
||||||
|
statement.getMoreResults();
|
||||||
|
resultSet = statement.getGeneratedKeys();
|
||||||
|
|
||||||
if (affectedRows == 0)
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
throw new SQLException("Adding player version record failed, no rows affected.");
|
return resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
try
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(10);
|
if (statement != null)
|
||||||
}
|
statement.close();
|
||||||
catch (InterruptedException e)
|
}
|
||||||
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return addPlayer(playerName);
|
try
|
||||||
|
{
|
||||||
|
if (resultSet != null)
|
||||||
|
resultSet.close();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updatePlayerSession(int loginSessionId)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(UPDATE_LOGINSESSION);
|
||||||
|
preparedStatement.setInt(1, loginSessionId);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package mineplex.bungee.playerStats.data;
|
||||||
|
|
||||||
|
public class IpInfo
|
||||||
|
{
|
||||||
|
public int id;
|
||||||
|
public String ipAddress;
|
||||||
|
}
|
@ -2,6 +2,11 @@ package mineplex.bungee.playerTracker;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
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.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
@ -10,8 +15,13 @@ import net.md_5.bungee.event.EventHandler;
|
|||||||
|
|
||||||
public class PlayerTracker implements Listener
|
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 Plugin _plugin;
|
||||||
private PlayerTrackerRepository _repository = null;
|
|
||||||
|
|
||||||
public PlayerTracker(Plugin plugin)
|
public PlayerTracker(Plugin plugin)
|
||||||
{
|
{
|
||||||
@ -19,8 +29,9 @@ public class PlayerTracker implements Listener
|
|||||||
|
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
_repository = new PlayerTrackerRepository();
|
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||||
_repository.initialize(!new File("eu.dat").exists());
|
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
|
region, PlayerStatus.class, "playerStatus");
|
||||||
|
|
||||||
System.out.println("Initialized PlayerTracker.");
|
System.out.println("Initialized PlayerTracker.");
|
||||||
}
|
}
|
||||||
@ -32,7 +43,8 @@ public class PlayerTracker implements Listener
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.updatePlayerServer(event.getPlayer().getName(), event.getServer().getInfo().getName());
|
PlayerStatus snapshot = new PlayerStatus(event.getPlayer().getName(), event.getServer().getInfo().getName());
|
||||||
|
_repository.addElement(snapshot, DEFAULT_STATUS_TIMEOUT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -44,7 +56,7 @@ public class PlayerTracker implements Listener
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.deleteServerTransfers(event.getPlayer().getName());
|
_repository.removeElement(event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,203 +0,0 @@
|
|||||||
package mineplex.bungee.playerTracker;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class PlayerTrackerRepository
|
|
||||||
{
|
|
||||||
private static Object _connectionLock = new Object();
|
|
||||||
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private boolean _us = true;
|
|
||||||
|
|
||||||
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
|
|
||||||
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
|
|
||||||
private static String INSERT_PLAYERMAP = "INSERT INTO playerMap (playerName, serverName, us) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE serverName = VALUES(serverName), us = VALUES(us);";
|
|
||||||
private static String DELETE_PLAYERMAP = "DELETE FROM playerMap WHERE playerName = ? AND us = ?;";
|
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
public void initialize(boolean us)
|
|
||||||
{
|
|
||||||
_us = us;
|
|
||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String retrievePlayerServer(String playerName)
|
|
||||||
{
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
String server = "N/A";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
if (_connection.isClosed())
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setBoolean(2, _us);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
server = resultSet.getString(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteServerTransfers(String playerName)
|
|
||||||
{
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
if (_connection.isClosed())
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(DELETE_PLAYERMAP);
|
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setBoolean(2, _us);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updatePlayerServer(String playerName, String serverName)
|
|
||||||
{
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
if (_connection.isClosed())
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(INSERT_PLAYERMAP);
|
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setString(2, serverName);
|
|
||||||
preparedStatement.setBoolean(3, _us);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,20 +10,15 @@ import net.md_5.bungee.api.plugin.Plugin;
|
|||||||
|
|
||||||
public class InternetStatus implements Runnable
|
public class InternetStatus implements Runnable
|
||||||
{
|
{
|
||||||
|
// Current internet connectivity status
|
||||||
|
private static boolean _connected = true;
|
||||||
|
public static boolean isConnected() { return _connected; }
|
||||||
|
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
private StatusRepository _repository;
|
|
||||||
|
|
||||||
public InternetStatus(Plugin plugin)
|
public InternetStatus(Plugin plugin)
|
||||||
{
|
{
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
|
||||||
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
|
|
||||||
boolean us = !new File("eu.dat").exists();
|
|
||||||
String address = listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort();
|
|
||||||
|
|
||||||
_repository = new StatusRepository(address, us);
|
|
||||||
_repository.initialize();
|
|
||||||
|
|
||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
|
||||||
|
|
||||||
System.out.println("Initialized InternetStatus.");
|
System.out.println("Initialized InternetStatus.");
|
||||||
@ -32,48 +27,28 @@ public class InternetStatus implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.updateOnlineStatus(isOnline());
|
_connected = isOnline(); // Update _connected flag.
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOnline()
|
private boolean isOnline()
|
||||||
{
|
{
|
||||||
if (testUrl("www.google.com"))
|
return testUrl("www.google.com")
|
||||||
return true;
|
|| testUrl("www.espn.com")
|
||||||
else if (testUrl("www.espn.com"))
|
|| testUrl("www.bing.com");
|
||||||
return true;
|
|
||||||
else if (testUrl("www.bing.com"))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean testUrl(String url)
|
private boolean testUrl(String url)
|
||||||
{
|
{
|
||||||
Socket socket = null;
|
|
||||||
boolean reachable = false;
|
boolean reachable = false;
|
||||||
|
|
||||||
try
|
try (Socket socket = new Socket(url, 80))
|
||||||
{
|
{
|
||||||
socket = new Socket(url, 80);
|
|
||||||
reachable = true;
|
reachable = true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// Meh i don't care
|
// Meh i don't care
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (socket != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return reachable;
|
return reachable;
|
||||||
}
|
}
|
||||||
|
@ -1,120 +0,0 @@
|
|||||||
package mineplex.bungee.status;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class StatusRepository
|
|
||||||
{
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private String _address;
|
|
||||||
private boolean _us;
|
|
||||||
|
|
||||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));";
|
|
||||||
private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated);";
|
|
||||||
private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated), lastOnline = VALUES(lastOnline);";
|
|
||||||
|
|
||||||
public StatusRepository(String address, boolean us)
|
|
||||||
{
|
|
||||||
_address = address;
|
|
||||||
_us = us;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = connection.prepareStatement(CREATE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateOnlineStatus(boolean online)
|
|
||||||
{
|
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(online ? INSERT_ONLINE_SERVER : INSERT_SERVER);
|
|
||||||
|
|
||||||
preparedStatement.setString(1, _address);
|
|
||||||
preparedStatement.setBoolean(2, online);
|
|
||||||
preparedStatement.setBoolean(3, _us);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package net.md_5.bungee.connection;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
||||||
import net.md_5.bungee.protocol.packet.PingPacket;
|
|
||||||
|
|
||||||
public interface CustomMotd
|
|
||||||
{
|
|
||||||
public void handlePing(ProxyPingEvent event, InitialHandler initialHandler);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package net.md_5.bungee.connection;
|
|
||||||
|
|
||||||
public interface CustomMotdFactory
|
|
||||||
{
|
|
||||||
public CustomMotd makeMotd();
|
|
||||||
}
|
|
@ -1,487 +0,0 @@
|
|||||||
//
|
|
||||||
// Source code recreated from a .class file by IntelliJ IDEA
|
|
||||||
// (powered by Fernflower decompiler)
|
|
||||||
//
|
|
||||||
|
|
||||||
package net.md_5.bungee.connection;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import java.beans.ConstructorProperties;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import net.md_5.bungee.BungeeCipher;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.BungeeServerInfo;
|
|
||||||
import net.md_5.bungee.EncryptionUtil;
|
|
||||||
import net.md_5.bungee.UserConnection;
|
|
||||||
import net.md_5.bungee.Util;
|
|
||||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
|
||||||
import net.md_5.bungee.api.Callback;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.Favicon;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
import net.md_5.bungee.api.ServerPing.PlayerInfo;
|
|
||||||
import net.md_5.bungee.api.ServerPing.Players;
|
|
||||||
import net.md_5.bungee.api.ServerPing.Protocol;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.config.ListenerInfo;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
|
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.PreLoginEvent;
|
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
|
||||||
import net.md_5.bungee.http.HttpClient;
|
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
|
||||||
import net.md_5.bungee.netty.HandlerBoss;
|
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
|
||||||
import net.md_5.bungee.netty.cipher.CipherDecoder;
|
|
||||||
import net.md_5.bungee.netty.cipher.CipherEncoder;
|
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
|
||||||
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
|
||||||
import net.md_5.bungee.protocol.packet.Handshake;
|
|
||||||
import net.md_5.bungee.protocol.packet.Kick;
|
|
||||||
import net.md_5.bungee.protocol.packet.LegacyHandshake;
|
|
||||||
import net.md_5.bungee.protocol.packet.LegacyPing;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.LoginSuccess;
|
|
||||||
import net.md_5.bungee.protocol.packet.PingPacket;
|
|
||||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
|
||||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
|
||||||
|
|
||||||
public class InitialHandler extends PacketHandler implements PendingConnection {
|
|
||||||
|
|
||||||
private static CustomMotdFactory _customMotdFactory;
|
|
||||||
|
|
||||||
private PingPacket _pingPacket;
|
|
||||||
private final ProxyServer bungee;
|
|
||||||
private ChannelWrapper ch;
|
|
||||||
private final ListenerInfo listener;
|
|
||||||
private Handshake handshake;
|
|
||||||
private LoginRequest loginRequest;
|
|
||||||
private EncryptionRequest request;
|
|
||||||
private final List<PluginMessage> registerMessages = new ArrayList();
|
|
||||||
private InitialHandler.State thisState;
|
|
||||||
private final Unsafe unsafe;
|
|
||||||
private boolean onlineMode;
|
|
||||||
private InetSocketAddress virtualHost;
|
|
||||||
private UUID uniqueId;
|
|
||||||
private UUID offlineId;
|
|
||||||
private LoginResult loginProfile;
|
|
||||||
private boolean legacy;
|
|
||||||
|
|
||||||
public void connected(ChannelWrapper channel) throws Exception {
|
|
||||||
this.ch = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exception(Throwable t) throws Exception {
|
|
||||||
this.disconnect((String)(ChatColor.RED + Util.exception(t)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(PluginMessage pluginMessage) throws Exception {
|
|
||||||
if(pluginMessage.getTag().equals("REGISTER")) {
|
|
||||||
Preconditions.checkState(this.registerMessages.size() < 128, "Too many channels registered");
|
|
||||||
this.registerMessages.add(pluginMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(LegacyHandshake legacyHandshake) throws Exception {
|
|
||||||
this.legacy = true;
|
|
||||||
this.ch.getHandle().writeAndFlush(this.bungee.getTranslation("outdated_client", new Object[0]));
|
|
||||||
this.ch.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(LegacyPing ping) throws Exception {
|
|
||||||
this.legacy = true;
|
|
||||||
final boolean v1_5 = ping.isV1_5();
|
|
||||||
ServerPing legacy = new ServerPing(new Protocol(this.bungee.getName() + " " + this.bungee.getGameVersion(), this.bungee.getProtocolVersion()), new Players(this.listener.getMaxPlayers(), this.bungee.getOnlineCount(), (PlayerInfo[])null), this.listener.getMotd(), (Favicon)null);
|
|
||||||
Callback callback = new Callback<ProxyPingEvent>() {
|
|
||||||
public void done(ProxyPingEvent result, Throwable error) {
|
|
||||||
if(!InitialHandler.this.ch.isClosed()) {
|
|
||||||
ServerPing legacy = result.getResponse();
|
|
||||||
String kickMessage;
|
|
||||||
if(v1_5) {
|
|
||||||
kickMessage = ChatColor.DARK_BLUE + "\u0000" + 127 + '\u0000' + legacy.getVersion().getName() + '\u0000' + InitialHandler.getFirstLine(legacy.getDescription()) + '\u0000' + legacy.getPlayers().getOnline() + '\u0000' + legacy.getPlayers().getMax();
|
|
||||||
} else {
|
|
||||||
kickMessage = ChatColor.stripColor(InitialHandler.getFirstLine(legacy.getDescription())) + '§' + legacy.getPlayers().getOnline() + '§' + legacy.getPlayers().getMax();
|
|
||||||
}
|
|
||||||
|
|
||||||
InitialHandler.this.ch.getHandle().writeAndFlush(kickMessage);
|
|
||||||
InitialHandler.this.ch.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.bungee.getPluginManager().callEvent(new ProxyPingEvent(this, legacy, callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getFirstLine(String str) {
|
|
||||||
int pos = str.indexOf(10);
|
|
||||||
return pos == -1?str:str.substring(0, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(StatusRequest statusRequest) throws Exception {
|
|
||||||
Preconditions.checkState(this.thisState == InitialHandler.State.STATUS, "Not expecting STATUS");
|
|
||||||
ServerInfo forced = AbstractReconnectHandler.getForcedHost(this);
|
|
||||||
String motd = forced != null?forced.getMotd():this.listener.getMotd();
|
|
||||||
Callback pingBack = new Callback<ServerPing>() {
|
|
||||||
public void done(ServerPing result, Throwable error) {
|
|
||||||
if(error != null) {
|
|
||||||
result = new ServerPing();
|
|
||||||
result.setDescription(InitialHandler.this.bungee.getTranslation("ping_cannot_connect", new Object[0]));
|
|
||||||
InitialHandler.this.bungee.getLogger().log(Level.WARNING, "Error pinging remote server", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
Callback callback = new Callback<ProxyPingEvent>() {
|
|
||||||
public void done(ProxyPingEvent pingResult, Throwable error) {
|
|
||||||
// MINEPLEX
|
|
||||||
if (_customMotdFactory != null)
|
|
||||||
{
|
|
||||||
_customMotdFactory.makeMotd().handlePing(pingResult, InitialHandler.this);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BungeeCord.getInstance().getConnectionThrottle().unthrottle(InitialHandler.this.getAddress().getAddress());
|
|
||||||
Gson gson = InitialHandler.this.handshake.getProtocolVersion() == 4?BungeeCord.getInstance().gsonLegacy:BungeeCord.getInstance().gson;
|
|
||||||
InitialHandler.this.unsafe.sendPacket(new StatusResponse(gson.toJson(pingResult.getResponse())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
InitialHandler.this.bungee.getPluginManager().callEvent(new ProxyPingEvent(InitialHandler.this, result, callback));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if(forced != null && this.listener.isPingPassthrough()) {
|
|
||||||
((BungeeServerInfo)forced).ping(pingBack, this.handshake.getProtocolVersion());
|
|
||||||
} else {
|
|
||||||
int protocol = net.md_5.bungee.protocol.Protocol.supportedVersions.contains(Integer.valueOf(this.handshake.getProtocolVersion()))?this.handshake.getProtocolVersion():this.bungee.getProtocolVersion();
|
|
||||||
pingBack.done(new ServerPing(new Protocol(this.bungee.getName() + " " + this.bungee.getGameVersion(), protocol), new Players(this.listener.getMaxPlayers(), this.bungee.getOnlineCount(), (PlayerInfo[])null), motd, BungeeCord.getInstance().config.getFaviconObject()), (Throwable)null);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.thisState = InitialHandler.State.PING;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(final PingPacket ping) throws Exception {
|
|
||||||
|
|
||||||
_pingPacket = ping;
|
|
||||||
// if (thisState == State.PING) return; // MINEPLEX
|
|
||||||
// Preconditions.checkState(this.thisState == InitialHandler.State.PING, "Not expecting PING");
|
|
||||||
// getChannelWrapper().getHandle().eventLoop().schedule(new Runnable()
|
|
||||||
// {
|
|
||||||
// @Override
|
|
||||||
// public void run()
|
|
||||||
// {
|
|
||||||
// unsafe.sendPacket(ping);
|
|
||||||
// }
|
|
||||||
// }, 6, TimeUnit.SECONDS);
|
|
||||||
//
|
|
||||||
// this.unsafe.sendPacket(ping);
|
|
||||||
// this.disconnect((String)"");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(Handshake handshake) throws Exception {
|
|
||||||
Preconditions.checkState(this.thisState == InitialHandler.State.HANDSHAKE, "Not expecting HANDSHAKE");
|
|
||||||
this.handshake = handshake;
|
|
||||||
this.ch.setVersion(handshake.getProtocolVersion());
|
|
||||||
if(handshake.getHost().endsWith(".")) {
|
|
||||||
handshake.setHost(handshake.getHost().substring(0, handshake.getHost().length() - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.virtualHost = InetSocketAddress.createUnresolved(handshake.getHost(), handshake.getPort());
|
|
||||||
this.bungee.getLogger().log(Level.INFO, "{0} has connected", this);
|
|
||||||
this.bungee.getPluginManager().callEvent(new PlayerHandshakeEvent(this, handshake));
|
|
||||||
switch(handshake.getRequestedProtocol()) {
|
|
||||||
case 1:
|
|
||||||
this.thisState = InitialHandler.State.STATUS;
|
|
||||||
this.ch.setProtocol(net.md_5.bungee.protocol.Protocol.STATUS);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
this.thisState = InitialHandler.State.USERNAME;
|
|
||||||
this.ch.setProtocol(net.md_5.bungee.protocol.Protocol.LOGIN);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Cannot request protocol " + handshake.getRequestedProtocol());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(LoginRequest loginRequest) throws Exception {
|
|
||||||
Preconditions.checkState(this.thisState == InitialHandler.State.USERNAME, "Not expecting USERNAME");
|
|
||||||
this.loginRequest = loginRequest;
|
|
||||||
if(!net.md_5.bungee.protocol.Protocol.supportedVersions.contains(Integer.valueOf(this.handshake.getProtocolVersion()))) {
|
|
||||||
this.disconnect((String)this.bungee.getTranslation("outdated_server", new Object[0]));
|
|
||||||
} else if(this.getName().contains(".")) {
|
|
||||||
this.disconnect((String)this.bungee.getTranslation("name_invalid", new Object[0]));
|
|
||||||
} else if(this.getName().length() > 16) {
|
|
||||||
this.disconnect((String)this.bungee.getTranslation("name_too_long", new Object[0]));
|
|
||||||
} else {
|
|
||||||
int limit = BungeeCord.getInstance().config.getPlayerLimit();
|
|
||||||
if(limit > 0 && this.bungee.getOnlineCount() > limit) {
|
|
||||||
this.disconnect((String)this.bungee.getTranslation("proxy_full", new Object[0]));
|
|
||||||
} else if(!this.isOnlineMode() && this.bungee.getPlayer(this.getName()) != null) {
|
|
||||||
this.disconnect((String)this.bungee.getTranslation("already_connected", new Object[0]));
|
|
||||||
} else {
|
|
||||||
Callback callback = new Callback<PreLoginEvent>() {
|
|
||||||
public void done(PreLoginEvent result, Throwable error) {
|
|
||||||
if(result.isCancelled()) {
|
|
||||||
InitialHandler.this.disconnect((String)result.getCancelReason());
|
|
||||||
} else if(!InitialHandler.this.ch.isClosed()) {
|
|
||||||
if(InitialHandler.this.onlineMode) {
|
|
||||||
InitialHandler.this.unsafe().sendPacket(InitialHandler.this.request = EncryptionUtil.encryptRequest());
|
|
||||||
} else {
|
|
||||||
InitialHandler.this.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
InitialHandler.this.thisState = InitialHandler.State.ENCRYPT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.bungee.getPluginManager().callEvent(new PreLoginEvent(this, callback));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(EncryptionResponse encryptResponse) throws Exception {
|
|
||||||
Preconditions.checkState(this.thisState == InitialHandler.State.ENCRYPT, "Not expecting ENCRYPT");
|
|
||||||
SecretKey sharedKey = EncryptionUtil.getSecret(encryptResponse, this.request);
|
|
||||||
BungeeCipher decrypt = EncryptionUtil.getCipher(false, sharedKey);
|
|
||||||
this.ch.addBefore("frame-decoder", "decrypt", new CipherDecoder(decrypt));
|
|
||||||
BungeeCipher encrypt = EncryptionUtil.getCipher(true, sharedKey);
|
|
||||||
this.ch.addBefore("frame-prepender", "encrypt", new CipherEncoder(encrypt));
|
|
||||||
String encName = URLEncoder.encode(this.getName(), "UTF-8");
|
|
||||||
MessageDigest sha = MessageDigest.getInstance("SHA-1");
|
|
||||||
byte[][] encodedHash = new byte[][]{this.request.getServerId().getBytes("ISO_8859_1"), sharedKey.getEncoded(), EncryptionUtil.keys.getPublic().getEncoded()};
|
|
||||||
int authURL = encodedHash.length;
|
|
||||||
|
|
||||||
for(int handler = 0; handler < authURL; ++handler) {
|
|
||||||
byte[] bit = encodedHash[handler];
|
|
||||||
sha.update(bit);
|
|
||||||
}
|
|
||||||
|
|
||||||
String var11 = URLEncoder.encode((new BigInteger(sha.digest())).toString(16), "UTF-8");
|
|
||||||
String var12 = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + var11;
|
|
||||||
Callback var13 = new Callback<String>() {
|
|
||||||
public void done(String result, Throwable error) {
|
|
||||||
if(error == null) {
|
|
||||||
LoginResult obj = (LoginResult)BungeeCord.getInstance().gson.fromJson(result, LoginResult.class);
|
|
||||||
if(obj != null) {
|
|
||||||
InitialHandler.this.loginProfile = obj;
|
|
||||||
InitialHandler.this.uniqueId = Util.getUUID(obj.getId());
|
|
||||||
InitialHandler.this.finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
InitialHandler.this.disconnect((String)"Not authenticated with Minecraft.net");
|
|
||||||
} else {
|
|
||||||
InitialHandler.this.disconnect((String)InitialHandler.this.bungee.getTranslation("mojang_fail", new Object[0]));
|
|
||||||
InitialHandler.this.bungee.getLogger().log(Level.SEVERE, "Error authenticating " + InitialHandler.this.getName() + " with minecraft.net", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
HttpClient.get(var12, this.ch.getHandle().eventLoop(), var13);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void finish() {
|
|
||||||
ProxiedPlayer old = this.bungee.getPlayer(this.getName());
|
|
||||||
if(old != null) {
|
|
||||||
old.disconnect(this.bungee.getTranslation("already_connected", new Object[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.offlineId = UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.getName()).getBytes(Charsets.UTF_8));
|
|
||||||
if(this.uniqueId == null) {
|
|
||||||
this.uniqueId = this.offlineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
Callback complete = new Callback<LoginEvent>() {
|
|
||||||
public void done(LoginEvent result, Throwable error) {
|
|
||||||
if(result.isCancelled()) {
|
|
||||||
InitialHandler.this.disconnect((String)result.getCancelReason());
|
|
||||||
} else if(!InitialHandler.this.ch.isClosed()) {
|
|
||||||
InitialHandler.this.ch.getHandle().eventLoop().execute(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if(InitialHandler.this.ch.getHandle().isActive()) {
|
|
||||||
if(InitialHandler.this.getVersion() >= 5) {
|
|
||||||
InitialHandler.this.unsafe.sendPacket(new LoginSuccess(InitialHandler.this.getUniqueId().toString(), InitialHandler.this.getName()));
|
|
||||||
} else {
|
|
||||||
InitialHandler.this.unsafe.sendPacket(new LoginSuccess(InitialHandler.this.getUUID(), InitialHandler.this.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
InitialHandler.this.ch.setProtocol(net.md_5.bungee.protocol.Protocol.GAME);
|
|
||||||
UserConnection userCon = new UserConnection(InitialHandler.this.bungee, InitialHandler.this.ch, InitialHandler.this.getName(), InitialHandler.this);
|
|
||||||
userCon.init();
|
|
||||||
InitialHandler.this.bungee.getPluginManager().callEvent(new PostLoginEvent(userCon));
|
|
||||||
((HandlerBoss)InitialHandler.this.ch.getHandle().pipeline().get(HandlerBoss.class)).setHandler(new UpstreamBridge(InitialHandler.this.bungee, userCon));
|
|
||||||
ServerInfo server;
|
|
||||||
if(InitialHandler.this.bungee.getReconnectHandler() != null) {
|
|
||||||
server = InitialHandler.this.bungee.getReconnectHandler().getServer(userCon);
|
|
||||||
} else {
|
|
||||||
server = AbstractReconnectHandler.getForcedHost(InitialHandler.this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(server == null) {
|
|
||||||
server = InitialHandler.this.bungee.getServerInfo(InitialHandler.this.listener.getDefaultServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
userCon.connect(server, (Callback)null, true);
|
|
||||||
InitialHandler.this.thisState = InitialHandler.State.FINISHED;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.bungee.getPluginManager().callEvent(new LoginEvent(this, complete));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect(String reason) {
|
|
||||||
this.disconnect((BaseComponent[])TextComponent.fromLegacyText(reason));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect(final BaseComponent... reason) {
|
|
||||||
if(!this.ch.isClosed()) {
|
|
||||||
this.ch.getHandle().eventLoop().schedule(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
InitialHandler.this.unsafe().sendPacket(new Kick(ComponentSerializer.toString(reason)));
|
|
||||||
InitialHandler.this.ch.close();
|
|
||||||
}
|
|
||||||
}, 500L, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect(BaseComponent reason) {
|
|
||||||
this.disconnect((BaseComponent[])(new BaseComponent[]{reason}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.loginRequest == null?null:this.loginRequest.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersion() {
|
|
||||||
return this.handshake == null?-1:this.handshake.getProtocolVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetSocketAddress getAddress() {
|
|
||||||
return (InetSocketAddress)this.ch.getHandle().remoteAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Unsafe unsafe() {
|
|
||||||
return this.unsafe;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOnlineMode(boolean onlineMode) {
|
|
||||||
Preconditions.checkState(this.thisState == InitialHandler.State.USERNAME, "Can only set online mode status whilst state is username");
|
|
||||||
this.onlineMode = onlineMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUUID() {
|
|
||||||
return this.uniqueId.toString().replaceAll("-", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "[" + (this.getName() != null?this.getName():this.getAddress()) + "] <-> InitialHandler";
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConstructorProperties({"bungee", "listener"})
|
|
||||||
public InitialHandler(ProxyServer bungee, ListenerInfo listener) {
|
|
||||||
this.thisState = InitialHandler.State.HANDSHAKE;
|
|
||||||
this.unsafe = new Unsafe() {
|
|
||||||
public void sendPacket(DefinedPacket packet) {
|
|
||||||
InitialHandler.this.ch.write(packet);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.onlineMode = BungeeCord.getInstance().config.isOnlineMode();
|
|
||||||
this.bungee = bungee;
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ListenerInfo getListener() {
|
|
||||||
return this.listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Handshake getHandshake() {
|
|
||||||
return this.handshake;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginRequest getLoginRequest() {
|
|
||||||
return this.loginRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PluginMessage> getRegisterMessages() {
|
|
||||||
return this.registerMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOnlineMode() {
|
|
||||||
return this.onlineMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetSocketAddress getVirtualHost() {
|
|
||||||
return this.virtualHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getUniqueId() {
|
|
||||||
return this.uniqueId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getOfflineId() {
|
|
||||||
return this.offlineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginResult getLoginProfile() {
|
|
||||||
return this.loginProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLegacy() {
|
|
||||||
return this.legacy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelWrapper getChannelWrapper()
|
|
||||||
{
|
|
||||||
return ch; //MINEPLEX
|
|
||||||
}
|
|
||||||
|
|
||||||
public PingPacket getPingPacket()
|
|
||||||
{
|
|
||||||
return _pingPacket; // MINEPLEX
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPingPacket(PingPacket packet)
|
|
||||||
{
|
|
||||||
_pingPacket = packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static enum State {
|
|
||||||
HANDSHAKE,
|
|
||||||
STATUS,
|
|
||||||
PING,
|
|
||||||
USERNAME,
|
|
||||||
ENCRYPT,
|
|
||||||
FINISHED;
|
|
||||||
|
|
||||||
private State() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setCustomMotdFactory(CustomMotdFactory factory)
|
|
||||||
{
|
|
||||||
_customMotdFactory = factory;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
//
|
|
||||||
// Source code recreated from a .class file by IntelliJ IDEA
|
|
||||||
// (powered by Fernflower decompiler)
|
|
||||||
//
|
|
||||||
|
|
||||||
package net.md_5.bungee.connection;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
import net.md_5.bungee.api.Callback;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.ServerPing;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
|
||||||
import net.md_5.bungee.protocol.MinecraftDecoder;
|
|
||||||
import net.md_5.bungee.protocol.MinecraftEncoder;
|
|
||||||
import net.md_5.bungee.protocol.Protocol;
|
|
||||||
import net.md_5.bungee.protocol.packet.Handshake;
|
|
||||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
|
||||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
|
||||||
|
|
||||||
public class PingHandler extends PacketHandler {
|
|
||||||
private final ServerInfo target;
|
|
||||||
private final Callback<ServerPing> callback;
|
|
||||||
private final int protocol;
|
|
||||||
private ChannelWrapper channel;
|
|
||||||
|
|
||||||
public void connected(ChannelWrapper channel) throws Exception {
|
|
||||||
this.channel = channel;
|
|
||||||
MinecraftEncoder encoder = new MinecraftEncoder(Protocol.HANDSHAKE, false, this.protocol);
|
|
||||||
channel.getHandle().pipeline().addAfter("frame-decoder", "packet-decoder", new MinecraftDecoder(Protocol.STATUS, false, ProxyServer.getInstance().getProtocolVersion()));
|
|
||||||
channel.getHandle().pipeline().addAfter("frame-prepender", "packet-encoder", encoder);
|
|
||||||
channel.write(new Handshake(this.protocol, this.target.getAddress().getHostString(), this.target.getAddress().getPort(), 1));
|
|
||||||
encoder.setProtocol(Protocol.STATUS);
|
|
||||||
channel.write(new StatusRequest());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exception(Throwable t) throws Exception {
|
|
||||||
this.callback.done(null, t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(StatusResponse statusResponse) throws Exception {
|
|
||||||
Gson gson = this.protocol == 4?BungeeCord.getInstance().gsonLegacy:BungeeCord.getInstance().gson;
|
|
||||||
this.callback.done(gson.fromJson(statusResponse.getResponse(), ServerPing.class), (Throwable)null);
|
|
||||||
System.out.println("handle");
|
|
||||||
// this.channel.close(); //MINEPLEX
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "[Ping Handler] -> " + this.target.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PingHandler(ServerInfo target, Callback<ServerPing> callback, int protocol) {
|
|
||||||
this.target = target;
|
|
||||||
this.callback = callback;
|
|
||||||
this.protocol = protocol;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
|
||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/javax.mail.jar"/>
|
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -1,142 +0,0 @@
|
|||||||
package mineplex.bungee;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BungeeRepository
|
|
||||||
{
|
|
||||||
// Yip Yip actual IP because if null route happens we can't resolve the HOSTNAME DERP FACE DEFEK7!!! -defek7
|
|
||||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
|
||||||
private String _userName = "root";
|
|
||||||
private String _password = "tAbechAk3wR7tuTh";
|
|
||||||
|
|
||||||
private static String CREATE_ONLINE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));";
|
|
||||||
private static String CREATE_PLAYER_TABLE = "CREATE TABLE IF NOT EXISTS BungeeServers (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(256), updated LONG, players INT, maxPlayers INT, ram INT, maxRam INT, PRIMARY KEY (id));";
|
|
||||||
|
|
||||||
private static String RETRIEVE_SERVERS_PLAYERCOUNTS = "SELECT bos.address, players, maxPlayers, BungeeServers.updated, bos.lastOnline, BungeeServers.US, now() FROM BungeeServers INNER JOIN bungeeOnlineStatus AS bos ON bos.address = BungeeServers.address WHERE TIME_TO_SEC(TIMEDIFF(now(), BungeeServers.updated)) < 15;";
|
|
||||||
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
preparedStatement = connection.prepareStatement(CREATE_ONLINE_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
|
|
||||||
preparedStatement.close();
|
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(CREATE_PLAYER_TABLE);
|
|
||||||
preparedStatement.execute();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<BungeeServer> getBungeeServers()
|
|
||||||
{
|
|
||||||
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>();
|
|
||||||
Connection connection = null;
|
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_SERVERS_PLAYERCOUNTS);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
|
||||||
long current = dateFormat.parse(resultSet.getString(7)).getTime();
|
|
||||||
long updated = dateFormat.parse(resultSet.getString(4)).getTime();
|
|
||||||
long lastOnline = dateFormat.parse(resultSet.getString(5)).getTime();
|
|
||||||
|
|
||||||
if (current - updated <= 15000 && current - lastOnline <= 300000)
|
|
||||||
{
|
|
||||||
BungeeServer server = new BungeeServer();
|
|
||||||
server.Address = resultSet.getString(1).split(":")[0];
|
|
||||||
server.Players = resultSet.getInt(2);
|
|
||||||
server.MaxPlayers = resultSet.getInt(3);
|
|
||||||
server.US = resultSet.getBoolean(6);
|
|
||||||
|
|
||||||
bungeeServers.add(server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bungeeServers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,10 @@
|
|||||||
package mineplex.bungee;
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -15,19 +17,28 @@ import java.util.logging.Logger;
|
|||||||
import mineplex.bungee.api.ApiDeleteCall;
|
import mineplex.bungee.api.ApiDeleteCall;
|
||||||
import mineplex.bungee.api.ApiGetCall;
|
import mineplex.bungee.api.ApiGetCall;
|
||||||
import mineplex.bungee.api.ApiPostCall;
|
import mineplex.bungee.api.ApiPostCall;
|
||||||
|
import mineplex.bungee.api.HttpCallBase;
|
||||||
import mineplex.bungee.api.token.ARecord;
|
import mineplex.bungee.api.token.ARecord;
|
||||||
import mineplex.bungee.api.token.DnsRecord;
|
import mineplex.bungee.api.token.DnsRecord;
|
||||||
import mineplex.bungee.api.token.DomainRecords;
|
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.ServerManager;
|
||||||
|
|
||||||
public class BungeeRotator
|
public class BungeeRotator
|
||||||
{
|
{
|
||||||
private static BungeeRepository _repository = null;
|
private static DataRepository<BungeeServer> _repository;
|
||||||
|
private static PlayerStatsRepository _ipRepository;
|
||||||
|
//private static ServerRepository _repository = null;
|
||||||
|
|
||||||
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||||
private static Logger _logger = Logger.getLogger("BungeeRotator");
|
private static Logger _logger = Logger.getLogger("BungeeRotator");
|
||||||
|
private static boolean _debug = false;
|
||||||
|
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
@ -56,7 +67,13 @@ public class BungeeRotator
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
_repository = new BungeeRepository();
|
_debug = new File("debug.dat").exists();
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
_ipRepository = new PlayerStatsRepository();
|
||||||
|
|
||||||
BungeeSorter bungeeSorter = new BungeeSorter();
|
BungeeSorter bungeeSorter = new BungeeSorter();
|
||||||
int maxRecordCount = 10;
|
int maxRecordCount = 10;
|
||||||
|
|
||||||
@ -64,92 +81,156 @@ public class BungeeRotator
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<BungeeServer> bungeeServers = _repository.getBungeeServers();
|
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>(_repository.getElements());
|
||||||
HashSet<String> usServers = new HashSet<String>();
|
|
||||||
HashSet<String> euServers = new HashSet<String>();
|
|
||||||
|
|
||||||
Collections.sort(bungeeServers, bungeeSorter);
|
Collections.sort(bungeeServers, bungeeSorter);
|
||||||
|
|
||||||
for (BungeeServer server : bungeeServers)
|
if (_debug)
|
||||||
{
|
{
|
||||||
if (usServers.size() < maxRecordCount && server.US)
|
int totalPlayers = 0;
|
||||||
|
int usPlayers = 0;
|
||||||
|
int euPlayers = 0;
|
||||||
|
|
||||||
|
for (BungeeServer server : bungeeServers)
|
||||||
{
|
{
|
||||||
if (usServers.size() >= 2 && server.Players > 900)
|
if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
log("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
totalPlayers += server.getPlayerCount();
|
||||||
usServers.add(server.Address);
|
|
||||||
}
|
|
||||||
else if (euServers.size() < maxRecordCount && !server.US)
|
|
||||||
{
|
|
||||||
if (euServers.size() >= 2 && server.Players > 900)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
log("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
if (server.getRegion() == Region.US)
|
||||||
euServers.add(server.Address);
|
usPlayers += server.getPlayerCount();
|
||||||
|
else
|
||||||
|
euPlayers += server.getPlayerCount();
|
||||||
|
|
||||||
|
System.out.println(server.getRegion().toString() + " " + 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
|
||||||
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"))
|
HashSet<String> usServers = new HashSet<String>();
|
||||||
|
HashSet<String> euServers = new HashSet<String>();
|
||||||
|
|
||||||
|
|
||||||
|
for (BungeeServer server : bungeeServers)
|
||||||
{
|
{
|
||||||
if (record.name.equalsIgnoreCase("us"))
|
if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (usServers.size() < maxRecordCount && server.getRegion() == Region.US)
|
||||||
{
|
{
|
||||||
if (usServers.contains(record.value))
|
if (usServers.size() >= 2 && server.getPlayerCount() > 900)
|
||||||
usServers.remove(record.value);
|
continue;
|
||||||
else
|
|
||||||
recordsToDelete.add(record);
|
log("SELECTED " + server.getPublicAddress() + " " + (server.getRegion() == Region.US ? "us" : "eu") + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
|
||||||
|
usServers.add(server.getPublicAddress());
|
||||||
}
|
}
|
||||||
else if (record.name.equalsIgnoreCase("eu"))
|
else if (euServers.size() < maxRecordCount && server.getRegion() != Region.US)
|
||||||
{
|
{
|
||||||
if (euServers.contains(record.value))
|
if (euServers.size() >= 2 && server.getPlayerCount() > 900)
|
||||||
euServers.remove(record.value);
|
continue;
|
||||||
else
|
|
||||||
recordsToDelete.add(record);
|
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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String address : usServers)
|
List<IpInfo> updatedAddresses = new ArrayList<IpInfo>(1000);
|
||||||
|
|
||||||
|
for (IpInfo ipInfo : _ipRepository.getIpAddresses())
|
||||||
{
|
{
|
||||||
recordsToAdd.add(new ARecord("us", address, 300));
|
IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/" + ipInfo.ipAddress).Execute(IPGeoData.class);
|
||||||
log("Addding server address in DNS : " + "us " + address);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String address : euServers)
|
_ipRepository.updateIps(updatedAddresses);
|
||||||
{
|
|
||||||
recordsToAdd.add(new ARecord("eu", address, 300));
|
|
||||||
log("Addding 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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
@ -162,6 +243,7 @@ public class BungeeRotator
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
log("Error doing something : " + ex.getMessage());
|
log("Error doing something : " + ex.getMessage());
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package mineplex.bungee;
|
|
||||||
|
|
||||||
public class BungeeServer
|
|
||||||
{
|
|
||||||
public String Address;
|
|
||||||
public int Players;
|
|
||||||
public int MaxPlayers;
|
|
||||||
public boolean US;
|
|
||||||
}
|
|
@ -2,14 +2,16 @@ package mineplex.bungee;
|
|||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
|
||||||
public class BungeeSorter implements Comparator<BungeeServer>
|
public class BungeeSorter implements Comparator<BungeeServer>
|
||||||
{
|
{
|
||||||
public int compare(BungeeServer a, BungeeServer b)
|
public int compare(BungeeServer a, BungeeServer b)
|
||||||
{
|
{
|
||||||
if (a.Players < b.Players)
|
if (a.getPlayerCount() < b.getPlayerCount())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (b.Players < a.Players)
|
if (b.getPlayerCount() < a.getPlayerCount())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -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,146 @@
|
|||||||
|
package mineplex.bungee;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlayerStatsRepository
|
||||||
|
{
|
||||||
|
private Connection _connection = null;
|
||||||
|
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
|
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 void initialize()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Initialized PlayerStats.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IpInfo> getIpAddresses()
|
||||||
|
{
|
||||||
|
List<IpInfo> ipinfos = new ArrayList<IpInfo>(1000);
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -51,13 +51,13 @@ public abstract class DnsMadeEasyApiCallBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
String timeStamp = getServerTime();
|
String timeStamp = getServerTime();
|
||||||
SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1");
|
SecretKeySpec keySpec = new SecretKeySpec("35bb3b97-3815-4b63-b60b-eb1882c07b40".getBytes(), "HmacSHA1");
|
||||||
Mac mac = Mac.getInstance("HmacSHA1");
|
Mac mac = Mac.getInstance("HmacSHA1");
|
||||||
mac.init(keySpec);
|
mac.init(keySpec);
|
||||||
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
|
||||||
Hex.encodeHexString(hashBytes);
|
Hex.encodeHexString(hashBytes);
|
||||||
|
|
||||||
request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850");
|
request.addHeader("x-dnsme-apiKey", "a9750980-b7df-4a7e-a047-2ade43628f0d");
|
||||||
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
request.addHeader("x-dnsme-requestDate", timeStamp + "");
|
||||||
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
|
||||||
request.addHeader("Content-Type", "application/json");
|
request.addHeader("Content-Type", "application/json");
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,6 @@ public class DnsRecord
|
|||||||
public String name;
|
public String name;
|
||||||
public String type;
|
public String type;
|
||||||
public String value;
|
public String value;
|
||||||
public String gtdLocation;
|
public String gtdLocation = "DEFAULT";
|
||||||
public int ttl;
|
public int ttl;
|
||||||
}
|
}
|
||||||
|
11
Plugins/Mineplex.ChestConverter/.classpath
Normal file
11
Plugins/Mineplex.ChestConverter/.classpath
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||||
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ChestConverter,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="ChestConverter,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ChestConverter,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||||
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}/common.xml"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.ChestConverter}"/>
|
||||||
|
</launchConfiguration>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||||
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}/common.xml"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.ServerMonitor}"/>
|
||||||
|
</launchConfiguration>
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="ServerMonitor,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
|
||||||
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}/common.xml"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
|
||||||
|
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||||
|
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Mineplex.ServerMonitor}"/>
|
||||||
|
</launchConfiguration>
|
37
Plugins/Mineplex.ChestConverter/.project
Normal file
37
Plugins/Mineplex.ChestConverter/.project
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Mineplex.ChestConverter</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||||
|
<triggers>auto,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
<dictionary>
|
||||||
|
<key>LaunchConfigHandle</key>
|
||||||
|
<value><project>/.externalToolBuilders/ServerMonitor.launch</value>
|
||||||
|
</dictionary>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||||
|
<triggers>auto,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
<dictionary>
|
||||||
|
<key>LaunchConfigHandle</key>
|
||||||
|
<value><project>/.externalToolBuilders/Chest.launch</value>
|
||||||
|
</dictionary>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.7
|
17
Plugins/Mineplex.ChestConverter/Mineplex.ServerMonitor.iml
Normal file
17
Plugins/Mineplex.ChestConverter/Mineplex.ServerMonitor.iml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="gson" level="project" />
|
||||||
|
<orderEntry type="library" name="httpclient" level="project" />
|
||||||
|
<orderEntry type="library" name="httpcore" level="project" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.Core.Common" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
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");
|
||||||
|
|
||||||
|
public static void main (String args[])
|
||||||
|
{
|
||||||
|
_repository = new ChestConverterRepository();
|
||||||
|
int count = 5000;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
HashMap<String, Integer> playerMap = _repository.retrieveKeyInventoryBatch(count);
|
||||||
|
|
||||||
|
if (playerMap.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_repository.incrementClient(playerMap, false);
|
||||||
|
_repository.deleteKeys(count);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds.");
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(String message)
|
||||||
|
{
|
||||||
|
System.out.println("[" + _dateFormat.format(new Date()) + "] " + message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,316 @@
|
|||||||
|
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.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
public class ChestConverterRepository
|
||||||
|
{
|
||||||
|
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
|
private static String RETRIEVE_CHESTS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 56 AND count > 0 ORDER BY accountInventory.id LIMIT ?;";
|
||||||
|
private static String RETRIEVE_KEYS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 67 AND count > 0 ORDER BY accountInventory.id LIMIT ?;";
|
||||||
|
|
||||||
|
private static String DELETE_CHESTS = "DELETE FROM accountInventory WHERE itemId = 56 ORDER BY accountInventory.id LIMIT ?";
|
||||||
|
private static String DELETE_KEYS = "DELETE FROM accountInventory WHERE itemId = 67 ORDER BY accountInventory.id LIMIT ?";
|
||||||
|
|
||||||
|
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
||||||
|
private static String UPDATE_CLIENT_INVENTORY = "UPDATE accountInventory AS AI INNER JOIN accounts ON AI.accountId = accounts.id SET AI.count = AI.count + ? WHERE accounts.uuid = ? AND AI.itemId = ?;";
|
||||||
|
|
||||||
|
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> retrieveChestInventoryBatch(int count)
|
||||||
|
{
|
||||||
|
HashMap<String, Integer> playerList = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_CHESTS);
|
||||||
|
preparedStatement.setInt(1, count);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
playerList.put(resultSet.getString(1), resultSet.getInt(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Integer> retrieveKeyInventoryBatch(int count)
|
||||||
|
{
|
||||||
|
HashMap<String, Integer> playerList = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_KEYS);
|
||||||
|
preparedStatement.setInt(1, count);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
playerList.put(resultSet.getString(1), resultSet.getInt(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementClient(HashMap<String, Integer> playerList, boolean chest)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(UPDATE_CLIENT_INVENTORY);
|
||||||
|
|
||||||
|
for (Entry<String, Integer> entry : playerList.entrySet())
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, entry.getValue());
|
||||||
|
preparedStatement.setString(2, entry.getKey());
|
||||||
|
preparedStatement.setInt(3, chest ? 690 : 692);
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
|
||||||
|
if (chest)
|
||||||
|
{
|
||||||
|
if (entry.getValue() > 20)
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, 1);
|
||||||
|
preparedStatement.setString(2, entry.getKey());
|
||||||
|
preparedStatement.setInt(3, 692);
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.getValue() > 50)
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, 1);
|
||||||
|
preparedStatement.setString(2, entry.getKey());
|
||||||
|
preparedStatement.setInt(3, 691);
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] rowsAffected = preparedStatement.executeBatch();
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
preparedStatement.close();
|
||||||
|
preparedStatement = _connection.prepareStatement(INSERT_CLIENT_INVENTORY);
|
||||||
|
|
||||||
|
for (Entry<String, Integer> entry : playerList.entrySet())
|
||||||
|
{
|
||||||
|
if (rowsAffected[i] < 1)
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, chest ? 690 : 692);
|
||||||
|
preparedStatement.setInt(2, entry.getValue());
|
||||||
|
preparedStatement.setString(3, entry.getKey());
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
|
||||||
|
if (chest)
|
||||||
|
{
|
||||||
|
if (entry.getValue() > 20)
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, 692);
|
||||||
|
preparedStatement.setInt(2, 1);
|
||||||
|
preparedStatement.setString(3, entry.getKey());
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.getValue() > 50)
|
||||||
|
{
|
||||||
|
preparedStatement.setInt(1, 691);
|
||||||
|
preparedStatement.setInt(2, 1);
|
||||||
|
preparedStatement.setString(3, entry.getKey());
|
||||||
|
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.executeBatch();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteChests(int count)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(DELETE_CHESTS);
|
||||||
|
preparedStatement.setInt(1, count);
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
System.out.println("Deleting " + count + " inventory records.");
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (preparedStatement != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
preparedStatement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteKeys(int count)
|
||||||
|
{
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || _connection.isClosed())
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(DELETE_KEYS);
|
||||||
|
preparedStatement.setInt(1, count);
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
|
||||||
|
System.out.println("Deleting " + count + " inventory records.");
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
@ -14,12 +14,15 @@ public enum Rank
|
|||||||
SNR_MODERATOR("Sr.Mod", ChatColor.GOLD),
|
SNR_MODERATOR("Sr.Mod", ChatColor.GOLD),
|
||||||
MODERATOR("Mod", ChatColor.GOLD),
|
MODERATOR("Mod", ChatColor.GOLD),
|
||||||
HELPER("Helper", ChatColor.DARK_AQUA),
|
HELPER("Helper", ChatColor.DARK_AQUA),
|
||||||
MAPDEV("Mapper", ChatColor.BLUE),
|
MAPDEV("Builder", ChatColor.BLUE),
|
||||||
MAPLEAD("MapKing", ChatColor.DARK_PURPLE),
|
MAPLEAD("MapLead", ChatColor.DARK_PURPLE),
|
||||||
|
|
||||||
|
EVENT("Event", ChatColor.WHITE),
|
||||||
|
|
||||||
//Staff ^^
|
//Staff ^^
|
||||||
|
|
||||||
YOUTUBE("YouTube", ChatColor.RED),
|
YOUTUBE("YouTube", ChatColor.RED),
|
||||||
|
TWITCH("Twitch", ChatColor.DARK_PURPLE),
|
||||||
LEGEND("Legend", ChatColor.GREEN),
|
LEGEND("Legend", ChatColor.GREEN),
|
||||||
HERO("Hero", ChatColor.LIGHT_PURPLE),
|
HERO("Hero", ChatColor.LIGHT_PURPLE),
|
||||||
ULTRA("Ultra", ChatColor.AQUA),
|
ULTRA("Ultra", ChatColor.AQUA),
|
||||||
|
@ -134,6 +134,13 @@ public class F
|
|||||||
if (on) return indent + C.listTitle + variable + ": " + C.listValueOn + value;
|
if (on) return indent + C.listTitle + variable + ": " + C.listValueOn + value;
|
||||||
else return indent + C.listTitle + variable + ": " + C.listValueOff + value;
|
else return indent + C.listTitle + variable + ": " + C.listValueOff + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String ed(boolean var)
|
||||||
|
{
|
||||||
|
if (var)
|
||||||
|
return C.listValueOn + "Enabled" + C.mBody;
|
||||||
|
return C.listValueOff + "Disabled" + C.mBody;
|
||||||
|
}
|
||||||
|
|
||||||
public static String oo(boolean var)
|
public static String oo(boolean var)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Set;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -92,6 +93,10 @@ public class UtilAlg
|
|||||||
if (y <= 0) pitch += 90;
|
if (y <= 0) pitch += 90;
|
||||||
else pitch -= 90;
|
else pitch -= 90;
|
||||||
|
|
||||||
|
//Fix for two vectors at same Y giving 180
|
||||||
|
if (pitch == 180)
|
||||||
|
pitch = 0;
|
||||||
|
|
||||||
return (float) pitch;
|
return (float) pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,4 +249,15 @@ public class UtilAlg
|
|||||||
|
|
||||||
return bestLoc;
|
return bestLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isInPyramid(Vector a, Vector b, double angleLimit)
|
||||||
|
{
|
||||||
|
return (Math.abs(GetPitch(a) - GetPitch(b)) < angleLimit) && (Math.abs(GetYaw(a) - GetYaw(b)) < angleLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTargetInPlayerPyramid(Player player, Player target, double angleLimit)
|
||||||
|
{
|
||||||
|
return isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getEyeLocation()), angleLimit) ||
|
||||||
|
isInPyramid(player.getLocation().getDirection(), UtilAlg.getTrajectory(player.getEyeLocation(), target.getLocation()), angleLimit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ public class UtilEnt
|
|||||||
|
|
||||||
for (Entity cur : loc.getWorld().getEntities())
|
for (Entity cur : loc.getWorld().getEntities())
|
||||||
{
|
{
|
||||||
if (!(cur instanceof LivingEntity) || (cur instanceof Player && ((Player)cur).getGameMode() == GameMode.CREATIVE))
|
if (!(cur instanceof LivingEntity) || UtilPlayer.isSpectator(cur))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LivingEntity ent = (LivingEntity)cur;
|
LivingEntity ent = (LivingEntity)cur;
|
||||||
@ -627,4 +627,9 @@ public class UtilEnt
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean inWater(LivingEntity ent)
|
||||||
|
{
|
||||||
|
return ent.getLocation().getBlock().getTypeId() == 8 || ent.getLocation().getBlock().getTypeId() == 9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package mineplex.core.common.util;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -68,20 +67,28 @@ public class UtilInv
|
|||||||
{
|
{
|
||||||
return contains(player, null, item, data, required);
|
return contains(player, null, item, data, required);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required)
|
public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required)
|
||||||
|
{
|
||||||
|
return contains(player, itemNameContains, item, data, required, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required, boolean checkArmor, boolean checkCursor)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i : player.getInventory().all(item).keySet())
|
for (ItemStack stack : getItems(player, checkArmor, checkCursor))
|
||||||
{
|
{
|
||||||
if (required <= 0)
|
if (required <= 0)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
ItemStack stack = player.getInventory().getItem(i);
|
|
||||||
|
|
||||||
if (stack == null)
|
if (stack == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (stack.getType() != item)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (stack.getAmount() <= 0)
|
if (stack.getAmount() <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -152,34 +159,45 @@ public class UtilInv
|
|||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<ItemStack> getItems(Player player)
|
public static ArrayList<ItemStack> getItems(Player player)
|
||||||
{
|
{
|
||||||
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
return getItems(player, true, true);
|
||||||
PlayerInventory inv = player.getInventory();
|
}
|
||||||
|
|
||||||
for (ItemStack item : inv.getContents())
|
public static ArrayList<ItemStack> getItems(Player player, boolean getArmor, boolean getCursor)
|
||||||
{
|
{
|
||||||
if (item != null && item.getType() != Material.AIR)
|
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
{
|
PlayerInventory inv = player.getInventory();
|
||||||
items.add(item.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemStack item : inv.getArmorContents())
|
|
||||||
{
|
|
||||||
if (item != null && item.getType() != Material.AIR)
|
|
||||||
{
|
|
||||||
items.add(item.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack cursorItem = player.getItemOnCursor();
|
for (ItemStack item : inv.getContents())
|
||||||
|
{
|
||||||
|
if (item != null && item.getType() != Material.AIR)
|
||||||
|
{
|
||||||
|
items.add(item.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cursorItem != null && cursorItem.getType() != Material.AIR)
|
if (getArmor)
|
||||||
items.add(cursorItem.clone());
|
{
|
||||||
|
for (ItemStack item : inv.getArmorContents())
|
||||||
return items;
|
{
|
||||||
|
if (item != null && item.getType() != Material.AIR)
|
||||||
|
{
|
||||||
|
items.add(item.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCursor)
|
||||||
|
{
|
||||||
|
ItemStack cursorItem = player.getItemOnCursor();
|
||||||
|
|
||||||
|
if (cursorItem != null && cursorItem.getType() != Material.AIR)
|
||||||
|
items.add(cursorItem.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drop(Player player, boolean clear)
|
public static void drop(Player player, boolean clear)
|
||||||
|
@ -0,0 +1,130 @@
|
|||||||
|
package mineplex.core.common.util;
|
||||||
|
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class UtilItem
|
||||||
|
{
|
||||||
|
public static LinkedList<Entry<Material, Byte>> matchItem(Player caller, String items, boolean inform)
|
||||||
|
{
|
||||||
|
LinkedList<Entry<Material, Byte>> matchList = new LinkedList<Entry<Material, Byte>>();
|
||||||
|
|
||||||
|
String failList = "";
|
||||||
|
|
||||||
|
//Mass Search
|
||||||
|
for (String cur : items.split(","))
|
||||||
|
{
|
||||||
|
Entry<Material, Byte> match = searchItem(caller, cur, inform);
|
||||||
|
|
||||||
|
if (match != null)
|
||||||
|
matchList.add(match);
|
||||||
|
|
||||||
|
else
|
||||||
|
failList += cur + " " ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inform && failList.length() > 0)
|
||||||
|
{
|
||||||
|
failList = failList.substring(0, failList.length() - 1);
|
||||||
|
UtilPlayer.message(caller, F.main("Item(s) Search", "" +
|
||||||
|
C.mBody + " Invalid [" +
|
||||||
|
C.mElem + failList +
|
||||||
|
C.mBody + "]."));
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Entry<Material, Byte> searchItem(Player caller, String args, boolean inform)
|
||||||
|
{
|
||||||
|
LinkedList<Entry<Material, Byte>> matchList = new LinkedList<Entry<Material, Byte>>();
|
||||||
|
|
||||||
|
for (Material cur : Material.values())
|
||||||
|
{
|
||||||
|
//By Name
|
||||||
|
if (cur.toString().equalsIgnoreCase(args))
|
||||||
|
return new AbstractMap.SimpleEntry<Material, Byte>(cur, (byte)0);
|
||||||
|
|
||||||
|
if (cur.toString().toLowerCase().contains(args.toLowerCase()))
|
||||||
|
matchList.add(new AbstractMap.SimpleEntry<Material, Byte>(cur, (byte)0));
|
||||||
|
|
||||||
|
//By ID:Data
|
||||||
|
String[] arg = args.split(":");
|
||||||
|
|
||||||
|
//ID
|
||||||
|
int id = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (arg.length > 0)
|
||||||
|
id = Integer.parseInt(arg[0]);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id != cur.getId())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
//Data
|
||||||
|
byte data = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (arg.length > 1)
|
||||||
|
data = Byte.parseByte(arg[1]);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AbstractMap.SimpleEntry<Material, Byte>(cur, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//No / Non-Unique
|
||||||
|
if (matchList.size() != 1)
|
||||||
|
{
|
||||||
|
if (!inform)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//Inform
|
||||||
|
UtilPlayer.message(caller, F.main("Item Search", "" +
|
||||||
|
C.mCount + matchList.size() +
|
||||||
|
C.mBody + " matches for [" +
|
||||||
|
C.mElem + args +
|
||||||
|
C.mBody + "]."));
|
||||||
|
|
||||||
|
if (matchList.size() > 0)
|
||||||
|
{
|
||||||
|
String matchString = "";
|
||||||
|
for (Entry<Material, Byte> cur : matchList)
|
||||||
|
matchString += F.elem(cur.getKey().toString()) + ", ";
|
||||||
|
if (matchString.length() > 1)
|
||||||
|
matchString = matchString.substring(0 , matchString.length() - 2);
|
||||||
|
|
||||||
|
UtilPlayer.message(caller, F.main("Item Search", "" +
|
||||||
|
C.mBody + "Matches [" +
|
||||||
|
C.mElem + matchString +
|
||||||
|
C.mBody + "]."));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String itemToStr(ItemStack item)
|
||||||
|
{
|
||||||
|
String data = "0";
|
||||||
|
if (item.getData() != null)
|
||||||
|
data = item.getData().getData() + "";
|
||||||
|
|
||||||
|
return item.getType() + ":" + item.getAmount() + ":" + item.getDurability() + ":" + data;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
|||||||
|
package mineplex.core.common.util;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class UtilText
|
||||||
|
{
|
||||||
|
public static <T> String listToString(Collection<T> inputList, boolean comma)
|
||||||
|
{
|
||||||
|
String out = "";
|
||||||
|
|
||||||
|
for (T cur : inputList)
|
||||||
|
{
|
||||||
|
out += cur.toString() + (comma ? ", " : " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out.length() > 0)
|
||||||
|
{
|
||||||
|
out = out.substring(0, out.length()-(comma ? 2 : 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
|||||||
private HashSet<Integer> _ignoreSkulls = new HashSet<Integer>();
|
private HashSet<Integer> _ignoreSkulls = new HashSet<Integer>();
|
||||||
|
|
||||||
private NautHashMap<UUID, Long> _exemptTimeMap = new NautHashMap<UUID, Long>();
|
private NautHashMap<UUID, Long> _exemptTimeMap = new NautHashMap<UUID, Long>();
|
||||||
|
private NautHashMap<UUID, NautHashMap<CheckType, Long>> _doubleStrike = new NautHashMap<UUID, NautHashMap<CheckType, Long>>();
|
||||||
|
|
||||||
private Field _destroyId;
|
private Field _destroyId;
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
|||||||
|
|
||||||
NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
|
NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
|
||||||
NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
|
NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
|
||||||
|
NCPHookManager.addHook(CheckType.ALL, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -138,6 +140,24 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Iterator<Entry<UUID, NautHashMap<CheckType, Long>>> iterator = _doubleStrike.entrySet().iterator(); iterator.hasNext();)
|
||||||
|
{
|
||||||
|
Entry<UUID, NautHashMap<CheckType, Long>> entry = iterator.next();
|
||||||
|
|
||||||
|
for (Iterator<Entry<CheckType, Long>> innerIterator = entry.getValue().entrySet().iterator(); innerIterator.hasNext();)
|
||||||
|
{
|
||||||
|
final Entry<CheckType, Long> entry2 = innerIterator.next();
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() > entry2.getValue())
|
||||||
|
{
|
||||||
|
innerIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entry.getValue() == null || entry.getValue().size() == 0)
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -556,11 +576,28 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo violationInfo)
|
public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo violationInfo)
|
||||||
{
|
{
|
||||||
boolean failure = _exemptTimeMap.containsKey(player.getUniqueId());
|
boolean failure = false;
|
||||||
|
|
||||||
if (failure)
|
if (checkType == CheckType.MOVING_SURVIVALFLY || checkType == CheckType.MOVING_PASSABLE)
|
||||||
MovingData.getData(player).clearFlyData();
|
{
|
||||||
|
failure = _exemptTimeMap.containsKey(player.getUniqueId());
|
||||||
|
|
||||||
|
if (failure)
|
||||||
|
MovingData.getData(player).clearFlyData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the second strike system.
|
||||||
|
if (!failure)
|
||||||
|
{
|
||||||
|
if (!_doubleStrike.containsKey(player.getUniqueId()) || !_doubleStrike.get(player.getUniqueId()).containsKey(checkType.getParent()))
|
||||||
|
failure = true;
|
||||||
|
|
||||||
|
if (!_doubleStrike.containsKey(player.getUniqueId()))
|
||||||
|
_doubleStrike.put(player.getUniqueId(), new NautHashMap<CheckType, Long>());
|
||||||
|
|
||||||
|
_doubleStrike.get(player.getUniqueId()).put(checkType.getParent(), System.currentTimeMillis() + 5000);
|
||||||
|
}
|
||||||
|
|
||||||
return failure;
|
return failure;
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,9 @@ public abstract class MiniDbClientPlugin<DataType extends Object> extends MiniCl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
|
public abstract void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
|
||||||
|
|
||||||
|
public CoreClientManager getClientManager()
|
||||||
|
{
|
||||||
|
return ClientManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package mineplex.core.account;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mineplex.serverdata.data.Data;
|
||||||
|
|
||||||
|
public class AccountCache implements Data
|
||||||
|
{
|
||||||
|
private UUID _uuid;
|
||||||
|
private Integer _id;
|
||||||
|
|
||||||
|
public AccountCache(UUID uuid, int id)
|
||||||
|
{
|
||||||
|
_uuid = uuid;
|
||||||
|
_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUUID()
|
||||||
|
{
|
||||||
|
return _uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDataId()
|
||||||
|
{
|
||||||
|
return _uuid.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class CoreClient
|
public class CoreClient
|
||||||
{
|
{
|
||||||
private int _accountId;
|
private int _accountId = -1;
|
||||||
private String _name;
|
private String _name;
|
||||||
private Player _player;
|
private Player _player;
|
||||||
private Rank _rank;
|
private Rank _rank;
|
||||||
@ -37,7 +37,7 @@ public class CoreClient
|
|||||||
_player = player;
|
_player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetAccountId()
|
public int getAccountId()
|
||||||
{
|
{
|
||||||
return _accountId;
|
return _accountId;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ public class CoreClient
|
|||||||
_player = null;
|
_player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAccountId(int accountId)
|
public void setAccountId(int accountId)
|
||||||
{
|
{
|
||||||
_accountId = accountId;
|
_accountId = accountId;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,10 @@ import mineplex.core.common.util.UtilPlayer;
|
|||||||
import mineplex.core.timing.TimingManager;
|
import mineplex.core.timing.TimingManager;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -43,6 +47,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
private AccountRepository _repository;
|
private AccountRepository _repository;
|
||||||
private NautHashMap<String, CoreClient> _clientList;
|
private NautHashMap<String, CoreClient> _clientList;
|
||||||
private HashSet<String> _duplicateLoginGlitchPreventionList;
|
private HashSet<String> _duplicateLoginGlitchPreventionList;
|
||||||
|
private RedisDataRepository<AccountCache> _accountCacheRepository;
|
||||||
|
|
||||||
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
|
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
|
||||||
|
|
||||||
@ -59,6 +64,9 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
_repository = new AccountRepository(plugin, webServer);
|
_repository = new AccountRepository(plugin, webServer);
|
||||||
_clientList = new NautHashMap<String, CoreClient>();
|
_clientList = new NautHashMap<String, CoreClient>();
|
||||||
_duplicateLoginGlitchPreventionList = new HashSet<String>();
|
_duplicateLoginGlitchPreventionList = new HashSet<String>();
|
||||||
|
|
||||||
|
_accountCacheRepository = new RedisDataRepository<AccountCache>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
|
Region.ALL, AccountCache.class, "accountCache");
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountRepository getRepository()
|
public AccountRepository getRepository()
|
||||||
@ -155,7 +163,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
catch(Exception exception)
|
catch(Exception exception)
|
||||||
{
|
{
|
||||||
event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute.");
|
event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute.");
|
||||||
System.out.println(exception.getMessage());
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -189,34 +197,45 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ClientToken token = null;
|
try
|
||||||
Gson gson = new Gson();
|
|
||||||
|
|
||||||
// Fails if not in DB and if duplicate.
|
|
||||||
UUID uuid = loadUUIDFromDB(playerName);
|
|
||||||
|
|
||||||
if (uuid == null)
|
|
||||||
uuid = UUIDFetcher.getUUIDOf(playerName);
|
|
||||||
|
|
||||||
String response = _repository.getClientByUUID(uuid);
|
|
||||||
token = gson.fromJson(response, ClientToken.class);
|
|
||||||
|
|
||||||
client.SetAccountId(token.AccountId);
|
|
||||||
client.SetRank(Rank.valueOf(token.Rank));
|
|
||||||
|
|
||||||
_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName());
|
|
||||||
|
|
||||||
// JSON sql response
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
|
|
||||||
{
|
{
|
||||||
public void run()
|
ClientToken token = null;
|
||||||
|
Gson gson = new Gson();
|
||||||
|
|
||||||
|
// Fails if not in DB and if duplicate.
|
||||||
|
UUID uuid = loadUUIDFromDB(playerName);
|
||||||
|
|
||||||
|
if (uuid == null)
|
||||||
|
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||||
|
|
||||||
|
String response = _repository.getClientByUUID(uuid);
|
||||||
|
token = gson.fromJson(response, ClientToken.class);
|
||||||
|
|
||||||
|
client.SetRank(Rank.valueOf(token.Rank));
|
||||||
|
|
||||||
|
client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||||
|
|
||||||
|
// JSON sql response
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
|
||||||
|
|
||||||
|
if (client.getAccountId() > 0)
|
||||||
|
_accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId()));
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
|
||||||
{
|
{
|
||||||
if (runnable != null)
|
public void run()
|
||||||
runnable.run();
|
{
|
||||||
}
|
if (runnable != null)
|
||||||
});
|
runnable.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -234,7 +253,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName());
|
client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()));
|
||||||
_clientLoginLock.remove(client.GetPlayerName());
|
_clientLoginLock.remove(client.GetPlayerName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -244,8 +263,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
TimingManager.stop(client.GetPlayerName() + " GetClient.");
|
TimingManager.stop(client.GetPlayerName() + " GetClient.");
|
||||||
|
|
||||||
token = gson.fromJson(response, ClientToken.class);
|
token = gson.fromJson(response, ClientToken.class);
|
||||||
|
|
||||||
client.SetAccountId(token.AccountId);
|
|
||||||
client.SetRank(Rank.valueOf(token.Rank));
|
client.SetRank(Rank.valueOf(token.Rank));
|
||||||
|
|
||||||
// _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
|
// _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
|
||||||
@ -272,6 +290,11 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
|
|
||||||
TimingManager.stop(client.GetPlayerName() + " LoadClient Total.");
|
TimingManager.stop(client.GetPlayerName() + " LoadClient Total.");
|
||||||
|
|
||||||
|
System.out.println(client.GetPlayerName() + "'s account id = " + client.getAccountId());
|
||||||
|
|
||||||
|
if (client.getAccountId() > 0)
|
||||||
|
_accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId()));
|
||||||
|
|
||||||
return !_clientLoginLock.containsKey(client.GetPlayerName());
|
return !_clientLoginLock.containsKey(client.GetPlayerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +360,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveRank(final String name, Rank rank, boolean perm)
|
public void SaveRank(final String name, final UUID uuid, Rank rank, boolean perm)
|
||||||
{
|
{
|
||||||
_repository.saveRank(new Callback<Rank>()
|
_repository.saveRank(new Callback<Rank>()
|
||||||
{
|
{
|
||||||
@ -350,7 +373,7 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
client.SetRank(newRank);
|
client.SetRank(newRank);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, name, rank, perm);
|
}, name, uuid, rank, perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName)
|
public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName)
|
||||||
@ -473,4 +496,9 @@ public class CoreClientManager extends MiniPlugin
|
|||||||
|
|
||||||
return client.GetRank().Has(rank);
|
return client.GetRank().Has(rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCachedClientAccountId(UUID uuid)
|
||||||
|
{
|
||||||
|
return _accountCacheRepository.getElement(uuid.toString()).getId();
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,5 +9,5 @@ public interface ILoginProcessor
|
|||||||
|
|
||||||
void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
|
void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
|
||||||
|
|
||||||
String getQuery(String uuid, String name);
|
String getQuery(int accountId, String uuid, String name);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package mineplex.core.account.command;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -11,6 +12,7 @@ import mineplex.core.command.CommandBase;
|
|||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
|
|
||||||
public class UpdateRank extends CommandBase<CoreClientManager>
|
public class UpdateRank extends CommandBase<CoreClientManager>
|
||||||
@ -50,7 +52,7 @@ public class UpdateRank extends CommandBase<CoreClientManager>
|
|||||||
|
|
||||||
final Rank rank = tempRank;
|
final Rank rank = tempRank;
|
||||||
|
|
||||||
if ((rank == Rank.YOUTUBE && Plugin.Get(caller).GetRank().Has(Rank.OWNER)) || rank == Rank.MODERATOR || rank == Rank.HELPER || rank == Rank.ALL || rank == Rank.MAPDEV || rank == Rank.SNR_MODERATOR)
|
if (rank == Rank.YOUTUBE || rank == Rank.MODERATOR || rank == Rank.HELPER || rank == Rank.ALL || rank == Rank.MAPDEV || rank == Rank.SNR_MODERATOR)
|
||||||
{
|
{
|
||||||
Plugin.getRepository().matchPlayerName(new Callback<List<String>>()
|
Plugin.getRepository().matchPlayerName(new Callback<List<String>>()
|
||||||
{
|
{
|
||||||
@ -86,13 +88,18 @@ public class UpdateRank extends CommandBase<CoreClientManager>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UUID uuid = Plugin.loadUUIDFromDB(playerName);
|
||||||
|
|
||||||
|
if (uuid == null)
|
||||||
|
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||||
|
|
||||||
Plugin.getRepository().saveRank(new Callback<Rank>()
|
Plugin.getRepository().saveRank(new Callback<Rank>()
|
||||||
{
|
{
|
||||||
public void run(Rank rank)
|
public void run(Rank rank)
|
||||||
{
|
{
|
||||||
caller.sendMessage(F.main(Plugin.getName(), target + "'s rank has been updated to " + rank.Name + "!"));
|
caller.sendMessage(F.main(Plugin.getName(), target + "'s rank has been updated to " + rank.Name + "!"));
|
||||||
}
|
}
|
||||||
}, target, rank, true);
|
}, target, uuid, rank, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, caller, playerName, true);
|
}, caller, playerName, true);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.core.account.repository;
|
package mineplex.core.account.repository;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@ -18,7 +19,7 @@ import mineplex.core.account.repository.token.RankUpdateToken;
|
|||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
@ -30,7 +31,7 @@ import mineplex.core.server.remotecall.JsonWebCall;
|
|||||||
public class AccountRepository extends RepositoryBase
|
public class AccountRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));";
|
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));";
|
||||||
private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);";
|
private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());";
|
||||||
private static String UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
|
private static String UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
|
||||||
private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
|
private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
|
||||||
private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;";
|
private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;";
|
||||||
@ -43,34 +44,9 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
public AccountRepository(JavaPlugin plugin, String webAddress)
|
public AccountRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
|
|
||||||
Statement statement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement = getConnection().createStatement();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (statement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,14 +55,40 @@ public class AccountRepository extends RepositoryBase
|
|||||||
//executeUpdate(CREATE_ACCOUNT_TABLE);
|
//executeUpdate(CREATE_ACCOUNT_TABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
|
public int login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
|
||||||
{
|
{
|
||||||
Statement statement = null;
|
int accountId = -1;
|
||||||
ResultSet resultSet = null;
|
try (
|
||||||
|
Connection connection = getConnection();
|
||||||
try
|
Statement statement = connection.createStatement()
|
||||||
|
)
|
||||||
{
|
{
|
||||||
statement = getConnection().createStatement();
|
statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;");
|
||||||
|
ResultSet resultSet = statement.getResultSet();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
accountId = resultSet.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountId == -1)
|
||||||
|
{
|
||||||
|
final List<Integer> tempList = new ArrayList<Integer>(1);
|
||||||
|
|
||||||
|
executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||||
|
{
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
tempList.add(resultSet.getInt(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name));
|
||||||
|
|
||||||
|
accountId = tempList.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
boolean statementStatus = statement.execute(
|
boolean statementStatus = statement.execute(
|
||||||
@ -100,10 +102,11 @@ public class AccountRepository extends RepositoryBase
|
|||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';";
|
String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';";
|
||||||
|
|
||||||
for (ILoginProcessor loginProcessor : loginProcessors.values())
|
for (ILoginProcessor loginProcessor : loginProcessors.values())
|
||||||
{
|
{
|
||||||
loginString += loginProcessor.getQuery(uuid, name);
|
loginString += loginProcessor.getQuery(accountId, uuid, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.execute(loginString);
|
statement.execute(loginString);
|
||||||
@ -133,51 +136,22 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
System.out.println("Done");
|
System.out.println("Done");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
boolean accountExists = statement.getUpdateCount() != 0;
|
|
||||||
|
|
||||||
|
statement.getUpdateCount();
|
||||||
statement.getMoreResults();
|
statement.getMoreResults();
|
||||||
|
|
||||||
for (ILoginProcessor loginProcessor : loginProcessors.values())
|
for (ILoginProcessor loginProcessor : loginProcessors.values())
|
||||||
{
|
{
|
||||||
loginProcessor.processLoginResultSet(name, statement.getResultSet());
|
loginProcessor.processLoginResultSet(name, statement.getResultSet());
|
||||||
statement.getMoreResults();
|
statement.getMoreResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!accountExists)
|
|
||||||
{
|
|
||||||
executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
return accountId;
|
||||||
if (statement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultSet != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetClient(String name, UUID uuid, String ipAddress)
|
public String GetClient(String name, UUID uuid, String ipAddress)
|
||||||
@ -211,13 +185,13 @@ public class AccountRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
}, new ColumnVarChar("name", 100, name));
|
}, new ColumnVarChar("name", 100, name));
|
||||||
|
|
||||||
if (uuids.size() > 1)
|
if (uuids.size() > 0)
|
||||||
return null;
|
return uuids.get(uuids.size() - 1);
|
||||||
else
|
else
|
||||||
return uuids.size() == 1 ? uuids.get(0) : null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveRank(final Callback<Rank> callback, final String name, final Rank rank, final boolean perm)
|
public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)
|
||||||
{
|
{
|
||||||
final RankUpdateToken token = new RankUpdateToken();
|
final RankUpdateToken token = new RankUpdateToken();
|
||||||
token.Name = name;
|
token.Name = name;
|
||||||
@ -231,16 +205,16 @@ public class AccountRepository extends RepositoryBase
|
|||||||
if (rank == Rank.ULTRA || rank == Rank.HERO || rank == Rank.LEGEND)
|
if (rank == Rank.ULTRA || rank == Rank.HERO || rank == Rank.LEGEND)
|
||||||
{
|
{
|
||||||
if (perm)
|
if (perm)
|
||||||
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
|
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||||
else
|
else
|
||||||
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
|
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (perm)
|
if (perm)
|
||||||
executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
|
executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||||
else
|
else
|
||||||
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
|
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
|
||||||
|
@ -209,6 +209,8 @@ public class AchievementManager extends MiniPlugin
|
|||||||
level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
|
level = Math.max(level, 50 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
|
||||||
else if (rank.Has(Rank.ADMIN))
|
else if (rank.Has(Rank.ADMIN))
|
||||||
level = Math.max(level, 30 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
|
level = Math.max(level, 30 + get(sender, Achievement.GLOBAL_GEM_HUNTER).getLevel());
|
||||||
|
else if (rank.Has(Rank.SNR_MODERATOR))
|
||||||
|
level = Math.max(level, 15);
|
||||||
else if (rank.Has(Rank.MODERATOR))
|
else if (rank.Has(Rank.MODERATOR))
|
||||||
level = Math.max(level, 5);
|
level = Math.max(level, 5);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public class AntiHack extends MiniPlugin
|
|||||||
if (player.equals(other))
|
if (player.equals(other))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (other.getGameMode() != GameMode.SURVIVAL)
|
if (other.getGameMode() != GameMode.SURVIVAL || UtilPlayer.isSpectator(player))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (other.getVehicle() != null)
|
if (other.getVehicle() != null)
|
||||||
@ -202,7 +202,7 @@ public class AntiHack extends MiniPlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL)
|
if (player.isFlying() || player.isInsideVehicle() || player.getGameMode() != GameMode.SURVIVAL || UtilPlayer.isSpectator(player))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import mineplex.core.antihack.AntiHack;
|
|||||||
import mineplex.core.antihack.Detector;
|
import mineplex.core.antihack.Detector;
|
||||||
import mineplex.core.common.util.UtilEvent;
|
import mineplex.core.common.util.UtilEvent;
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
@ -29,7 +30,7 @@ public class Reach extends MiniPlugin implements Detector
|
|||||||
|
|
||||||
public Reach (AntiHack host)
|
public Reach (AntiHack host)
|
||||||
{
|
{
|
||||||
super("Speed Detector", host.getPlugin());
|
super("Reach Detector", host.getPlugin());
|
||||||
Host = host;
|
Host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class Reach extends MiniPlugin implements Detector
|
|||||||
|
|
||||||
for (Player player : UtilServer.getPlayers())
|
for (Player player : UtilServer.getPlayers())
|
||||||
{
|
{
|
||||||
if (player.getGameMode() != GameMode.SURVIVAL)
|
if (player.getGameMode() != GameMode.SURVIVAL || UtilPlayer.isSpectator(player))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!_history.containsKey(player))
|
if (!_history.containsKey(player))
|
||||||
|
@ -0,0 +1,203 @@
|
|||||||
|
package mineplex.core.aprilfools;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.MiniPlugin;
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.util.UtilMath;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.common.util.UtilTextMiddle;
|
||||||
|
import mineplex.core.disguise.DisguiseManager;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseCow;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
|
public class AprilFoolsManager extends MiniPlugin
|
||||||
|
{
|
||||||
|
public static AprilFoolsManager Instance;
|
||||||
|
|
||||||
|
private boolean _enabled;
|
||||||
|
private DisguiseManager _disguiseManager;
|
||||||
|
private CoreClientManager _clientManager;
|
||||||
|
|
||||||
|
protected AprilFoolsManager(JavaPlugin plugin, CoreClientManager clientManager, DisguiseManager disguiseManager)
|
||||||
|
{
|
||||||
|
super("April Fools", plugin);
|
||||||
|
|
||||||
|
_disguiseManager = disguiseManager;
|
||||||
|
_clientManager = clientManager;
|
||||||
|
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
_enabled = (c.get(Calendar.MONTH) == Calendar.APRIL && c.get(Calendar.DAY_OF_MONTH) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Initialize(JavaPlugin plugin, CoreClientManager clientManager, DisguiseManager disguiseManager)
|
||||||
|
{
|
||||||
|
Instance = new AprilFoolsManager(plugin, clientManager, disguiseManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void updateEnabled(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.SLOW)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
_enabled = (c.get(Calendar.MONTH) == Calendar.APRIL && c.get(Calendar.DAY_OF_MONTH) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void chatAdd(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
if (!_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String[] words = event.getMessage().split(" ");
|
||||||
|
|
||||||
|
String out = "";
|
||||||
|
for (String word : words)
|
||||||
|
{
|
||||||
|
//Prefix
|
||||||
|
if (Math.random() > 0.85)
|
||||||
|
{
|
||||||
|
out += "moo";
|
||||||
|
|
||||||
|
for (int i=0 ; i<UtilMath.r(2) ; i++)
|
||||||
|
out += "o";
|
||||||
|
|
||||||
|
out += " " + word + " ";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Suffix
|
||||||
|
else if (Math.random() > 0.85)
|
||||||
|
{
|
||||||
|
out += word + " ";
|
||||||
|
|
||||||
|
out += "moo";
|
||||||
|
|
||||||
|
for (int i=0 ; i<UtilMath.r(2) ; i++)
|
||||||
|
out += "o";
|
||||||
|
|
||||||
|
out += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
//Swap
|
||||||
|
else if (Math.random() > 0.99)
|
||||||
|
{
|
||||||
|
out += "moo";
|
||||||
|
|
||||||
|
for (int i=3 ; i<word.length() ; i++)
|
||||||
|
out += "o";
|
||||||
|
|
||||||
|
out += " ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out += word + " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setMessage(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void updateText(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (!_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.getType() != UpdateType.SLOW)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Math.random() <= 0.99)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UtilTextMiddle.display("Moo", null, 5, 20, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void updateCow(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (!_enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event.getType() != UpdateType.FAST)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//Disguise
|
||||||
|
for (Player player : UtilServer.getPlayers())
|
||||||
|
{
|
||||||
|
if (_disguiseManager.getDisguise(player) != null)
|
||||||
|
{
|
||||||
|
//Moo
|
||||||
|
if (Math.random() > 0.8)
|
||||||
|
{
|
||||||
|
if (_disguiseManager.getDisguise(player) instanceof DisguiseCow)
|
||||||
|
{
|
||||||
|
player.getWorld().playSound(player.getLocation(), Sound.COW_IDLE, (float)Math.random() + 0.5f, (float)Math.random() + 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Disguise
|
||||||
|
DisguiseCow disguise = new DisguiseCow(player);
|
||||||
|
disguise.setName(getName(player), _clientManager.Get(player).GetRank());
|
||||||
|
disguise.setCustomNameVisible(true);
|
||||||
|
_disguiseManager.disguise(disguise);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive()
|
||||||
|
{
|
||||||
|
return _enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(Player player)
|
||||||
|
{
|
||||||
|
//Name
|
||||||
|
int index = 0;
|
||||||
|
boolean hitVowel = false;
|
||||||
|
for (int i=0 ; i<player.getName().length()-2 && i<5 ; i++)
|
||||||
|
{
|
||||||
|
//Detect vowel ;o
|
||||||
|
if (player.getName().toLowerCase().charAt(i) == 'a' ||
|
||||||
|
player.getName().toLowerCase().charAt(i) == 'e' ||
|
||||||
|
player.getName().toLowerCase().charAt(i) == 'i' ||
|
||||||
|
player.getName().toLowerCase().charAt(i) == 'o' ||
|
||||||
|
player.getName().toLowerCase().charAt(i) == 'u')
|
||||||
|
{
|
||||||
|
hitVowel = true;
|
||||||
|
}
|
||||||
|
//Post vowel consonant - stop here
|
||||||
|
else if (hitVowel)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index = i+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = "Moo" + player.getName().substring(index, player.getName().length());
|
||||||
|
|
||||||
|
if (name.length() > 16)
|
||||||
|
name = name.substring(0, 16);
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean b)
|
||||||
|
{
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
_enabled = b && (c.get(Calendar.MONTH) == Calendar.APRIL && c.get(Calendar.DAY_OF_MONTH) == 1);
|
||||||
|
}
|
||||||
|
}
|
@ -78,8 +78,8 @@ public class BenefitManager extends MiniDbClientPlugin<BenefitData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQuery(String uuid, String name)
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
{
|
{
|
||||||
return "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';";
|
return "SELECT benefit FROM rankBenefits WHERE rankBenefits.accountId = '" + accountId + "';";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package mineplex.core.benefit;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
|
|
||||||
@ -10,13 +11,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public class BenefitManagerRepository extends RepositoryBase
|
public class BenefitManagerRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
// private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));";
|
private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));";
|
||||||
|
|
||||||
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
|
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
|
||||||
|
|
||||||
public BenefitManagerRepository(JavaPlugin plugin)
|
public BenefitManagerRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,24 +7,23 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
|||||||
|
|
||||||
public final class DBPool
|
public final class DBPool
|
||||||
{
|
{
|
||||||
public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "root", "tAbechAk3wR7tuTh");
|
public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||||
public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "root", "tAbechAk3wR7tuTh");
|
public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||||
public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||||
public static final DataSource STATS_MINEPLEX = openDataSource("jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
public static final DataSource STATS_MINEPLEX = openDataSource("jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
private static DataSource openDataSource(String url, String username, String password)
|
private static DataSource openDataSource(String url, String username, String password)
|
||||||
{
|
{
|
||||||
BasicDataSource source = new BasicDataSource();
|
BasicDataSource source = new BasicDataSource();
|
||||||
source.addConnectionProperty("autoReconnect", "true");
|
source.addConnectionProperty("autoReconnect", "true");
|
||||||
source.setDefaultAutoCommit(true);
|
source.addConnectionProperty("allowMultiQueries", "true");
|
||||||
source.setEnableAutoCommitOnReturn(true);
|
source.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
||||||
source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
|
|
||||||
source.setDriverClassName("com.mysql.jdbc.Driver");
|
source.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
source.setUrl(url);
|
source.setUrl(url);
|
||||||
source.setUsername(username);
|
source.setUsername(username);
|
||||||
source.setPassword(password);
|
source.setPassword(password);
|
||||||
source.setMaxTotal(10);
|
source.setMaxTotal(4);
|
||||||
source.setMaxIdle(3);
|
source.setMaxIdle(4);
|
||||||
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
||||||
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package mineplex.core.database;
|
package mineplex.core.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.column.Column;
|
import mineplex.core.database.column.Column;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
@ -20,70 +21,72 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public abstract class RepositoryBase implements Listener
|
public abstract class RepositoryBase implements Listener
|
||||||
{
|
{
|
||||||
protected static Object _connectionLock = new Object();
|
// Queue for failed processes
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
private static Object _queueLock = new Object();
|
private static Object _queueLock = new Object();
|
||||||
|
|
||||||
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
||||||
|
|
||||||
private String _connectionString;
|
private DataSource _dataSource; // Connection pool
|
||||||
private String _userName;
|
protected JavaPlugin Plugin; // Plugin responsible for this repository
|
||||||
private String _password;
|
|
||||||
|
|
||||||
protected JavaPlugin Plugin;
|
/**
|
||||||
|
* Constructor
|
||||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
* @param plugin - the {@link JavaPlugin} module responsible for this repository.
|
||||||
|
* @param dataSource - the {@link DataSource} responsible for providing the connection pool to this repository.
|
||||||
|
*/
|
||||||
|
public RepositoryBase(JavaPlugin plugin, DataSource dataSource)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
|
_dataSource = dataSource;
|
||||||
_connectionString = connectionString;
|
|
||||||
_userName = username;
|
|
||||||
_password = password;
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
initialize();
|
||||||
{
|
update();
|
||||||
initialize();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initialize();
|
protected abstract void initialize();
|
||||||
|
|
||||||
protected abstract void update();
|
protected abstract void update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the {@link DataSource} used by the repository for connection pooling.
|
||||||
|
*/
|
||||||
|
protected DataSource getConnectionPool()
|
||||||
|
{
|
||||||
|
return _dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool!
|
||||||
|
* @see Connection#close()
|
||||||
|
* @return a newly fetched {@link Connection} from the connection pool, if a connection can be made, null otherwise.
|
||||||
|
*/
|
||||||
protected Connection getConnection()
|
protected Connection getConnection()
|
||||||
{
|
{
|
||||||
return getConnection(false);
|
try
|
||||||
}
|
|
||||||
|
|
||||||
protected Connection getConnection(boolean validate)
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
{
|
||||||
try
|
return _dataSource.getConnection();
|
||||||
{
|
}
|
||||||
if (_connection == null || (validate && !_connection.isValid(2)))
|
catch (SQLException e)
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
{
|
||||||
}
|
e.printStackTrace();
|
||||||
catch (SQLException e)
|
// TODO: Log connection failures?
|
||||||
{
|
return null;
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a query against the repository.
|
||||||
|
* @param query - the concatenated query to execute in string form.
|
||||||
|
* @param columns - the column data values used for insertion into the query.
|
||||||
|
* @return the number of rows affected by this query in the repository.
|
||||||
|
*/
|
||||||
protected int executeUpdate(String query, Column<?>...columns)
|
protected int executeUpdate(String query, Column<?>...columns)
|
||||||
{
|
{
|
||||||
return executeInsert(query, null, columns);
|
return executeInsert(query, null, columns);
|
||||||
@ -91,17 +94,14 @@ public abstract class RepositoryBase implements Listener
|
|||||||
|
|
||||||
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
|
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
// Automatic resource management for handling/closing objects.
|
||||||
|
try (
|
||||||
|
Connection connection = getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_connection == null)
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
for (int i=0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
{
|
{
|
||||||
columns[i].setValue(preparedStatement, i+1);
|
columns[i].setValue(preparedStatement, i+1);
|
||||||
@ -110,49 +110,24 @@ public abstract class RepositoryBase implements Listener
|
|||||||
affectedRows = preparedStatement.executeUpdate();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
|
|
||||||
if (callable != null)
|
if (callable != null)
|
||||||
|
{
|
||||||
callable.processResultSet(preparedStatement.getGeneratedKeys());
|
callable.processResultSet(preparedStatement.getGeneratedKeys());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
try
|
exception.printStackTrace();
|
||||||
{
|
|
||||||
if (!_connection.isValid(5))
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
executeInsert(query, callable, columns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i=0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
@ -160,129 +135,41 @@ public abstract class RepositoryBase implements Listener
|
|||||||
columns[i].setValue(statement, i+1);
|
columns[i].setValue(statement, i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
try (ResultSet resultSet = statement.executeQuery())
|
||||||
|
{
|
||||||
callable.processResultSet(resultSet);
|
callable.processResultSet(resultSet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
try
|
exception.printStackTrace();
|
||||||
{
|
|
||||||
if (!_connection.isValid(5))
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
executeQuery(statement, callable, columns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (resultSet != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
// Automatic resource management for handling/closing objects.
|
||||||
|
try (
|
||||||
try
|
Connection connection = getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (_connection == null)
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(query);
|
|
||||||
|
|
||||||
executeQuery(preparedStatement, callable, columns);
|
executeQuery(preparedStatement, callable, columns);
|
||||||
}
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
try
|
exception.printStackTrace();
|
||||||
{
|
|
||||||
if (!_connection.isValid(5))
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
executeQuery(query, callable, columns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
|
|
||||||
{
|
|
||||||
int affectedRows = 0;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (int i=0; i < columns.length; i++)
|
|
||||||
{
|
|
||||||
columns[i].setValue(preparedStatement, i+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
affectedRows = preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
catch (SQLException exception)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_connection.isValid(5))
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
executeUpdate(preparedStatement, columns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return affectedRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
||||||
{
|
{
|
||||||
Thread asyncThread = new Thread(new Runnable()
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
@ -325,32 +212,6 @@ public abstract class RepositoryBase implements Listener
|
|||||||
processFailedQueue();
|
processFailedQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void validateConnection(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.MIN_02)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Plugin, new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_connection == null || !_connection.isValid(5))
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processFailedQueue()
|
private void processFailedQueue()
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R4.Block;
|
import net.minecraft.server.v1_7_R4.Block;
|
||||||
@ -17,6 +18,7 @@ import net.minecraft.server.v1_7_R4.ChunkAddEntityEvent;
|
|||||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
||||||
import net.minecraft.server.v1_7_R4.Packet;
|
import net.minecraft.server.v1_7_R4.Packet;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutBed;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutBed;
|
||||||
|
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityStatus;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunk;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunk;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunkBulk;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunkBulk;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
||||||
@ -28,6 +30,7 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove;
|
|||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMoveLook;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMoveLook;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityTeleport;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityTeleport;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata;
|
||||||
|
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutUpdateAttributes;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutUpdateAttributes;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedSoundEffect;
|
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedSoundEffect;
|
||||||
@ -62,6 +65,7 @@ import mineplex.core.disguise.disguises.DisguiseBase;
|
|||||||
import mineplex.core.disguise.disguises.DisguiseBlock;
|
import mineplex.core.disguise.disguises.DisguiseBlock;
|
||||||
import mineplex.core.disguise.disguises.DisguiseInsentient;
|
import mineplex.core.disguise.disguises.DisguiseInsentient;
|
||||||
import mineplex.core.disguise.disguises.DisguisePlayer;
|
import mineplex.core.disguise.disguises.DisguisePlayer;
|
||||||
|
import mineplex.core.disguise.disguises.DisguiseRabbit;
|
||||||
import mineplex.core.packethandler.IPacketHandler;
|
import mineplex.core.packethandler.IPacketHandler;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
import mineplex.core.packethandler.PacketVerifier;
|
import mineplex.core.packethandler.PacketVerifier;
|
||||||
@ -80,6 +84,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
private NautHashMap<DisguiseBase, HashSet<Player>> _disguisePlayerMap = new NautHashMap<DisguiseBase, HashSet<Player>>();
|
private NautHashMap<DisguiseBase, HashSet<Player>> _disguisePlayerMap = new NautHashMap<DisguiseBase, HashSet<Player>>();
|
||||||
private HashSet<String> _blockedNames = new HashSet<String>();
|
private HashSet<String> _blockedNames = new HashSet<String>();
|
||||||
private NautHashMap<Integer, Entry<DisguiseBase, Player[]>> _futureDisguises = new NautHashMap<Integer, Entry<DisguiseBase, Player[]>>();
|
private NautHashMap<Integer, Entry<DisguiseBase, Player[]>> _futureDisguises = new NautHashMap<Integer, Entry<DisguiseBase, Player[]>>();
|
||||||
|
private NautHashMap<Integer, NautHashMap<Integer, Long>> _lastRabbitHop = new NautHashMap<Integer, NautHashMap<Integer, Long>>();
|
||||||
|
|
||||||
private boolean _handlingPacket = false;
|
private boolean _handlingPacket = false;
|
||||||
|
|
||||||
@ -93,6 +98,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
private Field _bedD;
|
private Field _bedD;
|
||||||
private Field _xChunk;
|
private Field _xChunk;
|
||||||
private Field _zChunk;
|
private Field _zChunk;
|
||||||
|
private Field _eStatusId;
|
||||||
|
private Field _eStatusState;
|
||||||
|
|
||||||
private Chunk _bedChunk;
|
private Chunk _bedChunk;
|
||||||
private boolean _bedPackets;
|
private boolean _bedPackets;
|
||||||
@ -121,6 +128,10 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
_bedB.setAccessible(true);
|
_bedB.setAccessible(true);
|
||||||
_bedD = PacketPlayOutBed.class.getDeclaredField("d");
|
_bedD = PacketPlayOutBed.class.getDeclaredField("d");
|
||||||
_bedD.setAccessible(true);
|
_bedD.setAccessible(true);
|
||||||
|
_eStatusId = PacketPlayOutEntityStatus.class.getDeclaredField("a");
|
||||||
|
_eStatusId.setAccessible(true);
|
||||||
|
_eStatusState = PacketPlayOutEntityStatus.class.getDeclaredField("b");
|
||||||
|
_eStatusState.setAccessible(true);
|
||||||
|
|
||||||
_bedChunk = new Chunk(null, 0, 0);
|
_bedChunk = new Chunk(null, 0, 0);
|
||||||
Field cSection = Chunk.class.getDeclaredField("sections");
|
Field cSection = Chunk.class.getDeclaredField("sections");
|
||||||
@ -221,6 +232,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
disguise.setEntity(event.GetEntity());
|
disguise.setEntity(event.GetEntity());
|
||||||
_spawnPacketMap.put(event.GetEntity().getEntityId(), disguise);
|
_spawnPacketMap.put(event.GetEntity().getEntityId(), disguise);
|
||||||
_entityDisguiseMap.remove(event.GetEntity().getUniqueId().toString());
|
_entityDisguiseMap.remove(event.GetEntity().getUniqueId().toString());
|
||||||
|
|
||||||
|
if (disguise instanceof DisguiseRabbit)
|
||||||
|
{
|
||||||
|
_lastRabbitHop.put(disguise.GetEntityId(), new NautHashMap<Integer, Long>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +341,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
{
|
{
|
||||||
_entityDisguiseMap.put(entity.getUniqueId().toString(), _spawnPacketMap.get(entity.getEntityId()));
|
_entityDisguiseMap.put(entity.getUniqueId().toString(), _spawnPacketMap.get(entity.getEntityId()));
|
||||||
_spawnPacketMap.remove(entity.getEntityId());
|
_spawnPacketMap.remove(entity.getEntityId());
|
||||||
|
_lastRabbitHop.remove(entity.getEntityId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,6 +391,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
_spawnPacketMap.put(disguise.GetEntityId(), disguise);
|
_spawnPacketMap.put(disguise.GetEntityId(), disguise);
|
||||||
_disguisePlayerMap.put(disguise, new HashSet<Player>());
|
_disguisePlayerMap.put(disguise, new HashSet<Player>());
|
||||||
|
|
||||||
|
if (disguise instanceof DisguiseRabbit)
|
||||||
|
{
|
||||||
|
_lastRabbitHop.put(disguise.GetEntityId(), new NautHashMap<Integer, Long>());
|
||||||
|
}
|
||||||
|
|
||||||
for (Player player : players)
|
for (Player player : players)
|
||||||
addViewerToDisguise(disguise, player, false);
|
addViewerToDisguise(disguise, player, false);
|
||||||
|
|
||||||
@ -513,6 +535,63 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
final Player owner = packetInfo.getPlayer();
|
final Player owner = packetInfo.getPlayer();
|
||||||
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
||||||
|
|
||||||
|
if (UtilPlayer.is1_8(owner)
|
||||||
|
&& (packet instanceof PacketPlayOutRelEntityMoveLook || packet instanceof PacketPlayOutRelEntityMove))
|
||||||
|
{
|
||||||
|
int entityId = -1;
|
||||||
|
|
||||||
|
if (packet instanceof PacketPlayOutRelEntityMoveLook)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutRelEntityMoveLook) packet).a;
|
||||||
|
}/*
|
||||||
|
else if (packet instanceof PacketPlayOutEntityLook)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutEntityLook) packet).a;
|
||||||
|
}*/
|
||||||
|
else if (packet instanceof PacketPlayOutRelEntityMove)
|
||||||
|
{
|
||||||
|
PacketPlayOutRelEntityMove rPacket = (PacketPlayOutRelEntityMove) packet;
|
||||||
|
|
||||||
|
if (rPacket.b != 0 || rPacket.c != 0 || rPacket.d != 0)
|
||||||
|
{
|
||||||
|
entityId = rPacket.a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*else if (packet instanceof PacketPlayOutEntityTeleport)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutEntityTeleport) packet).a;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (_lastRabbitHop.containsKey(entityId))
|
||||||
|
{
|
||||||
|
NautHashMap<Integer, Long> rabbitHops = _lastRabbitHop.get(entityId);
|
||||||
|
|
||||||
|
if (rabbitHops != null)
|
||||||
|
{
|
||||||
|
long last = rabbitHops.containsKey(owner.getEntityId()) ? System.currentTimeMillis()
|
||||||
|
- rabbitHops.get(owner.getEntityId()) : 1000;
|
||||||
|
|
||||||
|
if (last > 500 || last < 100)
|
||||||
|
{
|
||||||
|
rabbitHops.put(owner.getEntityId(), System.currentTimeMillis());
|
||||||
|
|
||||||
|
PacketPlayOutEntityStatus entityStatus = new PacketPlayOutEntityStatus();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_eStatusId.set(entityStatus, entityId);
|
||||||
|
_eStatusState.set(entityStatus, (byte) 1);
|
||||||
|
|
||||||
|
handlePacket(entityStatus, packetVerifier);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (packet instanceof PacketPlayOutPlayerInfo)
|
if (packet instanceof PacketPlayOutPlayerInfo)
|
||||||
{
|
{
|
||||||
if (_blockedNames.contains(((PacketPlayOutPlayerInfo) packet).username))
|
if (_blockedNames.contains(((PacketPlayOutPlayerInfo) packet).username))
|
||||||
@ -520,10 +599,23 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
packetInfo.setCancelled(true);
|
packetInfo.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (packet instanceof PacketPlayOutSpawnEntity || packet instanceof PacketPlayOutNamedEntitySpawn)
|
else if (packet instanceof PacketPlayOutSpawnEntity || packet instanceof PacketPlayOutSpawnEntityLiving
|
||||||
|
|| packet instanceof PacketPlayOutNamedEntitySpawn)
|
||||||
{
|
{
|
||||||
int entityId = packet instanceof PacketPlayOutSpawnEntity ? ((PacketPlayOutSpawnEntity) packet).a
|
int entityId = -1;
|
||||||
: ((PacketPlayOutNamedEntitySpawn) packet).a;
|
|
||||||
|
if (packet instanceof PacketPlayOutSpawnEntity)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutSpawnEntity) packet).a;
|
||||||
|
}
|
||||||
|
else if (packet instanceof PacketPlayOutSpawnEntityLiving)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutSpawnEntityLiving) packet).a;
|
||||||
|
}
|
||||||
|
else if (packet instanceof PacketPlayOutNamedEntitySpawn)
|
||||||
|
{
|
||||||
|
entityId = ((PacketPlayOutNamedEntitySpawn) packet).a;
|
||||||
|
}
|
||||||
|
|
||||||
if (_futureDisguises.containsKey(entityId))
|
if (_futureDisguises.containsKey(entityId))
|
||||||
{
|
{
|
||||||
@ -737,6 +829,12 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
private void handleSpawnPackets(PacketInfo packetInfo, DisguiseBase disguise)
|
private void handleSpawnPackets(PacketInfo packetInfo, DisguiseBase disguise)
|
||||||
{
|
{
|
||||||
final Player player = packetInfo.getPlayer();
|
final Player player = packetInfo.getPlayer();
|
||||||
|
|
||||||
|
if (!UtilPlayer.is1_8(player) && disguise instanceof DisguiseRabbit)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
final PacketVerifier packetVerifier = packetInfo.getVerifier();
|
||||||
|
|
||||||
if (disguise instanceof DisguisePlayer)
|
if (disguise instanceof DisguisePlayer)
|
||||||
@ -795,54 +893,12 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
{
|
{
|
||||||
_disguisePlayerMap.get(disguise).remove(event.getPlayer());
|
_disguisePlayerMap.get(disguise).remove(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*public void reApplyDisguise(final DisguiseBase disguise, final Player player)
|
for (Integer disguise : _lastRabbitHop.keySet())
|
||||||
{
|
|
||||||
PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(disguise.GetEntityId());
|
|
||||||
|
|
||||||
if (disguise.GetEntity() == ((CraftPlayer) player).getHandle())
|
|
||||||
return;
|
|
||||||
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
|
|
||||||
entityPlayer.playerConnection.sendPacket(destroyPacket);
|
|
||||||
|
|
||||||
List<Packet> tempArmor = new ArrayList<Packet>();
|
|
||||||
|
|
||||||
if (disguise instanceof DisguiseInsentient && disguise.GetEntity() instanceof LivingEntity)
|
|
||||||
{
|
{
|
||||||
if (((DisguiseInsentient) disguise).armorVisible())
|
_lastRabbitHop.get(disguise).remove(event.getPlayer().getEntityId());
|
||||||
{
|
|
||||||
for (Packet armorPacket : ((DisguiseInsentient) disguise).getArmorPackets())
|
|
||||||
tempArmor.add(armorPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
final List<Packet> armorPackets = tempArmor;
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
entityPlayer.playerConnection.sendPacket(disguise.GetSpawnPacket());
|
|
||||||
|
|
||||||
if (disguise instanceof DisguisePlayer && ((DisguisePlayer) disguise).getSleepingDirection() != null)
|
|
||||||
{
|
|
||||||
for (Packet packet : getBedPackets(player.getLocation(), (DisguisePlayer) disguise))
|
|
||||||
{
|
|
||||||
entityPlayer.playerConnection.sendPacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Packet packet : armorPackets)
|
|
||||||
{
|
|
||||||
entityPlayer.playerConnection.sendPacket(packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private void prepareChunk(Location loc)
|
private void prepareChunk(Location loc)
|
||||||
{
|
{
|
||||||
@ -1007,6 +1063,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
if (!_spawnPacketMap.containsKey(entity.getEntityId()))
|
if (!_spawnPacketMap.containsKey(entity.getEntityId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_lastRabbitHop.remove(entity.getEntityId());
|
||||||
DisguiseBase disguise = _spawnPacketMap.remove(entity.getEntityId());
|
DisguiseBase disguise = _spawnPacketMap.remove(entity.getEntityId());
|
||||||
Collection<? extends Player> players = (disguise.Global ? Bukkit.getOnlinePlayers() : _disguisePlayerMap.remove(disguise));
|
Collection<? extends Player> players = (disguise.Global ? Bukkit.getOnlinePlayers() : _disguisePlayerMap.remove(disguise));
|
||||||
|
|
||||||
@ -1054,4 +1111,34 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
|
|||||||
entityPlayer.playerConnection.sendPacket(disguise.GetMetaDataPacket());
|
entityPlayer.playerConnection.sendPacket(disguise.GetMetaDataPacket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void cleanDisguises(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.SLOWER || _disguisePlayerMap.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (Iterator<DisguiseBase> disguiseIterator = _disguisePlayerMap.keySet().iterator(); disguiseIterator.hasNext();)
|
||||||
|
{
|
||||||
|
DisguiseBase disguise = disguiseIterator.next();
|
||||||
|
|
||||||
|
if (!(disguise.GetEntity() instanceof EntityPlayer))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
EntityPlayer disguisedPlayer = (EntityPlayer)disguise.GetEntity();
|
||||||
|
|
||||||
|
if (Bukkit.getPlayerExact(disguisedPlayer.getName()) == null || !disguisedPlayer.isAlive() || !disguisedPlayer.valid)
|
||||||
|
disguiseIterator.remove();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (Iterator<Player> playerIterator = _disguisePlayerMap.get(disguise).iterator(); playerIterator.hasNext();)
|
||||||
|
{
|
||||||
|
Player player = playerIterator.next();
|
||||||
|
|
||||||
|
if (!player.isOnline() || !player.isValid())
|
||||||
|
playerIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package mineplex.core.disguise.disguises;
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||||
@ -31,7 +33,11 @@ public class DisguisePlayer extends DisguiseHuman
|
|||||||
|
|
||||||
public void setProfile(GameProfile profile)
|
public void setProfile(GameProfile profile)
|
||||||
{
|
{
|
||||||
_profile = profile;
|
GameProfile newProfile = new GameProfile(UUID.randomUUID(), profile.getName());
|
||||||
|
|
||||||
|
newProfile.getProperties().putAll(profile.getProperties());
|
||||||
|
|
||||||
|
_profile = newProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockFace getSleepingDirection()
|
public BlockFace getSleepingDirection()
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package mineplex.core.disguise.disguises;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_7_R4.EnumEntitySize;
|
||||||
|
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||||
|
import net.minecraft.server.v1_7_R4.Packet;
|
||||||
|
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
|
||||||
|
|
||||||
|
public class DisguiseRabbit extends DisguiseInsentient
|
||||||
|
{
|
||||||
|
|
||||||
|
public DisguiseRabbit(org.bukkit.entity.Entity entity)
|
||||||
|
{
|
||||||
|
super(entity);
|
||||||
|
|
||||||
|
DataWatcher.a(4, Byte.valueOf((byte) 0));
|
||||||
|
|
||||||
|
DataWatcher.a(12, (byte) 0);
|
||||||
|
DataWatcher.a(15, Byte.valueOf((byte) 0));
|
||||||
|
DataWatcher.a(18, Byte.valueOf((byte) 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet GetSpawnPacket()
|
||||||
|
{
|
||||||
|
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
|
||||||
|
packet.a = Entity.getId();
|
||||||
|
packet.b = (byte) 101;
|
||||||
|
packet.c = (int) EnumEntitySize.SIZE_2.a(Entity.locX);
|
||||||
|
packet.d = (int) MathHelper.floor(Entity.locY * 32.0D);
|
||||||
|
packet.e = (int) EnumEntitySize.SIZE_2.a(Entity.locZ);
|
||||||
|
packet.i = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
|
||||||
|
packet.j = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
|
||||||
|
packet.k = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
|
||||||
|
|
||||||
|
double var2 = 3.9D;
|
||||||
|
double var4 = 0;
|
||||||
|
double var6 = 0;
|
||||||
|
double var8 = 0;
|
||||||
|
|
||||||
|
if (var4 < -var2)
|
||||||
|
{
|
||||||
|
var4 = -var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var6 < -var2)
|
||||||
|
{
|
||||||
|
var6 = -var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var8 < -var2)
|
||||||
|
{
|
||||||
|
var8 = -var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var4 > var2)
|
||||||
|
{
|
||||||
|
var4 = var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var6 > var2)
|
||||||
|
{
|
||||||
|
var6 = var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var8 > var2)
|
||||||
|
{
|
||||||
|
var8 = var2;
|
||||||
|
}
|
||||||
|
|
||||||
|
packet.f = (int) (var4 * 8000.0D);
|
||||||
|
packet.g = (int) (var6 * 8000.0D);
|
||||||
|
packet.h = (int) (var8 * 8000.0D);
|
||||||
|
|
||||||
|
packet.l = DataWatcher;
|
||||||
|
packet.m = DataWatcher.b();
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.command.CommandBase;
|
import mineplex.core.command.CommandBase;
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
@ -27,34 +28,39 @@ public class CoinCommand extends CommandBase<DonationManager>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetName = args[0];
|
final String targetName = args[0];
|
||||||
String coinsString = args[1];
|
final String coinsString = args[1];
|
||||||
Player target = UtilPlayer.searchExact(targetName);
|
Player target = UtilPlayer.searchExact(targetName);
|
||||||
|
|
||||||
if (target == null)
|
if (target == null)
|
||||||
{
|
{
|
||||||
UUID uuid = UUIDFetcher.getUUIDOf(targetName);
|
Plugin.getClientManager().loadClientByName(targetName, new Runnable()
|
||||||
if (uuid != null)
|
|
||||||
{
|
{
|
||||||
rewardCoins(caller, null, targetName, uuid, coinsString);
|
public void run()
|
||||||
}
|
{
|
||||||
else
|
CoreClient client = Plugin.getClientManager().Get(targetName);
|
||||||
{
|
|
||||||
UtilPlayer.message(caller, F.main("Coin", "Could not find player " + F.name(targetName)));
|
if (client != null)
|
||||||
}
|
rewardCoins(caller, null, targetName, client.getAccountId(), coinsString);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Coin", "Could not find player " + F.name(targetName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rewardCoins(caller, target, target.getName(), target.getUniqueId(), coinsString);
|
rewardCoins(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), coinsString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, String coinsString)
|
private void rewardCoins(final Player caller, final Player target, final String targetName, final int accountId, String coinsString)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int coins = Integer.parseInt(coinsString);
|
int coins = Integer.parseInt(coinsString);
|
||||||
rewardCoins(caller, target, targetName, uuid, coins);
|
rewardCoins(caller, target, targetName, accountId, coins);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -62,7 +68,7 @@ public class CoinCommand extends CommandBase<DonationManager>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, final int coins)
|
private void rewardCoins(final Player caller, final Player target, final String targetName, final int accountId, final int coins)
|
||||||
{
|
{
|
||||||
Plugin.RewardCoins(new Callback<Boolean>()
|
Plugin.RewardCoins(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
@ -75,6 +81,6 @@ public class CoinCommand extends CommandBase<DonationManager>
|
|||||||
UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + "."));
|
UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, caller.getName(), targetName, uuid, coins);
|
}, caller.getName(), targetName, accountId, coins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
|
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase)
|
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase)
|
||||||
{
|
{
|
||||||
final Donor donor = Bukkit.getPlayerExact(name) != null ? Get(name) : null;
|
final Donor donor = Bukkit.getPlayerExact(name) != null ? Get(name) : null;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.run(response);
|
callback.run(response);
|
||||||
}
|
}
|
||||||
}, name, uuid.toString(), packageName, coinPurchase, cost);
|
}, name, accountId, packageName, coinPurchase, cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final int cost, final int salesPackageId)
|
public void PurchaseKnownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final int cost, final int salesPackageId)
|
||||||
@ -196,12 +196,12 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
_gemQueue.clear();
|
_gemQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardCoins(Callback<Boolean> callback, String caller, String name, UUID uuid, int amount)
|
public void RewardCoins(Callback<Boolean> callback, String caller, String name, int accountId, int amount)
|
||||||
{
|
{
|
||||||
RewardCoins(callback, caller, name, uuid, amount, true);
|
RewardCoins(callback, caller, name, accountId, amount, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardCoins(final Callback<Boolean> callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal)
|
public void RewardCoins(final Callback<Boolean> callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal)
|
||||||
{
|
{
|
||||||
_repository.rewardCoins(new Callback<Boolean>()
|
_repository.rewardCoins(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
@ -223,7 +223,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
callback.run(true);
|
callback.run(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, caller, name, uuid.toString(), amount);
|
}, caller, name, accountId, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardCoinsLater(final String caller, final Player player, final int amount)
|
public void RewardCoinsLater(final String caller, final Player player, final int amount)
|
||||||
@ -251,22 +251,35 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
if (event.getType() != UpdateType.SLOWER)
|
if (event.getType() != UpdateType.SLOWER)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Player player : _coinQueue.keySet())
|
for (final Player player : _coinQueue.keySet())
|
||||||
{
|
{
|
||||||
String caller = null;
|
String tempCaller = null;
|
||||||
int total = 0;
|
int tempTotal = 0;
|
||||||
|
|
||||||
for (String curCaller : _coinQueue.get(player).keySet())
|
for (String curCaller : _coinQueue.get(player).keySet())
|
||||||
{
|
{
|
||||||
caller = curCaller;
|
tempCaller = curCaller;
|
||||||
total += _coinQueue.get(player).get(curCaller);
|
tempTotal += _coinQueue.get(player).get(curCaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int total = tempTotal;
|
||||||
|
final String caller = tempCaller;
|
||||||
|
|
||||||
if (caller == null)
|
if (caller == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Actually Add Gems
|
if (player.isOnline() && player.isValid())
|
||||||
RewardCoins(null, caller, player.getName(), player.getUniqueId(), total, false);
|
RewardCoins(null, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
RewardCoins(null, caller, player.getName(), ClientManager.getCachedClientAccountId(player.getUniqueId()), total, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Queue Added [" + player + "] with Coins [" + total + "] for [" + caller + "]");
|
System.out.println("Queue Added [" + player + "] with Coins [" + total + "] for [" + caller + "]");
|
||||||
|
|
||||||
@ -278,12 +291,12 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
_coinQueue.clear();
|
_coinQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardGold(Callback<Boolean> callback, String caller, String name, UUID uuid, int amount)
|
public void RewardGold(Callback<Boolean> callback, String caller, String name, int accountId, int amount)
|
||||||
{
|
{
|
||||||
RewardGold(callback, caller, name, uuid, amount, true);
|
RewardGold(callback, caller, name, accountId, amount, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardGold(final Callback<Boolean> callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal)
|
public void RewardGold(final Callback<Boolean> callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal)
|
||||||
{
|
{
|
||||||
_repository.rewardGold(new Callback<Boolean>()
|
_repository.rewardGold(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
@ -309,7 +322,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.run(true);
|
callback.run(true);
|
||||||
}
|
}
|
||||||
}, caller, name, uuid.toString(), amount);
|
}, caller, name, accountId, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RewardGoldLater(final String caller, final Player player, final int amount)
|
public void RewardGoldLater(final String caller, final Player player, final int amount)
|
||||||
@ -352,7 +365,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Actually Add Gold
|
//Actually Add Gold
|
||||||
RewardGold(null, caller, player.getName(), player.getUniqueId(), total, false);
|
RewardGold(null, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false);
|
||||||
|
|
||||||
System.out.println("Queue Added [" + player + "] with Gold [" + total + "] for [" + caller + "]");
|
System.out.println("Queue Added [" + player + "] with Gold [" + total + "] for [" + caller + "]");
|
||||||
|
|
||||||
@ -375,15 +388,15 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
|||||||
Get(playerName).addGold(_repository.retrieveDonorInfo(resultSet).getGold());
|
Get(playerName).addGold(_repository.retrieveDonorInfo(resultSet).getGold());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getQuery(String uuid, String name)
|
|
||||||
{
|
|
||||||
return "SELECT gold FROM accounts WHERE uuid = '" + uuid + "';";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Donor AddPlayer(String player)
|
protected Donor AddPlayer(String player)
|
||||||
{
|
{
|
||||||
return new Donor();
|
return new Donor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
|
{
|
||||||
|
return "SELECT gold FROM accounts WHERE id = '" + accountId + "';";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.command.CommandBase;
|
import mineplex.core.command.CommandBase;
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
@ -31,34 +32,39 @@ public class GoldCommand extends CommandBase<DonationManager>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetName = args[0];
|
final String targetName = args[0];
|
||||||
String goldString = args[1];
|
final String goldString = args[1];
|
||||||
Player target = UtilPlayer.searchExact(targetName);
|
Player target = UtilPlayer.searchExact(targetName);
|
||||||
|
|
||||||
if (target == null)
|
if (target == null)
|
||||||
{
|
{
|
||||||
UUID uuid = UUIDFetcher.getUUIDOf(targetName);
|
Plugin.getClientManager().loadClientByName(targetName, new Runnable()
|
||||||
if (uuid != null)
|
|
||||||
{
|
{
|
||||||
rewardGold(caller, null, targetName, uuid, goldString);
|
public void run()
|
||||||
}
|
{
|
||||||
else
|
CoreClient client = Plugin.getClientManager().Get(targetName);
|
||||||
{
|
|
||||||
UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName)));
|
if (client != null)
|
||||||
}
|
rewardGold(caller, null, targetName, client.getAccountId(), goldString);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rewardGold(caller, target, target.getName(), target.getUniqueId(), goldString);
|
rewardGold(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), goldString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, String goldString)
|
private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, String goldString)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int gold = Integer.parseInt(goldString);
|
int gold = Integer.parseInt(goldString);
|
||||||
rewardGold(caller, target, targetName, uuid, gold);
|
rewardGold(caller, target, targetName, accountId, gold);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -66,7 +72,7 @@ public class GoldCommand extends CommandBase<DonationManager>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, final int gold)
|
private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold)
|
||||||
{
|
{
|
||||||
Plugin.RewardGold(new Callback<Boolean>()
|
Plugin.RewardGold(new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
@ -79,6 +85,6 @@ public class GoldCommand extends CommandBase<DonationManager>
|
|||||||
UtilPlayer.message(target, F.main("Gold", F.name(caller.getName()) + " gave you " + F.elem(gold + " Gold") + "."));
|
UtilPlayer.message(target, F.main("Gold", F.name(caller.getName()) + " gave you " + F.elem(gold + " Gold") + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, caller.getName(), targetName, uuid, gold);
|
}, caller.getName(), targetName, accountId, gold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package mineplex.core.donation.repository;
|
|||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -22,18 +22,18 @@ import mineplex.core.server.util.TransactionResponse;
|
|||||||
|
|
||||||
public class DonationRepository extends RepositoryBase
|
public class DonationRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX coinUuidIndex (accounts_uuid));";
|
private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
|
||||||
private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX gemUuidIndex (accounts_uuid));";
|
private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
|
||||||
private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accounts_uuid, reason, coins) VALUES(?, ?, ?);";
|
private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);";
|
||||||
private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE uuid = ?;";
|
private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;";
|
||||||
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE uuid = ?;";
|
private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;";
|
||||||
private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE uuid = ? AND gems IS NULL AND coins IS NULL;";
|
private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;";
|
||||||
|
|
||||||
private String _webAddress;
|
private String _webAddress;
|
||||||
|
|
||||||
public DonationRepository(JavaPlugin plugin, String webAddress)
|
public DonationRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ public class DonationRepository extends RepositoryBase
|
|||||||
}), "Error purchasing known sales package in DonationRepository : ");
|
}), "Error purchasing known sales package in DonationRepository : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final String uuid, final String packageName, final boolean coinPurchase, final int cost)
|
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost)
|
||||||
{
|
{
|
||||||
final UnknownPurchaseToken token = new UnknownPurchaseToken();
|
final UnknownPurchaseToken token = new UnknownPurchaseToken();
|
||||||
token.AccountName = name;
|
token.AccountName = name;
|
||||||
@ -86,8 +86,8 @@ public class DonationRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
if (coinPurchase)
|
if (coinPurchase)
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnVarChar("uuid", 100, uuid));
|
executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnInt("id", accountId));
|
||||||
executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost));
|
//executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ public class DonationRepository extends RepositoryBase
|
|||||||
}), "Error updating player gem amount in DonationRepository : ");
|
}), "Error updating player gem amount in DonationRepository : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rewardCoins(final Callback<Boolean> callback, final String giver, String name, final String uuid, final int coins)
|
public void rewardCoins(final Callback<Boolean> callback, final String giver, String name, final int accountId, final int coins)
|
||||||
{
|
{
|
||||||
final GemRewardToken token = new GemRewardToken();
|
final GemRewardToken token = new GemRewardToken();
|
||||||
token.Source = giver;
|
token.Source = giver;
|
||||||
@ -155,8 +155,8 @@ public class DonationRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
if (response)
|
if (response)
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, uuid));
|
executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnInt("id", accountId));
|
||||||
executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins));
|
//executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
|
||||||
@ -179,13 +179,13 @@ public class DonationRepository extends RepositoryBase
|
|||||||
}), "Error updating player coin amount in DonationRepository : ");
|
}), "Error updating player coin amount in DonationRepository : ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rewardGold(final Callback<Boolean> callback, final String giver, final String name, final String uuid, final int gold)
|
public void rewardGold(final Callback<Boolean> callback, final String giver, final String name, final int accountId, final int gold)
|
||||||
{
|
{
|
||||||
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1)
|
if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) < 1)
|
||||||
{
|
{
|
||||||
callback.run(false);
|
callback.run(false);
|
||||||
}
|
}
|
||||||
@ -207,13 +207,13 @@ public class DonationRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateGemsAndCoins(final UUID uuid, final int gems, final int coins)
|
public void updateGemsAndCoins(final int accountId, final int gems, final int coins)
|
||||||
{
|
{
|
||||||
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_, new ColumnInt("gems", gems), new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, uuid.toString()));
|
executeUpdate(UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_, new ColumnInt("gems", gems), new ColumnInt("coins", coins), new ColumnInt("id", accountId));
|
||||||
}
|
}
|
||||||
}), "Error updating player's null gems and coins DonationRepository : ");
|
}), "Error updating player's null gems and coins DonationRepository : ");
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQuery(String uuid, String name)
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
{
|
{
|
||||||
return "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';";
|
return "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';";
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -16,7 +17,7 @@ public class EloRepository extends RepositoryBase
|
|||||||
|
|
||||||
public EloRepository(JavaPlugin plugin)
|
public EloRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
@ -407,9 +407,9 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getQuery(String uuid, String name)
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
{
|
{
|
||||||
return "SELECT tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = '"
|
return "SELECT tA.Name, status, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget WHERE uuidSource = '"
|
||||||
+ uuid + "';";
|
+ uuid + "';";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user