diff --git a/Patches/CraftBukkit-Patches/0171-Add-IEntitySelector-have-isGhost-return-the-same-as-.patch b/Patches/CraftBukkit-Patches/0171-Add-IEntitySelector-have-isGhost-return-the-same-as-.patch new file mode 100644 index 000000000..a6166c4bd --- /dev/null +++ b/Patches/CraftBukkit-Patches/0171-Add-IEntitySelector-have-isGhost-return-the-same-as-.patch @@ -0,0 +1,119 @@ +From cddf775b575f0db92e478c858283869ac0b9bdc2 Mon Sep 17 00:00:00 2001 +From: libraryaddict +Date: Mon, 9 Nov 2015 00:07:26 +1300 +Subject: [PATCH] Add IEntitySelector, have isGhost() return the same as + isSpectator() + + +diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java +new file mode 100644 +index 0000000..1536600 +--- /dev/null ++++ b/src/main/java/net/minecraft/server/IEntitySelector.java +@@ -0,0 +1,103 @@ ++package net.minecraft.server; ++ ++import com.google.common.base.Predicate; ++ ++public final class IEntitySelector ++{ ++ public static class EntitySelectorEquipable ++ implements Predicate ++ { ++ ++ public boolean a(Entity entity) ++ { ++ if(!entity.isAlive()) ++ return false; ++ if(!(entity instanceof EntityLiving)) ++ return false; ++ EntityLiving entityliving = (EntityLiving)entity; ++ if(entityliving.getEquipment(EntityInsentient.c(a)) != null) ++ return false; ++ if(entityliving instanceof EntityInsentient) ++ return ((EntityInsentient)entityliving).bY(); ++ if(entityliving instanceof EntityArmorStand) ++ return true; ++ return entityliving instanceof EntityHuman; ++ } ++ ++ public boolean apply(Object obj) ++ { ++ return a((Entity)obj); ++ } ++ ++ private final ItemStack a; ++ ++ public EntitySelectorEquipable(ItemStack itemstack) ++ { ++ a = itemstack; ++ } ++ } ++ ++ ++ public static final Predicate a = new Predicate() { ++ ++ public boolean a(Entity entity) ++ { ++ return entity.isAlive(); ++ } ++ ++ public boolean apply(Object obj) ++ { ++ return a((Entity)obj); ++ } ++ ++ } ++; ++ public static final Predicate b = new Predicate() { ++ ++ public boolean a(Entity entity) ++ { ++ return entity.isAlive() && entity.passenger == null && entity.vehicle == null; ++ } ++ ++ public boolean apply(Object obj) ++ { ++ return a((Entity)obj); ++ } ++ ++ } ++; ++ public static final Predicate c = new Predicate() { ++ ++ public boolean a(Entity entity) ++ { ++ return (entity instanceof IInventory) && entity.isAlive(); ++ } ++ ++ public boolean apply(Object obj) ++ { ++ return a((Entity)obj); ++ } ++ ++ } ++; ++ public static final Predicate d = new Predicate() { ++ ++ public boolean a(Entity entity) ++ { ++ if (entity instanceof EntityLiving && ((EntityLiving) entity).isGhost()) ++ { ++ return false; ++ } ++ ++ return !(entity instanceof EntityHuman) || !((EntityHuman)entity).isSpectator(); ++ } ++ ++ public boolean apply(Object obj) ++ { ++ return a((Entity)obj); ++ } ++ ++ } ++; ++ ++} +-- +1.9.5.msysgit.0 + diff --git a/Patches/CraftBukkit-Patches/0172-Add-player-spectator.patch b/Patches/CraftBukkit-Patches/0172-Add-player-spectator.patch new file mode 100644 index 000000000..585ef7b7a --- /dev/null +++ b/Patches/CraftBukkit-Patches/0172-Add-player-spectator.patch @@ -0,0 +1,22 @@ +From e81762b9aa4f28474b2ccd06ae6ad5b7c840e1ba Mon Sep 17 00:00:00 2001 +From: libraryaddict +Date: Mon, 9 Nov 2015 00:13:21 +1300 +Subject: [PATCH] Add player spectator + + +diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java +index 1536600..f86cf48 100644 +--- a/src/main/java/net/minecraft/server/IEntitySelector.java ++++ b/src/main/java/net/minecraft/server/IEntitySelector.java +@@ -89,7 +89,7 @@ public final class IEntitySelector + return false; + } + +- return !(entity instanceof EntityHuman) || !((EntityHuman)entity).isSpectator(); ++ return !(entity instanceof EntityHuman) || !(((EntityHuman)entity).isSpectator() && !((EntityPlayer)entity).spectating); + } + + public boolean apply(Object obj) +-- +1.9.5.msysgit.0 + diff --git a/Patches/CraftBukkit-Patches/0173-Fixed-ai-typo.patch b/Patches/CraftBukkit-Patches/0173-Fixed-ai-typo.patch new file mode 100644 index 000000000..b6fd20b9d --- /dev/null +++ b/Patches/CraftBukkit-Patches/0173-Fixed-ai-typo.patch @@ -0,0 +1,22 @@ +From 5dac54f90504022449cbd5ea23e5306f17523fe2 Mon Sep 17 00:00:00 2001 +From: libraryaddict +Date: Mon, 9 Nov 2015 02:41:31 +1300 +Subject: [PATCH] Fixed ai typo + + +diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java +index f86cf48..b4d70ad 100644 +--- a/src/main/java/net/minecraft/server/IEntitySelector.java ++++ b/src/main/java/net/minecraft/server/IEntitySelector.java +@@ -89,7 +89,7 @@ public final class IEntitySelector + return false; + } + +- return !(entity instanceof EntityHuman) || !(((EntityHuman)entity).isSpectator() && !((EntityPlayer)entity).spectating); ++ return !(entity instanceof EntityHuman) || !(((EntityHuman)entity).isSpectator() || ((EntityPlayer)entity).spectating); + } + + public boolean apply(Object obj) +-- +1.9.5.msysgit.0 + diff --git a/Plugins/BuildFiles/EnjinTranslator.xml b/Plugins/BuildFiles/EnjinTranslator.xml index bf3c1fb4a..6cd7bf62d 100644 --- a/Plugins/BuildFiles/EnjinTranslator.xml +++ b/Plugins/BuildFiles/EnjinTranslator.xml @@ -11,6 +11,9 @@ + + + diff --git a/Plugins/Libraries/craftbukkit.jar b/Plugins/Libraries/craftbukkit.jar index 7592e0d0b..33fd74aa0 100644 Binary files a/Plugins/Libraries/craftbukkit.jar and b/Plugins/Libraries/craftbukkit.jar differ diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index 443dc104b..fadc89543 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -81,7 +81,7 @@ public class LobbyBalancer implements Listener, Runnable InetSocketAddress socketAddress = new InetSocketAddress(server.getPublicAddress(), server.getPort()); _plugin.getProxy().getServers().put(server.getName(), _plugin.getProxy().constructServerInfo(server.getName(), socketAddress, "LobbyBalancer", false)); - if (server.getName().toUpperCase().contains("LOBBY")) + if (server.getName().toUpperCase().startsWith("LOBBY")) { if (server.getMotd() == null || !server.getMotd().contains("Restarting")) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 511c9b08f..73138c191 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -31,6 +31,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerQuitEvent; @@ -201,9 +202,10 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook PacketPlayOutSpawnEntityLiving spawnPacket = (PacketPlayOutSpawnEntityLiving) packet; // Ignore Armor stand packets - if (spawnPacket.b == 30 || spawnPacket.l == null || spawnPacket.l.c() == null || spawnPacket.a == 777777) + if (spawnPacket.b == EntityType.ARMOR_STAND.getTypeId() || spawnPacket.l == null || spawnPacket.l.c() == null + || spawnPacket.a == 777777) { - if (spawnPacket.b == 30) + if (spawnPacket.b == EntityType.ARMOR_STAND.getTypeId()) { _ignoreSkulls.add(spawnPacket.a); } @@ -215,27 +217,30 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte) watchable.b()) == 1) { - final String entityName = spawnPacket.l.getString(2); - - if (entityName.isEmpty()) - { - _entityNameMap.get(owner.getName()).remove(spawnPacket.a); - return; - } - if (_entityMap.get(owner.getName()).containsKey(spawnPacket.a)) { UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[] { _entityMap.get(owner.getName()).get(spawnPacket.a) })); + + _entityNameMap.get(owner.getName()).remove(spawnPacket.a); + _entityMap.get(owner.getName()).remove(spawnPacket.a); + } + + final String entityName = spawnPacket.l.getString(2); + + if (entityName.isEmpty()) + { + return; } int newId = UtilEnt.getNewEntityId(); - sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier); - _entityMap.get(owner.getName()).put(spawnPacket.a, newId); - _entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName); + _entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName); + _entityMap.get(owner.getName()).put(spawnPacket.a, newId); + + sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true); break; } } @@ -244,34 +249,67 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { PacketPlayOutEntityMetadata metaPacket = (PacketPlayOutEntityMetadata) packet; - if (!_entityMap.get(owner.getName()).containsKey(metaPacket.a) && metaPacket.a != 777777 - && !_ignoreSkulls.contains(metaPacket.a)) + if (metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a)) { - String entityName = ""; - boolean nameShowing = false; + boolean isDisplaying = _entityMap.get(owner.getName()).containsKey(metaPacket.a); + String currentName = _entityNameMap.get(owner.getName()).get(metaPacket.a); + + if (currentName == null) + { + currentName = ""; + } + + String newName = currentName; + boolean newDisplay = isDisplaying; for (WatchableObject watchable : (List) metaPacket.b) { - if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte) watchable.b()) == 1) + if (watchable.a() == 3 && watchable.b() instanceof Byte) { - nameShowing = true; + newDisplay = ((Byte) watchable.b()) == 1; } + if (watchable.a() == 2 && watchable.b() instanceof String) { - entityName = (String) watchable.b(); + newName = (String) watchable.b(); } } - if (nameShowing && !entityName.isEmpty()) + // If the name has changed and the name should be showing, or the name display status has changed. + if ((!newName.equals(currentName) && newDisplay) || newDisplay != isDisplaying) { - int newId = UtilEnt.getNewEntityId(); - sendProtocolPackets(owner, metaPacket.a, newId, entityName, verifier); - _entityMap.get(owner.getName()).put(metaPacket.a, newId); - _entityNameMap.get(owner.getName()).put(metaPacket.a, entityName); - } - else if (!entityName.isEmpty()) - { - _entityNameMap.get(owner.getName()).remove(metaPacket.a); + // If name is still being displayed + if (newDisplay) + { + int newId; + + if (isDisplaying) // Sending metadata + { + newId = _entityMap.get(owner.getName()).get(metaPacket.a); + } + else + // Spawning new entity + { + newId = UtilEnt.getNewEntityId(); + _entityMap.get(owner.getName()).put(metaPacket.a, newId); + } + + sendProtocolPackets(owner, metaPacket.a, newId, newName, verifier, !isDisplaying); + + _entityNameMap.get(owner.getName()).put(metaPacket.a, newName); + } + else + { // Lets delete it + int id = _entityMap.get(owner.getName()).get(metaPacket.a); + + UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[] + { + id + })); + + _entityMap.get(owner.getName()).remove(metaPacket.a); + _entityNameMap.get(owner.getName()).remove(metaPacket.a); + } } } } @@ -330,7 +368,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook } private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName, - final PacketVerifier packetList) + final PacketVerifier packetList, final boolean newPacket) { CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName); _plugin.getServer().getPluginManager().callEvent(event); @@ -340,55 +378,6 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook { public void run() { - final PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); - spawnPacket.a = newEntityId; - spawnPacket.b = (byte) 30; - spawnPacket.c = (int) MathHelper.floor(100 * 32); - spawnPacket.d = (int) MathHelper.floor(64 * 32.0D); - spawnPacket.e = (int) MathHelper.floor(100 * 32); - spawnPacket.i = (byte) ((int) (0 * 256.0F / 360.0F)); - spawnPacket.j = (byte) ((int) (0 * 256.0F / 360.0F)); - spawnPacket.k = (byte) ((int) (0 * 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; - } - - spawnPacket.f = (int) (var4 * 8000.0D); - spawnPacket.g = (int) (var6 * 8000.0D); - spawnPacket.h = (int) (var8 * 8000.0D); - final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle())); watcher.a(0, Byte.valueOf((byte) 0)); @@ -415,16 +404,76 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook watcher.watch(2, finalEntityName); watcher.watch(3, Byte.valueOf((byte) 1)); - spawnPacket.l = watcher; + if (newPacket) + { + final PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(); + spawnPacket.a = newEntityId; + spawnPacket.b = (byte) 30; + spawnPacket.c = (int) MathHelper.floor(100 * 32); + spawnPacket.d = (int) MathHelper.floor(64 * 32.0D); + spawnPacket.e = (int) MathHelper.floor(100 * 32); + spawnPacket.i = (byte) ((int) (0 * 256.0F / 360.0F)); + spawnPacket.j = (byte) ((int) (0 * 256.0F / 360.0F)); + spawnPacket.k = (byte) ((int) (0 * 256.0F / 360.0F)); - UtilPlayer.sendPacket(owner, spawnPacket); + double var2 = 3.9D; + double var4 = 0; + double var6 = 0; + double var8 = 0; - PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); - vehiclePacket.a = 0; - vehiclePacket.b = spawnPacket.a; - vehiclePacket.c = entityId; + if (var4 < -var2) + { + var4 = -var2; + } - UtilPlayer.sendPacket(owner, vehiclePacket); + 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; + } + + spawnPacket.f = (int) (var4 * 8000.0D); + spawnPacket.g = (int) (var6 * 8000.0D); + spawnPacket.h = (int) (var8 * 8000.0D); + + spawnPacket.l = watcher; + + UtilPlayer.sendPacket(owner, spawnPacket); + + PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity(); + vehiclePacket.a = 0; + vehiclePacket.b = spawnPacket.a; + vehiclePacket.c = entityId; + + UtilPlayer.sendPacket(owner, vehiclePacket); + } + else + { + PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); + entityMetadata.a = newEntityId; + entityMetadata.b = watcher.c(); + + packetList.bypassProcess(entityMetadata); + } } }); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 22ac718f7..5c07e698c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -426,6 +426,25 @@ public class CoreClientManager extends MiniPlugin }, name, uuid, rank, perm); } + public void SaveRank(final Callback callback, final String name, final UUID uuid, Rank rank, boolean perm) + { + _repository.saveRank(new Callback() + { + public void run(Rank newRank) + { + if (_plugin.getServer().getPlayer(name) != null) + { + CoreClient client = Get(name); + + client.SetRank(newRank, false); + } + + if (callback != null) + callback.run(newRank); + } + }, name, uuid, rank, perm); + } + public void checkPlayerNameExact(final Callback callback, final String playerName) { _repository.matchPlayerName(new Callback>() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java index eb8817526..2d6eeeca4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java @@ -4,15 +4,17 @@ public class Giveaway { private int _id; private String _name; + private String _prettyName; private String _header; private String _message; private boolean _notifyNetwork; private int _notifyCooldown; - public Giveaway(int id, String name, String header, String message, boolean notifyNetwork, int notifyCooldown) + public Giveaway(int id, String name, String prettyName, String header, String message, boolean notifyNetwork, int notifyCooldown) { _id = id; _name = name; + _prettyName = prettyName; _header = header; _message = message; _notifyNetwork = notifyNetwork; @@ -29,6 +31,11 @@ public class Giveaway return _name; } + public String getPrettyName() + { + return _prettyName; + } + public String getMessage() { return _message; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java index 0ad5344f5..bfcfa4981 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java @@ -1,30 +1,43 @@ package mineplex.core.giveaway; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; import java.util.UUID; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.MiniDbClientPlugin; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.giveaway.redis.GiveawayMessage; import mineplex.core.giveaway.redis.GiveawayMessageHandler; +import mineplex.core.status.ServerStatusManager; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; import mineplex.serverdata.commands.ServerCommandManager; -public class GiveawayManager extends MiniPlugin +public class GiveawayManager extends MiniDbClientPlugin { private CoreClientManager _clientManager; + private ServerStatusManager _statusManager; private GiveawayRepository _repository; private HashMap _giveawayMap; private HashMap _cooldownMap; - public GiveawayManager(JavaPlugin plugin, CoreClientManager clientManager) + public GiveawayManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager) { - super("Giveaway Manager", plugin); + super("Giveaway Manager", plugin, clientManager); _clientManager = clientManager; + _statusManager = statusManager; _repository = new GiveawayRepository(plugin); _giveawayMap = _repository.loadGiveaways(); _cooldownMap = _repository.loadCooldowns(); @@ -66,7 +79,7 @@ public class GiveawayManager extends MiniPlugin if (_repository.canGiveaway(accountId, giveawayName, cooldownName)) { UUID uuid = UUID.randomUUID(); - if (_repository.addGiveaway(accountId, giveaway.getId(), cooldown.getId(), Region.US, "", uuid)) + if (_repository.addGiveaway(accountId, giveaway.getId(), cooldown.getId(), _statusManager.getRegion(), _statusManager.getCurrentServerName(), uuid)) { response = new GiveawayResponse(uuid); } @@ -89,6 +102,9 @@ public class GiveawayManager extends MiniPlugin { if (response.isSuccess()) { + Get(player).addGiveawayReward(new GiveawayReward(giveaway.getPrettyName(), response.getGiveawayId().toString().replace("-", ""))); + notifyPlayer(player); + GiveawayMessage message = new GiveawayMessage(giveawayName, player.getName(), giveaway.getMessage(), giveaway.getHeader()); message.publish(); } @@ -114,4 +130,51 @@ public class GiveawayManager extends MiniPlugin { return _cooldownMap.containsKey(name); } + + @EventHandler + public void notifyGiveaway(UpdateEvent event) + { + if (event.getType() == UpdateType.MIN_01) + { + for (Player player : UtilServer.getPlayers()) + notifyPlayer(player); + } + } + + @EventHandler + public void join(PlayerJoinEvent event) + { + notifyPlayer(event.getPlayer()); + } + + public void notifyPlayer(Player player) + { + PlayerGiveawayData data = Get(player); + if (!data.getGiveawayRewards().isEmpty()) + { + GiveawayReward reward = data.getGiveawayRewards().poll(); + UtilPlayer.message(player, F.main("Giveaway", "You have a prize to claim!")); + UtilPlayer.message(player, F.main("Giveaway", "You have won " + F.elem(reward.getName()))); + UtilPlayer.message(player, F.main("Giveaway", "To claim your reward please take a screenshot and contact support")); + UtilPlayer.message(player, F.main("Giveaway", "Reward Key: " + F.elem(reward.getUuid()))); + } + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + Set(playerName, _repository.loadPlayerGiveaway(resultSet)); + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT g.prettyName, ag.uuid FROM accountGiveaway AS ag INNER JOIN giveaway AS g ON ag.giveawayId = g.id WHERE ag.claimed = 0 AND ag.accountId = " + accountId + ";"; + } + + @Override + protected PlayerGiveawayData AddPlayer(String player) + { + return new PlayerGiveawayData(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java index 7025f2f04..c8cac2179 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java @@ -21,7 +21,7 @@ import mineplex.serverdata.Region; public class GiveawayRepository extends RepositoryBase { private static final String INSERT_GIVEAWAY = "INSERT INTO Account.accountGiveaway (giveawayId, accountId, cooldownId, region, serverName, time, uuid) VALUES (?, ?, ?, ?, ?, now(), ?)"; - private static final String LOAD_GIVEAWAY = "SELECT id, name, header, message, max, notifyNetwork, notifyCooldown, canWinTwice FROM Account.giveaway WHERE enabled = TRUE"; + private static final String LOAD_GIVEAWAY = "SELECT id, name, prettyName, header, message, max, notifyNetwork, notifyCooldown, canWinTwice FROM Account.giveaway WHERE enabled = TRUE"; private static final String LOAD_COOLDOWN = "SELECT id, name, cooldown FROM Account.giveawayCooldown"; public GiveawayRepository(JavaPlugin plugin) @@ -68,14 +68,15 @@ public class GiveawayRepository extends RepositoryBase { int id = resultSet.getInt(1); String name = resultSet.getString(2); - String header = resultSet.getString(3); - String message = resultSet.getString(4); - int max = resultSet.getInt(5); - boolean notifyNetwork = resultSet.getBoolean(6); - int notifyCooldown = resultSet.getInt(7); - boolean canWinTwice = resultSet.getBoolean(8); + String prettyName = resultSet.getString(3); + String header = resultSet.getString(4); + String message = resultSet.getString(5); + int max = resultSet.getInt(6); + boolean notifyNetwork = resultSet.getBoolean(7); + int notifyCooldown = resultSet.getInt(8); + boolean canWinTwice = resultSet.getBoolean(9); - Giveaway giveaway = new Giveaway(id, name, header, message, notifyNetwork, notifyCooldown); + Giveaway giveaway = new Giveaway(id, name, prettyName, header, message, notifyNetwork, notifyCooldown); map.put(name, giveaway); } } @@ -104,6 +105,21 @@ public class GiveawayRepository extends RepositoryBase return map; } + public PlayerGiveawayData loadPlayerGiveaway(ResultSet resultSet) throws SQLException + { + PlayerGiveawayData giveawayData = new PlayerGiveawayData(); + + while (resultSet.next()) + { + String name = resultSet.getString(1); + String uuid = resultSet.getString(2); + GiveawayReward reward = new GiveawayReward(name, uuid); + giveawayData.addGiveawayReward(reward); + } + + return giveawayData; + } + @Override protected void initialize() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayReward.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayReward.java new file mode 100644 index 000000000..21be3cd75 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayReward.java @@ -0,0 +1,23 @@ +package mineplex.core.giveaway; + +public class GiveawayReward +{ + private String _name; + private String _uuid; + + public GiveawayReward(String name, String uuid) + { + _name = name; + _uuid = uuid; + } + + public String getName() + { + return _name; + } + + public String getUuid() + { + return _uuid; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/PlayerGiveawayData.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/PlayerGiveawayData.java new file mode 100644 index 000000000..01f984fcb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/PlayerGiveawayData.java @@ -0,0 +1,26 @@ +package mineplex.core.giveaway; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +public class PlayerGiveawayData +{ + private Queue _giveawayRewards; + + public PlayerGiveawayData() + { + _giveawayRewards = new LinkedList(); + } + + public void addGiveawayReward(GiveawayReward reward) + { + _giveawayRewards.add(reward); + } + + public Queue getGiveawayRewards() + { + return _giveawayRewards; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java index 3a5edd15d..82becc622 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java @@ -132,6 +132,17 @@ public class InventoryManager extends MiniDbClientPlugin } public void addItemToInventoryForOffline(final Callback callback, final UUID uuid, final String item, final int count) + { + Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() + { + public void run() + { + addItemToInventoryForOffline(callback, PlayerCache.getInstance().getPlayer(uuid).getAccountId(), item, count); + } + }); + } + + public void addItemToInventoryForOffline(final Callback callback, final int accountId, final String item, final int count) { Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() { @@ -150,9 +161,8 @@ public class InventoryManager extends MiniDbClientPlugin synchronized (_inventoryLock) { - final boolean success = _repository.incrementClientInventoryItem(PlayerCache.getInstance().getPlayer(uuid) - .getAccountId(), _items.get(item).Id, count); - + final boolean success = _repository.incrementClientInventoryItem(accountId, _items.get(item).Id, count); + if (callback != null) { Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() @@ -213,14 +223,14 @@ public class InventoryManager extends MiniDbClientPlugin { level = Math.max(((Player) viewer).getLevel(), level); } - + event.getInventory().setItem(1, new ItemStack(Material.INK_SACK, level, (byte) 4)); return; } event.getInventory().setItem(1, new ItemStack(Material.AIR)); } - + @EventHandler public void onInventoryClick(final InventoryClickEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java index 2d4b29462..b051b051c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java @@ -293,6 +293,6 @@ public class PreferencesPage extends ShopPageBase> _cachedUUIDs = new NautHashMap>(); - private List _commandQueue = new ArrayList(); private static Object _commandLock = new Object(); public long _lastPoll = System.currentTimeMillis() - 120000; private SimpleDateFormat _dateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); - public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, Punish punish) + public Enjin(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager) { super("Enjin", plugin); @@ -56,8 +51,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor _donationManager = donationManager; _inventoryManager = inventoryManager; - _punish = punish; - _repository = new TempRepository(plugin); + _purchaseManager = new PurchaseManager(plugin); plugin.getCommand("enjin_mineplex").setExecutor(this); plugin.getCommand("pull").setExecutor(this); @@ -77,60 +71,6 @@ public class Enjin extends MiniPlugin implements CommandExecutor iterator.remove(); } } - - @EventHandler - public void processCommandQueue(UpdateEvent event) - { - if (event.getType() != UpdateType.MIN_01 || _commandQueue.size() == 0) - return; - - List commandCopyQueue = new ArrayList(); - - synchronized (_commandLock) - { - for (QueuedCommand command : _commandQueue) - commandCopyQueue.add(command); - - _commandQueue.clear(); - } - - System.out.println("=====] Processing queued commands [====="); - for (QueuedCommand command : commandCopyQueue) - { - try - { - onCommand(command.Sender, command.Command, command.Label, command.Args); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - } - System.out.println("========================================"); - } - - @EventHandler - public void pollLastPurchases(UpdateEvent event) - { - if (event.getType() != UpdateType.MIN_01) - return; - - /* - @SuppressWarnings("serial") - List purchases = new JsonWebCall("http://www.mineplex.com/api/m-shopping-purchases/m/14702725").Execute(new TypeToken>(){}.getType(), null); - _lastPoll = System.currentTimeMillis(); - - int i = 0; - for (EnjinPurchase purchase : purchases) - { - if (i > 10) - break; - - purchase.logInfoToConsole(); - i++; - } - */ - } @Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) @@ -180,240 +120,20 @@ public class Enjin extends MiniPlugin implements CommandExecutor final UUID playerUUID = uuid; _cachedUUIDs.put(name, new AbstractMap.SimpleEntry(playerUUID, System.currentTimeMillis() + 240000)); - - if (args.length == 3 && args[0].equalsIgnoreCase("gem")) - { - final int amount = Integer.parseInt(args[2]); - - _donationManager.RewardGems(new Callback() - { - public void run (Boolean response) - { - if (response) - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems."); - } - else - { - //_commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " gems. Queuing for run later."); - } - } - }, "purchase", name, playerUUID, amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("coin")) - { - final int amount = Integer.parseInt(args[2]); - _donationManager.RewardCoins(new Callback() - { - public void run (Boolean response) + if (!checkForCoinPurchase(args, name, playerUUID, client)) + if (!checkForRankPurchase(args, name, playerUUID, client)) + if(!checkForPurchase(args, name, client)) { - if (response) + StringBuilder sb = new StringBuilder(); + + for (String arg : args) { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); - } - else - { - //_commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); + sb.append(arg + " "); } + + System.out.println("Received Command : " + sb.toString()); } - }, "purchase", name, client.getAccountId(), amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("booster")) - { - int amount = Integer.parseInt(args[2]); - - _donationManager.PurchaseUnknownSalesPackage(null, name, client.getAccountId(), "Gem Booster " + amount, false, 0, false); - _repository.addGemBooster(name, amount); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Gem Boosters" + "."); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("key")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); - else - { - // Add arg so we don't add back to windows api call - //_commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } - } - }, playerUUID, "Treasure", "Treasure Key", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) - { - if (data == TransactionResponse.Success) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); - else - { - // Add arg so we don't add back to windows api call - //_commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } - } - }, playerUUID, "Treasure", "Treasure Key", amount); - } - else - { - //_commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } - } - }, name, client.getAccountId(), "Treasure Key " + amount, false, 0, false); - } - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("chest")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); - else - { - // Add arg so we don't add back to windows api call - //_commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); - } - } - }, playerUUID, "Utility", "Treasure Chest", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); - else - { - // Add arg so we don't add back to windows api call - //_commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); - } - } - }, playerUUID, "Utility", "Treasure Chest", amount); - } - }, name, client.getAccountId(), "Treasure Chest " + amount, false, 0, false); - } - } - else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) - { - final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); - final boolean perm = Boolean.parseBoolean(args[3]); - - _clientManager.loadClientByName(name, new Runnable() - { - public void run() - { - if (rank == Rank.ALL || _clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().has(rank) || _clientManager.Get(name).GetRank() == rank) - { - _clientManager.SaveRank(name, playerUUID, rank, perm); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - else - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - } - }); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) - { - final int amount = Integer.parseInt(args[2]); - final String category = args[3]; - String tempName = args[4]; - - for (int i = 5; i < args.length; i++) - { - tempName += " " + args[i]; - } - - final String packageName = tempName; - - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) - { - if (data == TransactionResponse.Success) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); - else - { - // Add arg so we don't add back to windows api call - //_commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); - } - } - }, playerUUID, category, packageName, amount); - } - else - { - //_commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } - } - }, name, client.getAccountId(), packageName, false, 0, false); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; - } - - _punish.RemoveBan(name, reason); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("ban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; - } - - _punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason); - } } } }); @@ -436,4 +156,111 @@ public class Enjin extends MiniPlugin implements CommandExecutor return true; } -} + + protected boolean checkForRankPurchase(String[] args, final String name, final UUID playerUUID, final CoreClient client) + { + if (args.length != 4 || !args[0].equalsIgnoreCase("rank")) + return false;; + + final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); + final boolean perm = Boolean.parseBoolean(args[3]); + + _clientManager.loadClientByName(name, new Runnable() + { + public void run() + { + if (rank == Rank.ALL || _clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().has(rank) || _clientManager.Get(name).GetRank() == rank) + { + _clientManager.SaveRank(new Callback() + { + public void run(Rank data) + { + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), rank.Name + (perm ? " Permanent" : " Monthly"), 1, data == rank); + } + }, name, playerUUID, rank, perm); + + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); + } + else + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), rank.Name + (perm ? " Permanent" : " Monthly"), 1, false); + } + } + }); + + return true; + } + + protected boolean checkForPurchase(String[] args, final String name, final CoreClient client) + { + if (args.length < 3 || !args[0].equalsIgnoreCase("purchase")) + return false; + + final int amount = Integer.parseInt(args[2]); + String tempName = args[4]; + + for (int i = 5; i < args.length; i++) + { + tempName += " " + args[i]; + } + + final String packageName = tempName; + + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + { + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, true); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + } + else + { + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, false); + } + } + }, client.getAccountId(), packageName, amount); + } + else + { + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + ". Queuing for run later."); + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), packageName, amount, data == TransactionResponse.Success); + } + } + }, name, client.getAccountId(), amount == 1 ? packageName : packageName + " " + amount, false, 0, false); + + return true; + } + + protected boolean checkForCoinPurchase(String[] args, final String name, final UUID playerUUID, final CoreClient client) + { + if (args.length != 3 || !args[0].equalsIgnoreCase("coin")) + return false; + + final int amount = Integer.parseInt(args[2]); + + _donationManager.RewardCoins(new Callback() + { + public void run (Boolean response) + { + if (response) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); + else + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); + + _purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), "Coins", amount, response); + } + }, "purchase", name, client.getAccountId(), amount); + + return true; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/EnjinTranslator.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/EnjinTranslator.java index d9222b689..1304f0a3e 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/EnjinTranslator.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/EnjinTranslator.java @@ -28,11 +28,9 @@ public class EnjinTranslator extends JavaPlugin CommandCenter.Instance.setClientManager(clientManager); DonationManager donationManager = new DonationManager(this, clientManager, GetWebServerAddress()); - //Other Modules - Punish punish = new Punish(this, GetWebServerAddress(), clientManager); //Main Modules - new Enjin(this, clientManager, donationManager, new InventoryManager(this, clientManager), punish); + new Enjin(this, clientManager, donationManager, new InventoryManager(this, clientManager)); new Updater(this); } diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java new file mode 100644 index 000000000..1897f407e --- /dev/null +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java @@ -0,0 +1,75 @@ +package mineplex.enjinTranslator.purchase; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.NautHashMap; +import mineplex.core.database.ResultSetCallable; +import mineplex.enjinTranslator.purchase.data.PurchaseRepository; +import mineplex.enjinTranslator.purchase.data.Package; + +public class PurchaseManager extends MiniPlugin +{ + private static Object _purchaseLock = new Object(); + + private PurchaseRepository _repository; + private NautHashMap _purchases = new NautHashMap(); + + public PurchaseManager(JavaPlugin plugin) + { + super("Purchase Manager", plugin); + + _repository = new PurchaseRepository(plugin); + + Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(getPlugin(), new Runnable() + { + public void run() + { + updatePackages(); + } + }, 20L); + } + + private void updatePackages() + { + List packages = _repository.retrievePackages(); + + synchronized (_purchaseLock) + { + for (mineplex.enjinTranslator.purchase.data.Package purchasePackage : packages) + { + _purchases.put(purchasePackage.getName(), purchasePackage); + } + } + } + + public void addAccountPurchaseToQueue(int accountId, final String packageName, int count, boolean success) + { + synchronized (_purchaseLock) + { + if (!_purchases.containsKey(packageName)) + { + _repository.addPackage(packageName, new ResultSetCallable() + { + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + int packageId = resultSet.getInt(1); + + _purchases.put(packageName, new Package(packageId, packageName)); + System.out.println("Added new package : " + packageName); + } + } + }); + } + + _repository.addAccountPurchase(accountId, _purchases.get(packageName).getId(), count, success); + } + } +} diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/Package.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/Package.java new file mode 100644 index 000000000..9796b8a5d --- /dev/null +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/Package.java @@ -0,0 +1,23 @@ +package mineplex.enjinTranslator.purchase.data; + +public class Package +{ + private int _id; + private String _name; + + public Package(int id, String name) + { + _id = id; + _name = name; + } + + public int getId() + { + return _id; + } + + public String getName() + { + return _name; + } +} diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java new file mode 100644 index 000000000..d71d09552 --- /dev/null +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java @@ -0,0 +1,62 @@ +package mineplex.enjinTranslator.purchase.data; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.ColumnBoolean; +import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnVarChar; + +public class PurchaseRepository extends RepositoryBase +{ + private static String INSERT_ACCOUNT_PURCHASE = "INSERT INTO accountPurchases (accountId, packageId, amount, date, success) VALUES (?, ?, ?, now(), ?);"; + + private static String INSERT_PACKAGE = "INSERT INTO packages (packageName) VALUES (?);"; + private static String RETRIEVE_PACKAGES = "SELECT id, packageName FROM packages;"; + + public PurchaseRepository(JavaPlugin plugin) + { + super(plugin, DBPool.ACCOUNT); + } + + @Override + protected void initialize() { } + + @Override + protected void update() { } + + public void addPackage(String name, ResultSetCallable callable) + { + executeInsert(INSERT_PACKAGE, callable, new ColumnVarChar("packageName", 100, name)); + } + + public List retrievePackages() + { + final List packages = new ArrayList(); + + executeQuery(RETRIEVE_PACKAGES, new ResultSetCallable() + { + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + packages.add(new Package(resultSet.getInt(1), resultSet.getString(2))); + } + } + }); + + return packages; + } + + public boolean addAccountPurchase(int accountId, int packageId, int count, boolean success) + { + return executeInsert(INSERT_ACCOUNT_PURCHASE, null, new ColumnInt("accountId", accountId), new ColumnInt("packageId", packageId), new ColumnInt("count", count), new ColumnBoolean("success", success)) > 0; + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 7bd1963cc..8a46416d1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -114,7 +114,7 @@ public class Hub extends JavaPlugin implements IRelation //Main Modules ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); - GiveawayManager giveawayManager = new GiveawayManager(this, clientManager); + GiveawayManager giveawayManager = new GiveawayManager(this, clientManager, serverStatusManager); new TitanGiveawayManager(this, clientManager, serverStatusManager); Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TrickOrTreatManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TrickOrTreatManager.java index ddb276a26..935d83754 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TrickOrTreatManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TrickOrTreatManager.java @@ -85,7 +85,8 @@ public class TrickOrTreatManager extends MiniPlugin public TrickOrTreatManager(JavaPlugin plugin, HubManager manager, TaskManager taskManager, DonationManager donationManager, CoreClientManager coreClientManager) { super("Trick or Treat", plugin); - + + // Test commit _manager = manager; _taskManager = taskManager; _donationManager = donationManager; @@ -93,7 +94,7 @@ public class TrickOrTreatManager extends MiniPlugin _tricks.add(new Blindness(plugin)); _tricks.add(new Nausea(plugin)); - _tricks.add(new RandomTeleport(plugin)); + //_tricks.add(new RandomTeleport(plugin)); _tricks.add(new ShockingStrikes(plugin)); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 5963ea411..f65dfb6d3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -588,12 +588,10 @@ public class ServerManager extends MiniPlugin if (largestServer.getAvailableSlots() >= MIN_SLOTS_REQUIRED || largestServer.MaxPlayers > 40) { - System.out.println("Largest."); return largestServer; } else { - System.out.println("Random."); return servers.get(random.nextInt(count)); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index 4940ce046..c1c98cf3b 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -23,13 +23,14 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.staffServer.customerSupport.CustomerSupport; import mineplex.staffServer.salespackage.SalesPackageManager; -import net.minecraft.server.v1_7_R4.MinecraftServer; -import net.minecraft.util.com.mojang.authlib.GameProfile; +import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_7_R4.CraftServer; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.plugin.java.JavaPlugin; +import com.mojang.authlib.GameProfile; + public class StaffServer extends JavaPlugin { private String WEB_CONFIG = "webServer"; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 179831f9d..0c60a3745 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -149,7 +149,7 @@ public class Arcade extends JavaPlugin new GlobalPacketManager(this, _clientManager, serverStatusManager); - GiveawayManager giveawayManager = new GiveawayManager(this, _clientManager); + GiveawayManager giveawayManager = new GiveawayManager(this, _clientManager, serverStatusManager); //Arcade Manager PollManager pollManager = new PollManager(this, _clientManager, _donationManager);