diff --git a/Art/Carl.png b/Art/Carl.png new file mode 100644 index 000000000..5d4fe6d36 Binary files /dev/null and b/Art/Carl.png differ diff --git a/Plugins/.idea/artifacts/Mineplex_Hub_test.xml b/Plugins/.idea/artifacts/Mineplex_Hub_test.xml index d164c4c6a..0527ee7d4 100644 --- a/Plugins/.idea/artifacts/Mineplex_Hub_test.xml +++ b/Plugins/.idea/artifacts/Mineplex_Hub_test.xml @@ -1,5 +1,5 @@ - + $PROJECT_DIR$/../Testing/Hub/plugins diff --git a/Plugins/.idea/artifacts/Mineplex_Votifier_jar.xml b/Plugins/.idea/artifacts/Mineplex_Votifier_jar.xml new file mode 100644 index 000000000..372114469 --- /dev/null +++ b/Plugins/.idea/artifacts/Mineplex_Votifier_jar.xml @@ -0,0 +1,24 @@ + + + $PROJECT_DIR$/out/artifacts/ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Plugins/.idea/libraries/bukkit.xml b/Plugins/.idea/libraries/bukkit.xml deleted file mode 100644 index 8053b86f3..000000000 --- a/Plugins/.idea/libraries/bukkit.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/Plugins/.idea/modules.xml b/Plugins/.idea/modules.xml index bf0ac4bae..bcc0470f4 100644 --- a/Plugins/.idea/modules.xml +++ b/Plugins/.idea/modules.xml @@ -17,6 +17,7 @@ + diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index c3513308c..72ce23304 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -85,5 +85,11 @@ public class UtilMath return Math.random() * d; } + + public static T randomElement(T[] array) { + if (array.length == 0) + return null; + return array[random.nextInt(array.length)]; + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index 322a55134..321f16789 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -6,20 +6,23 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; +import net.minecraft.server.v1_7_R4.EntityPlayer; +import net.minecraft.server.v1_7_R4.Packet; +import net.minecraft.server.v1_7_R4.PlayerConnection; + import org.bukkit.ChatColor; -import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.util.Vector; -import net.minecraft.server.v1_7_R4.Packet; -import net.minecraft.server.v1_7_R4.PlayerConnection; - public class UtilPlayer { private static boolean hasIntersection(Vector3D p1, Vector3D p2, Vector3D min, Vector3D max) @@ -608,7 +611,19 @@ public class UtilPlayer return ((CraftPlayer) player).getHandle().spectating; return false; } - + + public static InventoryView swapToInventory(Player player, Inventory inv) { + + EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); + if (nmsPlayer.activeContainer != nmsPlayer.defaultContainer) + { + // Do this so that other inventories know their time is over. + CraftEventFactory.handleInventoryCloseEvent(nmsPlayer); + nmsPlayer.m(); + } + return player.openInventory(inv); + } + /* public void setListName(Player player, CoreClient client) { diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 4ae8f94dc..4372b6fba 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -2,6 +2,8 @@ package mineplex.core.common.util; import java.util.Collection; +import org.apache.commons.lang.WordUtils; + public class UtilText { public static String listToString(Collection inputList, boolean comma) { String out = ""; @@ -84,4 +86,13 @@ public class UtilText { return false; } + + public static String[] wrap(String text, int lineLength) + { + return wrap(text, lineLength, true); + } + + public static String[] wrap(String text, int lineLength, boolean wrapLongerWords) { + return WordUtils.wrap(text, lineLength, "\00D0", wrapLongerWords).split("\00D0"); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index f2b2a0016..481bda4dd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -2,6 +2,7 @@ package mineplex.core.account; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; import java.util.UUID; @@ -50,6 +51,7 @@ public class CoreClientManager extends MiniPlugin private RedisDataRepository _accountCacheRepository; private NautHashMap _loginProcessors = new NautHashMap(); + private LinkedList _querylessLoginProcessors = new LinkedList(); private Object _clientLock = new Object(); @@ -110,7 +112,7 @@ public class CoreClientManager extends MiniPlugin { _clientList.remove(name); } - + _plugin.getServer().getPluginManager().callEvent(new ClientUnloadEvent(name)); } @@ -138,6 +140,16 @@ public class CoreClientManager extends MiniPlugin return Bukkit.getOnlinePlayers().size() + Math.max(0, _clientsConnecting.get()); } + /** + * Get the databse account id for a player. Requires the player is online + * @param player + * @return + */ + public int getAccountId(Player player) + { + return Get(player).getAccountId(); + } + @EventHandler(priority = EventPriority.LOWEST) public void AsyncLogin(AsyncPlayerPreLoginEvent event) { @@ -224,7 +236,7 @@ public class CoreClientManager extends MiniPlugin CoreClient client = Add(playerName); client.SetRank(Rank.valueOf(token.Rank)); - client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName())); + client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); @@ -264,7 +276,7 @@ public class CoreClientManager extends MiniPlugin { public void run() { - client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName())); + client.setAccountId(_repository.login(_loginProcessors, _querylessLoginProcessors, uuid.toString(), client.GetPlayerName())); _clientLoginLock.remove(client.GetPlayerName()); } }); @@ -454,7 +466,7 @@ public class CoreClientManager extends MiniPlugin callback.run(matchedName); return; } - + callback.run(matchedName); } }, caller, playerName, true); @@ -485,7 +497,9 @@ public class CoreClientManager extends MiniPlugin clientIterator.remove(); if (clientPlayer != null) + { _plugin.getServer().getPluginManager().callEvent(new ClientUnloadEvent(clientPlayer.getName())); + } } } } @@ -507,6 +521,11 @@ public class CoreClientManager extends MiniPlugin { _loginProcessors.put(processor.getName(), processor); } + + public void addStoredProcedureLoginProcessor(IQuerylessLoginProcessor processor) + { + _querylessLoginProcessors.add(processor); + } public boolean hasRank(Player player, Rank rank) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/IQuerylessLoginProcessor.java b/Plugins/Mineplex.Core/src/mineplex/core/account/IQuerylessLoginProcessor.java new file mode 100644 index 000000000..7c69bb1c1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/IQuerylessLoginProcessor.java @@ -0,0 +1,6 @@ +package mineplex.core.account; + +public interface IQuerylessLoginProcessor +{ + public void processLogin(String playerName, int accountId); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 60f756748..c8dccb23e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -6,6 +6,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -14,6 +15,7 @@ import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.ILoginProcessor; +import mineplex.core.account.IQuerylessLoginProcessor; import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; @@ -55,7 +57,7 @@ public class AccountRepository extends RepositoryBase //executeUpdate(CREATE_ACCOUNT_TABLE); } - public int login(NautHashMap loginProcessors, String uuid, String name) + public int login(NautHashMap loginProcessors, LinkedList querylessLoginProcessors, String uuid, String name) { int accountId = -1; try ( @@ -145,6 +147,11 @@ public class AccountRepository extends RepositoryBase loginProcessor.processLoginResultSet(name, accountId, statement.getResultSet()); statement.getMoreResults(); } + + for (IQuerylessLoginProcessor loginProcessor : querylessLoginProcessors) + { + loginProcessor.processLogin(name, accountId); + } } catch (Exception exception) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java index 485f5a124..76e58b6fb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java @@ -137,15 +137,6 @@ public class AchievementManager extends MiniPlugin _log.remove(event.getPlayer().getName()); } - @EventHandler - public void playerJoin(PlayerJoinEvent event) - { - if (_giveInterfaceItem) - { - giveInterfaceItem(event.getPlayer()); - } - } - public void clearLog(Player player) { _log.remove(player.getName()); @@ -161,22 +152,7 @@ public class AchievementManager extends MiniPlugin _giveInterfaceItem = giveInterfaceItem; } - public void giveInterfaceItem(Player player) - { - if (!UtilGear.isMat(player.getInventory().getItem(_interfaceSlot), Material.SKULL_ITEM)) - { - ItemStack item = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, ChatColor.RESET + C.cGreen + "/stats"); - SkullMeta meta = ((SkullMeta) item.getItemMeta()); - meta.setOwner(player.getName()); - item.setItemMeta(meta); - - player.getInventory().setItem(_interfaceSlot, item); - - UtilInv.Update(player); - } - } - - @EventHandler + /*@EventHandler public void openShop(PlayerInteractEvent event) { if (!_shopEnabled) @@ -188,7 +164,7 @@ public class AchievementManager extends MiniPlugin openShop(event.getPlayer()); } - } + }*/ public boolean hasCategory(Player player, Achievement[] required) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java new file mode 100644 index 000000000..d2cfef1f8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java @@ -0,0 +1,156 @@ +package mineplex.core.bonuses; + +import java.util.List; + +import mineplex.core.common.util.C; + +public class BonusAmount +{ + private int _gems; + private int _coins; + private int _gold; + private int _bonusGems; + private int _bonusCoins; + private int _bonusGold; + private int _experience; + private int _bonusExperience; + private int _tickets; + + public BonusAmount() + { + + } + + public int getGems() + { + return _gems; + } + + public void setGems(int gems) + { + _gems = gems; + } + + public int getCoins() + { + return _coins; + } + + public void setCoins(int coins) + { + _coins = coins; + } + + public int getGold() + { + return _gold; + } + + public void setGold(int gold) + { + _gold = gold; + } + + public int getBonusGems() + { + return _bonusGems; + } + + public void setBonusGems(int bonusGems) + { + _bonusGems = bonusGems; + } + + public int getBonusCoins() + { + return _bonusCoins; + } + + public void setBonusCoins(int bonusCoins) + { + _bonusCoins = bonusCoins; + } + + public int getBonusGold() + { + return _bonusGold; + } + + public void setBonusGold(int bonusGold) + { + _bonusGold = bonusGold; + } + + public int getTotalGems() + { + return getGems() + getBonusGems(); + } + + public int getTotalCoins() + { + return getCoins() + getBonusCoins(); + } + + public int getTotalGold() + { + return getGold() + getBonusGold(); + } + + public int getExperience() + { + return _experience; + } + + public void setExperience(int experience) + { + _experience = experience; + } + + public int getBonusExperience() + { + return _bonusExperience; + } + + public void setBonusExperience(int bonusExperience) + { + _bonusExperience = bonusExperience; + } + + public int getTotalExperience() + { + return getExperience() + getBonusExperience(); + } + + public int getTickets() + { + return _tickets; + } + + public void setTickets(int tickets) + { + _tickets = tickets; + } + + public boolean isGreaterThanZero() + { + return _bonusCoins > 0 || _coins > 0 || _bonusGems > 0 || _gems > 0 || _gold > 0 || _bonusGold > 0; + } + + public void addLore(List lore) + { + addLore(lore, getTickets(), 0, "Carl Spin Ticket" + (getTickets() > 1 ? "s" : "")); + addLore(lore, getCoins(), getBonusCoins(), "Coins"); + addLore(lore, getGems(), getBonusGems(), "Gems"); + addLore(lore, getGold(), getBonusGold(), "Gold"); + addLore(lore, getExperience(), getBonusExperience(), "Experience"); + } + + private void addLore(List lore, int amount, int bonus, String suffix) + { + if (amount > 0) + lore.add(C.cYellow + "Reward: " + C.cWhite + amount + " " + suffix); + +// if (bonus > 0) +// lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusClientData.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusClientData.java new file mode 100644 index 000000000..08cccac7f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusClientData.java @@ -0,0 +1,123 @@ +package mineplex.core.bonuses; + +import java.sql.Date; +import java.sql.Timestamp; + +import mineplex.core.hologram.Hologram; +import mineplex.database.tables.records.BonusRecord; + +public class BonusClientData +{ + private BonusRecord _record; + private Hologram _hologram; + + public BonusClientData(BonusRecord record) + { + _record = record; + } + + public BonusRecord getRecord() + { + return _record; + } + + public void setAccountId(Integer value) + { + _record.setAccountId(value); + } + + public Integer getAccountId() + { + return _record.getAccountId(); + } + + public void setDailyTime(Timestamp value) + { + _record.setDailytime(value); + } + + public Timestamp getDailyTime() + { + return _record.getDailytime(); + } + + public void setRankTime(Date value) + { + _record.setRanktime(value); + } + + public Date getRankTime() + { + return _record.getRanktime(); + } + + public void setVoteTime(Date value) + { + _record.setVotetime(value); + } + + public Date getVoteTime() + { + return _record.getVotetime(); + } + + public void setDailyStreak(Integer value) + { + _record.setDailyStreak(value); + } + + public Integer getDailyStreak() + { + return _record.getDailyStreak(); + } + + public void setMaxDailyStreak(Integer value) + { + _record.setMaxDailyStreak(value); + } + + public Integer getMaxDailyStreak() + { + return _record.getMaxDailyStreak(); + } + + public void setVoteStreak(Integer value) + { + _record.setVoteStreak(value); + } + + public Integer getVoteStreak() + { + return _record.getVoteStreak(); + } + + public void setMaxVoteStreak(Integer value) + { + _record.setMaxVoteStreak(value); + } + + public Integer getMaxVoteStreak() + { + return _record.getMaxVoteStreak(); + } + + public void setTickets(Integer value) + { + _record.setTickets(value); + } + + public Integer getTickets() + { + return _record.getTickets(); + } + + public Hologram getHologram() + { + return _hologram; + } + + public void setHologram(Hologram hologram) + { + _hologram = hologram; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java new file mode 100644 index 000000000..fe37f5a42 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -0,0 +1,1038 @@ +package mineplex.core.bonuses; + +import java.sql.Date; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.TimeZone; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.IQuerylessLoginProcessor; +import mineplex.core.account.event.ClientUnloadEvent; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.database.DBPool; +import mineplex.core.donation.DonationManager; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.npc.Npc; +import mineplex.core.npc.NpcManager; +import mineplex.core.pet.PetManager; +import mineplex.core.recharge.Recharge; +import mineplex.core.reward.RewardManager; +import mineplex.core.stats.StatsManager; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.votifier.VotifierCommand; +import mineplex.database.Tables; +import mineplex.core.bonuses.animations.AnimationCarl; +import mineplex.core.bonuses.commands.AnimationCommand; +import mineplex.core.bonuses.commands.GuiCommand; +import mineplex.core.bonuses.commands.TicketCommand; +import mineplex.core.bonuses.event.CarlSpinnerEvent; +import mineplex.core.bonuses.gui.BonusGui; +import mineplex.database.tables.records.BonusRecord; +import mineplex.core.bonuses.gui.SpinGui; +import mineplex.core.poll.PollManager; +import mineplex.serverdata.commands.ServerCommandManager; + +import org.jooq.SQLDialect; +import org.jooq.impl.DSL; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Dropper; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import net.minecraft.server.v1_7_R4.DataWatcher; +import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata; + +public class BonusManager extends MiniClientPlugin implements IQuerylessLoginProcessor +{ + + public static final TimeZone TIMEZONE = TimeZone.getTimeZone("UTC"); + + private static long timeOffSet = 0; + + private ArrayList _pendingExplosions = new ArrayList<>(); + private ArrayList _pendingExplosionsPlayers = new ArrayList<>(); + private HashMap _showCarl = new HashMap<>(); + private long _explode; + private boolean _canVote; + + public static long getSqlTime() + { + return getSqlTime(System.currentTimeMillis()); + } + + public static long getSqlTime(long currentTime) + { + return currentTime + timeOffSet; + } + + public static long getLocalTime() + { + return System.currentTimeMillis(); + } + + public static long getLocalTime(long sqlTime) + { + return sqlTime - timeOffSet; + } + + public void updateOffSet() + { + _repository.getTimeOffset(new Callback() { + + @Override + public void run(Long data) + { + System.out.println("Sql time offset is: " + data); + timeOffSet = data; + } + }); + } + + private BonusRepository _repository; + private CoreClientManager _clientManager; + private DonationManager _donationManager; + private PollManager _pollManager; + private NpcManager _npcManager; + private HologramManager _hologramManager; + private RewardManager _rewardManager; + private StatsManager _statsManager; + public boolean _enabled; + private Npc _carlNpc; + private AnimationCarl _animation; + private int _visualTick; + + // Streak + private StreakRecord _dailyStreak; + private StreakRecord _voteStreak; + + /** + * THIS SHOULD ONLY BE USED FOR VOTIFIER! + */ + public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super("Bonus", plugin); + _enabled = false; + + _repository = new BonusRepository(plugin, this, donationManager); + _clientManager = clientManager; + _donationManager = donationManager; + + updateOffSet(); + } + + public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager) + { + super("Bonus", plugin); + _repository = new BonusRepository(plugin, this, donationManager); + _clientManager = clientManager; + _donationManager = donationManager; + _npcManager = npcManager; + _hologramManager = hologramManager; + + _rewardManager = new RewardManager(clientManager, donationManager, inventoryManager, petManager, statsManager, + 100, 250, + 500, 1000, + 4000, 6000, + 12000, 32000, + true, true); + + _pollManager = pollManager; + _statsManager = statsManager; + + // Hope to god this works! + _canVote = true; + + if (npcManager != null) + { + _carlNpc = _npcManager.getNpcByName("Carl the Creeper"); + if (_carlNpc == null) + { + _enabled = false; + } + else + { + _enabled = true; +// _carlNpc.getEntity().setCustomName(""); +// _carlNpc.getEntity().setCustomNameVisible(false); + _animation = new AnimationCarl(_carlNpc.getEntity()); + _animation.setRunning(false); + } + } + else + { + _enabled = false; + } + + clientManager.addStoredProcedureLoginProcessor(this); + + ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class, + new VoteHandler(this)); + + updateOffSet(); + updateStreakRecord(); + } + + @Override + public void addCommands() + { + addCommand(new GuiCommand(this)); + addCommand(new AnimationCommand(this)); + addCommand(new TicketCommand(this)); + } + + // Just keeping things up-to-date + @EventHandler + public void onSlow(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_16) + return; + System.err.println("Updating off set"); + updateOffSet(); + } + + @EventHandler + public void updateStreak(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_16) + return; + + updateStreakRecord(); + } + + private void updateStreakRecord() + { + _repository.getDailyStreakRecord(new Callback() + { + @Override + public void run(StreakRecord data) + { + _dailyStreak = data; + } + }); + + _repository.getVoteStreakRecord(new Callback() + { + @Override + public void run(StreakRecord data) + { + _voteStreak = data; + } + }); + } + + public StreakRecord getDailyStreak() + { + return _dailyStreak; + } + + public StreakRecord getVoteStreak() + { + return _voteStreak; + } + + public void handleVote(final Player player) + { + runAsync(new Runnable() + { + @Override + public void run() + { + Get(player).getRecord().refresh(); + runSync(new Runnable() + { + @Override + public void run() + { + addPendingExplosion(player, player.getName()); + UtilPlayer.message(player, F.main("Carl", "Thanks for voting for Mineplex!")); + UtilPlayer.message(player, F.main("Carl", "You received 500 Gems and 1 Carls Spinner Ticket!")); + } + }); + } + }); + + } + + @EventHandler + public void fireCreeper(UpdateEvent event) + { + if(event.getType() != UpdateType.SLOW) + return; + + if(_pendingExplosions.isEmpty()) + return; + + if(!_canVote) + return; + + if (!_enabled) + return; + + _explode = System.currentTimeMillis(); + _animation.setTicks(0); + _canVote = false; + } + + @EventHandler + public void creeperAnimation(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if(_canVote) + return; + + if (!_enabled) + return; + + Entity creeper = _carlNpc.getEntity(); + + double elapsed = (System.currentTimeMillis() - _explode)/1000d; + + //Not Detonated + if (elapsed < 1) + { + //Sound + creeper.getWorld().playSound(creeper.getLocation(), Sound.CREEPER_HISS, (float)(0.5 + elapsed), (float)(0.5 + elapsed)); + + IncreaseSize(creeper); + return; + } + + if(!_animation.isRunning()) + { + //Effect + UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, creeper.getLocation(), 0, 0, 0, 0, 1, ViewDist.MAX, UtilServer.getPlayers()); + creeper.getWorld().playSound(creeper.getLocation(), Sound.EXPLODE, 2f, 1f); + _animation.setType(_pendingExplosions.get(0)); + _animation.setPlayer(_pendingExplosionsPlayers.get(0)); + _animation.setTime(System.currentTimeMillis()); + _animation.setRunning(true); + } + + if(!_animation.isDone()) + return; + + DecreaseSize(creeper); + _pendingExplosions.remove(0); + _pendingExplosionsPlayers.remove(0); + _canVote = true; + } + + @EventHandler + public void updateAnimation(UpdateEvent event) + { + if(event.getType() != UpdateType.TICK) + return; + + if (!_enabled) + return; + + if(!_animation.isRunning()) + return; + + _animation.run(); + } + + public void DecreaseSize(Entity player) + { + if (!_enabled) + return; + + ((CraftEntity)_carlNpc.getEntity()).getHandle().getDataWatcher().watch(16, -1); + } + + public void IncreaseSize(Entity player) + { + if (!_enabled) + return; + + ((CraftEntity)_carlNpc.getEntity()).getHandle().getDataWatcher().watch(16, 1); + } + + // DAILY BONUS + + public static final long TIME_BETWEEN_BONUSES = 1000 * 60 * 60 * 20; + public static final long STREAK_RESET_TIME = 1000 * 60 * 60 * 12; + + public void attemptDailyBonus(final Player player, final BonusAmount amount, final Callback result) + { + if (timeTillDailyBonus(player) > 0) + result.run(false); + + getRepository().attemptDailyBonus(player, new Callback() + { + @Override + public void run(Boolean r) + { + if (r) + { + incrementDailyStreak(player); + awardBonus(player, amount); + updateCreeperVisual(player, true, C.cAqua); + } + + result.run(r); + } + }); + } + + public long timeTillDailyBonus(Player player) + { + return nextDailyBonus(player) - getLocalTime(); + } + + // This calculates the the next daily bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION. + public long nextDailyBonus(Player player) + { + Timestamp timestamp = Get(player).getRecord().getDailytime(); + + if (timestamp == null) + return 0; + + long lastBonus = timestamp.getTime(); + + return getLocalTime(lastBonus + TIME_BETWEEN_BONUSES); + } + + // RANK BONUS + public void attemptRankBonus(final Player player, final Callback result) + { + if (timeTillRankBonus(player) > 0) + result.run(false); + getRepository().attemptRankBonus(player, new Callback() + { + @Override + public void run(Boolean aBoolean) + { + if (aBoolean) + { + awardBonus(player, getRankBonusAmount(player)); + updateCreeperVisual(player, true, C.cAqua); + } + + result.run(aBoolean); + } + }); + } + + public void attemptCarlSpin(final Player player) + { + final BonusClientData clientData = Get(player); + + if (clientData.getTickets() > 0) + { + CarlSpinnerEvent event = new CarlSpinnerEvent(player); + Bukkit.getServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) + { + final int accountId = _clientManager.Get(player).getAccountId(); + + _repository.attemptAddTickets(accountId, clientData, -1, new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + new SpinGui(_plugin, player, _rewardManager, BonusManager.this).openInventory(); + } + else + { + UtilPlayer.message(player, F.main("Carl", "There waa an error processing your request. Try again later")); + } + } + }); + } + } + } + + public long timeTillRankBonus(Player player) + { + return nextRankBonus(player) - getLocalTime(); + } + + + // This calculates the the next rank bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION. + public long nextRankBonus(Player player) + { + Date date = Get(player).getRecord().getRanktime(); + + if (date == null) + return 0; + + long lastBonus = date.getTime(); + + + return getNextRankBonusTime(getLocalTime(lastBonus)); + } + + public void updateDailyStreak(Player player) + { + BonusClientData client = Get(player); + if (client.getDailyStreak() > 0 && client.getDailyTime() != null) + { + long lastBonus = getLocalTime(client.getDailyTime().getTime()); + long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME); + + if (timeLeft < 0) + { + client.setDailyStreak(0); + } + } + } + + public void incrementDailyStreak(Player player) + { + BonusClientData data = Get(player); + + data.setDailyStreak(data.getDailyStreak() + 1); + + if (data.getDailyStreak() > data.getMaxDailyStreak()) + data.setMaxDailyStreak(data.getDailyStreak()); + } + + public void incrementVoteStreak(BonusClientData client) + { + client.setVoteStreak(client.getVoteStreak() + 1); + + if (client.getVoteStreak() > client.getMaxVoteStreak()) + client.setMaxVoteStreak(client.getVoteStreak()); + } + + public boolean continueStreak(long localLastBonus, long extendTime) + { + long maxTime = localLastBonus + TIME_BETWEEN_BONUSES + extendTime; + return System.currentTimeMillis() < maxTime; + } + + public long getStreakTimeRemaining(long localLastBonus, long extendTime) + { + long maxTime = localLastBonus + TIME_BETWEEN_BONUSES + extendTime; + return maxTime - System.currentTimeMillis(); + } + + public static long getNextRankBonusTime(long time) + { + + Calendar calendar = Calendar.getInstance(); + calendar.setTimeZone(TIMEZONE); + calendar.setTimeInMillis(time); + + calendar.add(Calendar.MONTH, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + + calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); + + return calendar.getTimeInMillis(); + } + + public int getDailyMultiplier(Player player) + { + BonusClientData client = Get(player); + int streak = client.getDailyStreak(); + + int multiplyer = Math.min(200, 5 * streak); + if (streak >= 40) multiplyer += (1 * (streak - 40)); + return multiplyer; + } + + public int getVoteMultiplyer(BonusClientData client) + { + int streak = client.getVoteStreak(); + + int multiplyer = Math.min(100, 5 * streak); + if (streak >= 20) multiplyer += (1 * (streak - 40)); + return multiplyer; + } + + public BonusAmount getDailyBonusAmount(Player player) + { + double mult = getDailyMultiplier(player) / 100.0; + + BonusAmount amount = new BonusAmount(); + int coins = 100; + int gems = 100; + int experience = 250; + + amount.setCoins(coins); + amount.setGems(gems); + amount.setExperience(experience); + amount.setBonusCoins((int) (mult * coins)); + amount.setBonusGems((int) (mult * gems)); + amount.setBonusExperience((int) (mult * experience)); + + return amount; + } + + public BonusAmount getVoteBonusAmount(Player player) + { + return getVoteBonusAmount(Get(player)); + } + + public BonusAmount getVoteBonusAmount(BonusClientData client) + { + double mult = getVoteMultiplyer(client) / 100.0; + + BonusAmount amount = new BonusAmount(); + amount.setTickets(1); + amount.setGems(400); + amount.setBonusGems((int) (mult * 400)); + + return amount; + } + + public BonusAmount getRankBonusAmount(Player player) + { + Rank rank = _clientManager.Get(player).GetRank(); + + BonusAmount data = new BonusAmount(); + + if (rank.Has(Rank.MODERATOR)) + { + data.setCoins(35000); + } + if (rank.Has(Rank.LEGEND)) + { + data.setCoins(30000); + } + else if (rank.Has(Rank.HERO)) + { + data.setCoins(15000); + } + else if (rank.Has(Rank.ULTRA)) + { + data.setCoins(7500); + } + + return data; + } + + //VOTE + + public long timeTillVoteBonus(Player player) + { + return nextVoteTime(player) - getLocalTime(); + } + + // This calculates the the next vote bonus, IT HAS TO MATCH THE MYSQL STORED FUNCTION. + public long nextVoteTime(Player player) + { + Date date = Get(player).getVoteTime(); + if (date == null) + return 0; + long lastBonus = date.getTime(); + + return getNextVoteTime(getLocalTime(lastBonus)); + + } + + public void awardBonus(final Player player, BonusAmount amount) + { + final BonusClientData bonusClient = Get(player); + CoreClient coreClient = _clientManager.Get(player); + + final int gems = amount.getTotalGems(); + final int gold = amount.getTotalGold(); + final int coins = amount.getTotalCoins(); + final int tickets = amount.getTickets(); + int experience = amount.getTotalExperience(); + + if (gems > 0) + { + _donationManager.RewardGems(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems"))); + } + else + { + UtilPlayer.message(player, F.main("Carl", "Failed to process Gems")); + } + } + }, "BonusManager", player.getName(), player.getUniqueId(), gems, true); + } + + if (gold > 0) + { + _donationManager.RewardGold(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gold + " Gold"))); + } + else + { + UtilPlayer.message(player, F.main("Carl", "Failed to process Gold")); + } + } + }, "BonusManager", player.getName(), coreClient.getAccountId(), gold, true); + } + + if (coins > 0) + { + _donationManager.RewardCoins(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + { + UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins"))); + } + else + { + UtilPlayer.message(player, F.main("Carl", "Failed to process Coins")); + } + } + }, "BonusManager", player.getName(), coreClient.getAccountId(), coins, true); + } + + if (tickets > 0) + { + final int accountId = _clientManager.Get(player).getAccountId(); + runAsync(new Runnable() + { + @Override + public void run() + { + try + { + final int newTickets = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL).update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)). + where(Tables.bonus.accountId.eq(accountId)).returning(Tables.bonus.tickets).fetchOne().getTickets(); + runSync(new Runnable() + { + @Override + public void run() + { + bonusClient.setTickets(newTickets); + UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(tickets + " Carl Spin Ticket"))); + } + }); + } + catch (Exception e) + { + System.out.println("Failed to award ticket to player: " + player); + e.printStackTrace(); + } + } + }); + } + + if (experience > 0) + { + _statsManager.incrementStat(player, "Global.ExpEarned", experience); + UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(experience + " Experience"))); + } + + UtilPlayer.message(player, F.main("Carl", "Come back tomorrow for more!")); + + } + + @EventHandler + public void openGui(PlayerInteractEntityEvent event) + { + if (!_enabled) + return; + + Entity entity = event.getRightClicked(); + if (entity.equals(_carlNpc.getEntity())) + { + updateDailyStreak(event.getPlayer()); + new BonusGui(_plugin, event.getPlayer(), this, _rewardManager).openInventory(); + } + } + + public static long getNextVoteTime(long time) { + + Calendar calendar = Calendar.getInstance(); + calendar.setTimeZone(TIMEZONE); + calendar.setTimeInMillis(time); + + calendar.add(Calendar.DAY_OF_YEAR, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + + return calendar.getTimeInMillis(); + } + + public boolean canVote(Player player) + { + long nextVoteTime = nextVoteTime(player); + return System.currentTimeMillis() >= nextVoteTime; + } + + public boolean canDaily(Player player) + { + long nextDailyTime = nextDailyBonus(player); + return System.currentTimeMillis() >= nextDailyTime; + } + + public boolean canRank(Player player) + { + long nextRankTime = nextRankBonus(player); + return System.currentTimeMillis() >= nextRankTime; + } + + @EventHandler + public void join(final PlayerJoinEvent event) + { + runSyncLater(new Runnable() + { + @Override + public void run() + { + if (event.getPlayer().isOnline()) + updateCreeperVisual(event.getPlayer(), true, C.cAqua); + } + }, 10); + } + + public void updateCreeperVisual(Player player, boolean updateDataWatcher, String rewardPrefix) + { + if (!_enabled) + return; + + BonusClientData client = Get(player); + + int availableRewards = 0; + + if (canVote(player)) availableRewards++; + if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA)) availableRewards++; + if (canDaily(player)) availableRewards++; + if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++; + + Hologram hologram; + + + if (client.getHologram() == null) + { + double yAdd = UtilPlayer.is1_8(player) ? 2.18 : 2.3; + hologram = new Hologram(_hologramManager, _carlNpc.getLocation().clone().add(0, yAdd, 0), ""); + hologram.setHologramTarget(Hologram.HologramTarget.WHITELIST); + hologram.addPlayer(player); + client.setHologram(hologram); + hologram.start(); + } + else + { + hologram = client.getHologram(); + } + + if (availableRewards > 0) + { + // Hologram +// String name = "Carl the Creeper"; + String text = rewardPrefix + availableRewards + " Reward" + (availableRewards > 1 ? "s" : "") + " to Claim"; + hologram.setText(text); + + if (updateDataWatcher) + { + // Charged + DataWatcher watcher = new DataWatcher(null); + watcher.a(0, (byte) 0); + watcher.a(1, (short) 300); + watcher.a(17, (byte) 1); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(); + packet.a = _carlNpc.getEntity().getEntityId(); + packet.b = watcher.c(); + + UtilPlayer.sendPacket(player, packet); + } + } + else + { + String text = C.cGray + "No Rewards"; + hologram.setText(text); + + if (updateDataWatcher) + { + // Charged + DataWatcher watcher = new DataWatcher(null); + watcher.a(17, (byte) 0); + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(); + packet.a = _carlNpc.getEntity().getEntityId(); + packet.b = watcher.c(); + + UtilPlayer.sendPacket(player, packet); + } + } + } + + @EventHandler + public void updateCreeper(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || !_enabled) + return; + + for (Player player : UtilServer.getPlayers()) + { + String prefix = _visualTick % 2 == 0 ? C.cAqua : C.cDAqua; + updateCreeperVisual(player, false, prefix); + _visualTick++; + } + } + + @Override + protected BonusClientData AddPlayer(String player) + { + // Should never be called! + return null; + } + + public BonusRepository getRepository() + { + return _repository; + } + + public CoreClientManager getClientManager() + { + return _clientManager; + } + + public RewardManager getRewardManager() + { + return _rewardManager; + } + + @Override + @EventHandler + public void UnloadPlayer(final ClientUnloadEvent event) + { + final BonusClientData clientData = Get(event.GetName()); + + if (clientData.getHologram() != null) + clientData.getHologram().stop(); + + // This shouldnt be necessary anymore +// runAsync(new Runnable() +// { +// @Override +// public void run() +// { +// clientData.getRecord().store(); +// } +// }); + + super.UnloadPlayer(event); + } + + @Override + public void processLogin(String playerName, int accountId) + { + BonusRecord record = _repository.loadRecord(playerName, accountId); + BonusClientData clientData = new BonusClientData(record); + Set(playerName, clientData); + } + + public void addPendingExplosion(Player player, Object obj) + { + _pendingExplosions.add(obj); + _pendingExplosionsPlayers.add(player); + } + + public PollManager getPollManager() + { + return _pollManager; + } + + @EventHandler + public void ItemDecay(UpdateEvent event) + { + if(event.getType() != UpdateType.TICK) + return; + + for(Entity entity : _carlNpc.getEntity().getNearbyEntities(3, -0.5, 3)) + { + if(!(entity instanceof Item)) + continue; + + if(((Item)entity).getItemStack().getType() == Material.MONSTER_EGG && ((Item)entity).getItemStack().hasItemMeta() && !((Item)entity).getItemStack().getItemMeta().getDisplayName().startsWith("Hidden")) + entity.remove(); + + if(!((Item) entity).getItemStack().hasItemMeta()) + continue; + + if(!((Item) entity).getItemStack().getItemMeta().getDisplayName().startsWith(" ")) + continue; + + entity.remove(); + } + } + + @EventHandler + public void Join(final PlayerJoinEvent event) + { + runSyncLater(new Runnable() + { + @Override + public void run() + { + _showCarl.put(event.getPlayer().getName(), true); + } + }, 200); + } + + @EventHandler + public void Quit(PlayerQuitEvent event) + { + _showCarl.remove(event.getPlayer().getName()); + } + + @EventHandler + public void carlUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + for (Player player : UtilServer.getPlayers()) + { + if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) + { + if(_pollManager.hasPoll(player) || canVote(player) || canRank(player) || canDaily(player)) + { + if(_showCarl.containsKey(player.getName())) + UtilPlayer.message(player, C.cDGreen + C.Bold + "Carl the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!"); + } + } + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java new file mode 100644 index 000000000..c33d49e19 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java @@ -0,0 +1,386 @@ +package mineplex.core.bonuses; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; + +import com.sun.org.apache.xpath.internal.operations.Bool; +import mineplex.core.bonuses.gui.SpinGui; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.donation.DonationManager; +import mineplex.core.recharge.Recharge; +import mineplex.database.Tables; +import mineplex.database.tables.records.BonusRecord; +import org.jooq.DSLContext; +import org.jooq.Record2; +import org.jooq.SQLDialect; +import org.jooq.TableField; +import org.jooq.impl.DSL; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +public class BonusRepository extends RepositoryBase +{ + private static String CREATE_BONUS_TABLE = "CREATE TABLE IF NOT EXISTS bonus (accountId INT NOT NULL AUTO_INCREMENT, dailytime TIMESTAMP NULL DEFAULT NULL, ranktime DATE NULL DEFAULT NULL, PRIMARY KEY (accountId), FOREIGN KEY (accountId) REFERENCES accounts(id));"; + private BonusManager _manager; + private DonationManager _donationManager; + + public BonusRepository(JavaPlugin plugin, BonusManager bonusManager, DonationManager donationManager) + { + super(plugin, DBPool.ACCOUNT); + _manager = bonusManager; + _donationManager = donationManager; + } + + public BonusRecord loadRecord(String playerName, int accountId) + { + DSLContext create = jooq(); + + BonusRecord record = create.selectFrom(Tables.bonus).where(Tables.bonus.accountId.eq(accountId)).fetchOne(); + + if (record == null) + { + // Need to create new record! + record = create.newRecord(Tables.bonus); + record.setAccountId(accountId); + record.setDailyStreak(0); + record.setMaxDailyStreak(0); + record.setVoteStreak(0); + record.setMaxVoteStreak(0); + record.setTickets(0); + record.store(); // Todo - is this necessary? + } + System.out.println("Loaded record. Daily time: " + record.getDailytime()); + return record; + } + + public void getDailyStreakRecord(Callback callback) + { + getStreakRecord(Tables.bonus.maxDailyStreak, callback); + } + + public void getVoteStreakRecord(Callback callback) + { + getStreakRecord(Tables.bonus.maxVoteStreak, callback); + } + + private void getStreakRecord(final TableField field, final Callback callback) + { + Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + final Record2 record = jooq().select(Tables.accounts.name, field) + .from(Tables.bonus.join(Tables.accounts).on(Tables.bonus.accountId.eq(Tables.accounts.id))) + .orderBy(field.desc()).limit(1).fetchOne(); + + Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + if (record.value1() != null && record.value2() != null) + { + callback.run(new StreakRecord(record.value1(), record.value2())); + } + } + }); + } + }); + } + + public void attemptAddTickets(final int accountId, final BonusClientData client, final int tickets, final Callback callback) + { + if (client.getTickets() + tickets < 0) + callback.run(false); + + Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + try + { + DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); + create.update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)). + where(Tables.bonus.accountId.eq(accountId)).execute(); + final int newTickets = create.select(Tables.bonus.tickets).from(Tables.bonus).where(Tables.bonus.accountId.eq(accountId)).fetchOne().value1(); + + Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + client.setTickets(newTickets); + callback.run(true); + } + }); + } + catch (Exception e) + { + e.printStackTrace(); + callback.run(false); + } + } + }); + } + + public void attemptDailyBonus(final Player player, final Callback result) + { + final int accountId = _manager.getClientManager().Get(player).getAccountId(); + final int coins = 0; + final int gems = 0; + /* + * if (coins == 0 && gems == 0) { result.accept(false); return; } + */ + final JavaPlugin plug = _manager.getPlugin(); + + Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable() + { + @Override + public void run() + { + try (Connection connection = getConnection(); + CallableStatement callableStatement = connection.prepareCall("{call check_daily(?, ?, ?, ?, ?)}")) + { + callableStatement.setInt(1, accountId); + callableStatement.setInt(2, coins); + callableStatement.setInt(3, gems); + callableStatement.registerOutParameter(4, java.sql.Types.BOOLEAN); + callableStatement.registerOutParameter(5, java.sql.Types.TIMESTAMP); + + callableStatement.executeUpdate(); + + final boolean pass = callableStatement.getBoolean(4); + + final Timestamp timeStamp = callableStatement.getTimestamp(5); + + _manager.Get(player).getRecord().update(); + + Bukkit.getScheduler().runTask(plug, new Runnable() + { + @Override + public void run() + { + + if (pass) + { + _manager.Get(player).setDailyTime(new Timestamp(BonusManager.getSqlTime())); + result.run(true); + } + else + { + Recharge.Instance.use(player, "AttemptDailyBonus", 1000 * 10, false, false); + _manager.Get(player).setDailyTime(timeStamp); + result.run(false); + } + } + }); + } + catch (Exception e) + { + Recharge.Instance.use(player, "AttemptDailyBonus", 1000 * 30, false, false); + e.printStackTrace(); + result.run(false); + } + } + }); + } + + @Deprecated + public void giveTickets(final Player player, final Callback result) + { + final int accountId = _manager.getClientManager().Get(player).getAccountId(); + + Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + final int newTickets = jooq().update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.sub(-1)). + where(Tables.bonus.accountId.eq(accountId)).returning(Tables.bonus.tickets).fetchOne().getTickets(); + + Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + + + } + }); + + } + }); + } + + public void attemptRankBonus(final Player player, final Callback result) + { + if (!Recharge.Instance.usable(player, "AttemptRankBonus")) { + result.run(false); + return; + } + final int accountId = _manager.getClientManager().Get(player).getAccountId(); + final int coins = _manager.getRankBonusAmount(player).getCoins(); + + if (coins == 0/* && gems == 0 */) { + result.run(false); + return; + } + + final JavaPlugin plug = _manager.getPlugin(); + + Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable() { + + @Override + public void run() + { + + try (Connection connection = getConnection(); + CallableStatement callableStatement = connection.prepareCall("{call check_rank(?, ?, ?, ?, ?)}")) { + callableStatement.setInt(1, accountId); + callableStatement.setInt(2, coins); + callableStatement.setInt(3, 0); + callableStatement.registerOutParameter(4, java.sql.Types.BOOLEAN); + callableStatement.registerOutParameter(5, java.sql.Types.DATE); + + callableStatement.executeUpdate(); + + final boolean pass = callableStatement.getBoolean(4); + + final Date date = callableStatement.getDate(5); + + Bukkit.getScheduler().runTask(plug, new Runnable() { + + @Override + public void run() + { + _manager.Get(player).setRankTime(date); + + if (pass) + { + result.run(true); + } + else + { + Recharge.Instance.use(player, "AttemptRankBonus", 1000 * 10, false, false); + result.run(false); + } + } + }); + } catch (Exception e) { + Recharge.Instance.use(player, "AttemptRankBonus", 1000 * 30, false, false); + e.printStackTrace(); + result.run(false); + } + } + }); + } + + public void attemptVoteBonus(final Player player, final Callback result) + { + final int accountId = _manager.getClientManager().Get(player).getAccountId(); + final int coins = 0; + final int gems = 0; + + final JavaPlugin plug = _manager.getPlugin(); + + Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable() { + + @Override + public void run() + { + + try (Connection connection = getConnection(); + CallableStatement callableStatement = connection.prepareCall("{call check_vote(?, ?, ?, ?, ?)}")) { + callableStatement.setInt(1, accountId); + callableStatement.setInt(2, coins); + callableStatement.setInt(3, gems); + callableStatement.registerOutParameter(4, java.sql.Types.DATE); + + callableStatement.executeUpdate(); + + //final boolean pass = callableStatement.getBoolean(4); + + final Date date = callableStatement.getDate(4); + + Bukkit.getScheduler().runTask(plug, new Runnable() { + + @Override + public void run() + { + _manager.Get(player).setVoteTime(date); + result.run(true); + + } + }); + } catch (Exception e) { + e.printStackTrace(); + result.run(false); + } + } + }); + } + + public void getTimeOffset(final Callback callback) + { + final long startTime = System.currentTimeMillis(); + final Plugin plugin = _manager.getPlugin(); + + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() + { + executeQuery("SELECT CURRENT_TIMESTAMP", new ResultSetCallable() { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + resultSet.next(); + + long theirTimeUnadjusted = resultSet.getTimestamp(1).getTime(); + + long ourCurrentTime = System.currentTimeMillis(); + + long latencyOffset = (ourCurrentTime - startTime) / 2; + + long theirTime = theirTimeUnadjusted - latencyOffset; + + final long offSet = theirTime - ourCurrentTime; + + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() + { + callback.run(offSet); + } + }); + } + }); + } + }); + } + + @Override + protected void initialize() + { + executeUpdate(CREATE_BONUS_TABLE); + } + + @Override + protected void update() + { + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/StreakRecord.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/StreakRecord.java new file mode 100644 index 000000000..7757a2c8c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/StreakRecord.java @@ -0,0 +1,23 @@ +package mineplex.core.bonuses; + +public class StreakRecord +{ + private String _playerName; + private int _streak; + + public StreakRecord(String playerName, int streak) + { + _playerName = playerName; + _streak = streak; + } + + public String getPlayerName() + { + return _playerName; + } + + public int getStreak() + { + return _streak; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/VoteHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/VoteHandler.java new file mode 100644 index 000000000..4dec15845 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/VoteHandler.java @@ -0,0 +1,31 @@ +package mineplex.core.bonuses; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.votifier.VotifierCommand; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +public class VoteHandler implements CommandCallback +{ + private BonusManager _bonusManager; + + public VoteHandler(BonusManager bonusManager) + { + _bonusManager = bonusManager; + } + + @Override + public void run(ServerCommand command) + { + VotifierCommand v = ((VotifierCommand) command); + + Player player = UtilPlayer.searchExact(v.getPlayerName()); + + if (player != null) + { + _bonusManager.handleVote(player); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java new file mode 100644 index 000000000..160b2e14c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/animations/AnimationCarl.java @@ -0,0 +1,268 @@ +package mineplex.core.bonuses.animations; + +import java.util.Random; + +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.reward.RewardRarity; +import mineplex.core.treasure.animation.Animation; + +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +public class AnimationCarl extends Animation +{ + + private boolean _isDone; + private Block _creeper; + private long _startTime; + private Object _type; + private Player _player; + private Random _random = new Random(); + + public AnimationCarl(Entity creeper) + { + _creeper = creeper.getLocation().getBlock(); + } + + @Override + protected void tick() + { + if(_type instanceof String) + { + if(((String) _type).contentEquals("DAILY") || ((String) _type).contentEquals("POLL")) + { + for (int i = 50; i < 60; i++) + { + Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); + Item coin = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.DOUBLE_PLANT, (byte) 0, 1, " " + i)); + Vector vel = new Vector(Math.sin(i * 9/5d), 0, Math.cos(i * 9/5d)); + UtilAction.velocity(gem, vel, Math.abs(Math.sin(i * 12/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i * 12/3000d))*0.6, 1, false); + UtilAction.velocity(coin, vel, Math.abs(Math.sin(UtilMath.r(i) * 30/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 30/3000d))*0.6, 1, false); + coin.setTicksLived(1160); + gem.setTicksLived(1160); + } + } + if(((String) _type).contentEquals("RANK")) + { + for (int i = 50; i < 60; i++) + { + Item coin = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.DOUBLE_PLANT, (byte) 0, 1, " " + i)); + Vector vel = new Vector(Math.sin(UtilMath.r(i) * 7/5d), 0, Math.cos(UtilMath.r(i) * 7/5d)); + UtilAction.velocity(coin, vel, Math.abs(Math.sin(UtilMath.r(i) * 7/3000d)), false, 0, 0.2 + Math.abs(Math.cos(UtilMath.r(i) * 7/3000d))*0.6, 1, false); + coin.setTicksLived(1160); + } + } + if(!((String) _type).contentEquals("DAILY")&& !((String) _type).contentEquals("RANK")&& !((String) _type).contentEquals("POLL")) + { + + Item paper = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.PAPER, (byte) 0, 1, " " + 64)); + Vector vel = new Vector(Math.sin(64 * 8/5d), 0, Math.cos(64 * 8/5d)); + UtilAction.velocity(paper, vel, Math.abs(Math.sin(64 * 9/3000d)), false, 0, 0.2 + Math.abs(Math.cos(64 + 9/3000d))*0.6, 1, false); + paper.setTicksLived(1160); + for (int i = 50; i < 60; i++) + { + Item gem = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, " " + i)); + Vector velo = new Vector(Math.sin(i * 8/5d), 0, Math.cos(i * 8/5d)); + UtilAction.velocity(gem, velo, Math.abs(Math.sin(i * 8/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i + 8/3000d))*0.6, 1, false); + gem.setTicksLived(1160); + } + } + finish(); + } + if(_type instanceof Reward) + { + if(getTicks() == 0) + { + RewardData rewardData = ((Reward)_type).getFakeRewardData(_player); + ItemStack itemStack = rewardData.getDisplayItem(); + Item item = _creeper.getWorld().dropItem(_creeper.getLocation().add(0.5, 1.7, 0.5), itemStack); + + Vector vel = new Vector(_player.getLocation().getX() - _creeper.getLocation().getX(), 0, _player.getLocation().getZ() - _creeper.getLocation().getZ()); + + UtilAction.velocity(item, vel, 0.1, false, 0, 0.2 + 1*0.4, 1, false); + + item.setTicksLived(1160); + } + + if(((Reward)_type).getRarity() == RewardRarity.RARE) + { + RareAnimation(); + } + else if(((Reward)_type).getRarity() == RewardRarity.LEGENDARY) + { + LegendAnimation(); + } + else if(((Reward)_type).getRarity() == RewardRarity.MYTHICAL) + { + MythicalAnimation(); + } + else + { + finish(); + } + } + } + + @Override + protected void onFinish() { + _isDone = true; + setTicks(0); + } + + public boolean isDone() + { + return _isDone; + } + + public void setDone(boolean b) + { + _isDone = b; + } + + public void setTime(long time) + { + _startTime = time; + } + + public void setType(Object type) + { + _type = type; + } + + public void setPlayer(Player player) + { + _player = player; + } + + public void LegendAnimation() + { + if (getTicks() < 1) + { + UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.LIME, true, true); + } + + if (getTicks() == 1) + { + _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); + } + else if (getTicks() < 35) + { + double radius = 2 - (getTicks() / 10D * 2); + int particleAmount = 20 - (getTicks() * 2); + Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); + for (int i = 0; i < particleAmount; i++) + { + double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; + double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; + for(double e = 0.1 ; e < 3 ; e += 0.6) + { + Location location = _centerLocation.clone().add(xDiff, e, zDiff); + UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + } + } + } + else + { + finish(); + } + } + + public void MythicalAnimation() + { + if (getTicks() < 30) + { + UtilFirework.playFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true); + } + + if (getTicks() == 1) + { + _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.PORTAL_TRAVEL, 10F, 2.0F); + _creeper.getLocation().getWorld().playSound(_creeper.getLocation().add(0.5, 0.5, 0.5), Sound.ZOMBIE_UNFECT, 10F, 0.1F); + } + else if (getTicks() < 40) + { + UtilFirework.launchFirework(_creeper.getLocation().add(0.5, 0.5, 0.5), Type.BALL_LARGE, Color.RED, true, true, + new Vector((Math.random()-0.5)*0.05, 0.1, (Math.random()-0.5)*0.05), 1); + + //Particle Spiral Up + double radius = getTicks() / 20D; + int particleAmount = getTicks() / 2; + for (int i = 0; i < particleAmount; i++) + { + double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; + double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; + + Location location = _creeper.getLocation().add(0.5, 0, 0.5).clone().add(xDiff, -1.3, zDiff); + UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, + ViewDist.NORMAL, UtilServer.getPlayers()); + } + + Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); + for (int i = 0; i < particleAmount; i++) + { + double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; + double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; + for(double e = 0.1 ; e < 3 ; e += 0.5) + { + Location location = _centerLocation.clone().add(xDiff, e, zDiff); + UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + } + } + } + else + { + finish(); + } + } + + public void RareAnimation() + { + if (getTicks() == 1) + { + for(int i = 0; i < 3; i++) + { + UtilFirework.playFirework(_creeper.getLocation().add(0.5, i, 0.5), Type.BALL, Color.FUCHSIA, false, false); + } + _creeper.getWorld().playSound(_creeper.getLocation(), Sound.WITHER_SPAWN, 10F, 1.2F); + } + else if (getTicks() >= 60) + { + finish(); + } + + else if (getTicks() < 35) + { + double radius = 2 - (getTicks() / 10D * 2); + int particleAmount = 20 - (getTicks() * 2); + Location _centerLocation = _creeper.getLocation().add(0.5, 0.1, 0.5); + for (int i = 0; i < particleAmount; i++) + { + double xDiff = Math.sin(i/(double)particleAmount * 2 * Math.PI) * radius; + double zDiff = Math.cos(i/(double)particleAmount * 2 * Math.PI) * radius; + for(double e = 0.1 ; e < 3 ; e += 0.6) + { + Location location = _centerLocation.clone().add(xDiff, e, zDiff); + UtilParticle.PlayParticle(UtilParticle.ParticleType.WITCH_MAGIC, location, 0, 0, 0, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + } + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java new file mode 100644 index 000000000..c3356c9b7 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/AnimationCommand.java @@ -0,0 +1,37 @@ +package mineplex.core.bonuses.commands; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.reward.RewardType; +import mineplex.core.bonuses.BonusManager; + +public class AnimationCommand extends CommandBase{ + + private BonusManager _plugin; + + public AnimationCommand(BonusManager plugin) + { + super(plugin, Rank.DEVELOPER, "animation"); + _plugin = plugin; + } + + @Override + public void Execute(Player caller, String[] args) + { + + if(args != null) + { + caller = Bukkit.getPlayer(args[0]); + _plugin.addPendingExplosion(caller, _plugin.getRewardManager().nextReward(caller, null, false, RewardType.SpinnerFiller, true)); + } + if(args.length >= 2) + { + _plugin.addPendingExplosion(caller, args[1]); + } + + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java new file mode 100644 index 000000000..ccc55a251 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java @@ -0,0 +1,23 @@ +package mineplex.core.bonuses.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.gui.BonusGui; + +public class GuiCommand extends CommandBase{ + + public GuiCommand(BonusManager plugin) + { + super(plugin, Rank.DEVELOPER, "bonus"); + } + + @Override + public void Execute(Player caller, String[] args) + { + new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager()).openInventory(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java new file mode 100644 index 000000000..20aa7ad66 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java @@ -0,0 +1,54 @@ +package mineplex.core.bonuses.commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.bonuses.BonusManager; + +import org.bukkit.entity.Player; + +public class TicketCommand extends CommandBase +{ + public TicketCommand(BonusManager plugin) + { + super(plugin, Rank.DEVELOPER, "ticket"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args.length < 2) + { + UtilPlayer.message(caller, F.main("Carl", "Missing Args: " + F.elem("/ticket "))); + return; + } + + final String targetName = args[0]; + final String ticketString = args[1]; + Player target = UtilPlayer.searchExact(targetName); + + + rewardTickets(caller, target, target.getName(), ticketString); + } + + private void rewardTickets(final Player caller, final Player target, final String targetName, String ticketString) + { + try + { + int tickets = Integer.parseInt(ticketString); + Plugin.Get(target).setTickets(Plugin.Get(targetName).getTickets() + tickets); + + UtilPlayer.message(caller, F.main("Carl", "You gave " + F.elem(tickets + " Carl Tickets") + " to " + F.name(targetName) + ".")); + + if (target != null) + { + UtilPlayer.message(target, F.main("Carl", F.name(caller.getName()) + " gave you " + F.elem(tickets + " Carl Tickets") + ".")); + } + } + catch (Exception e) + { + UtilPlayer.message(caller, F.main("Carl", "Invalid Ticket Amount")); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/event/CarlSpinnerEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/event/CarlSpinnerEvent.java new file mode 100644 index 000000000..a07e1770e --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/event/CarlSpinnerEvent.java @@ -0,0 +1,54 @@ +package mineplex.core.bonuses.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player attempts to purchase a spin through carl + */ +public class CarlSpinnerEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private boolean _cancelled; + + public CarlSpinnerEvent(Player player) + { + _player = player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Player getPlayer() + { + return _player; + } + + public void setPlayer(Player player) + { + _player = player; + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public void setCancelled(boolean b) + { + _cancelled = b; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java new file mode 100644 index 000000000..e54887dc8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java @@ -0,0 +1,43 @@ +package mineplex.core.bonuses.gui; + +import mineplex.core.gui.SimpleGui; +import mineplex.core.reward.RewardManager; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.gui.buttons.CarlSpinButton; +import mineplex.core.bonuses.gui.buttons.DailyBonusButton; +import mineplex.core.bonuses.gui.buttons.PollButton; +import mineplex.core.bonuses.gui.buttons.RankBonusButton; +import mineplex.core.bonuses.gui.buttons.VoteButton; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class BonusGui extends SimpleGui +{ + + private BonusManager manager; + + public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager) + { + super(plugin, player, player.getName() + "'s Bonuses", 5 * 9); + + this.manager = manager; + + setItem(10, new VoteButton(plugin, player, this, manager)); + + setItem(12, new RankBonusButton(getPlugin(), player, this, manager)); + + setItem(14, new DailyBonusButton(getPlugin(), player, this, manager)); + + setItem(16, new PollButton(getPlugin(), player, manager.getPollManager(), manager.getClientManager(), this, manager)); + + setItem(31, new CarlSpinButton(getPlugin(), player, manager, rewardManager)); + } + + @Override + protected void finalize() throws Throwable + { + System.err.println("Deleting the MailboxGui!"); + super.finalize(); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java new file mode 100644 index 000000000..18310ab5a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java @@ -0,0 +1,281 @@ +package mineplex.core.bonuses.gui; + +import java.util.ArrayList; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.gui.DisplayItem; +import mineplex.core.gui.SimpleGui; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.reward.RewardManager; +import mineplex.core.reward.RewardRarity; +import mineplex.core.reward.RewardType; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.gui.buttons.RewardButton; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class SpinGui extends SimpleGui +{ + private static final int HOPPER_SLOT = 4; + private static final int CARL_SLOT = 22; + private static final int[] LINE_NUMS = { /*-27, -18,*/ -9, 9/*, 18*/ }; + + private int _tickCount; + private RewardData _rewardData; + private Reward _reward; + private BonusManager _manager; + private int _currentRewardIndex; + private int _ticksThisSwap; + private int _ticksPerSwap; + private int _swapCount; + private Reward[] _rewards; + private boolean _stopped; + private boolean _rewarded; + private ArrayList _ticks; + private int _frame; + private float _pitch; + private int _stopSpinnerAt; + + public SpinGui(Plugin plugin, Player player, RewardManager rewardManager, BonusManager manager) + { + super(plugin, player, "Carl's Spinner", 27); + + _manager = manager; + + ShopItem carlItem = new ShopItem(Material.SKULL_ITEM, (byte) 4, "Carl's Spinner", new String[] {ChatColor.RESET + "Good Luck!" }, 1, false, false); + + setItem(HOPPER_SLOT, new DisplayItem(new ItemStack(Material.HOPPER))); + //setItem(CARL_SLOT, new DisplayItem(carlItem)); + + + _ticks = new ArrayList<>(); + _frame = 0; + _pitch = 1; + + + + _ticksPerSwap = 1; + + for (int i=0 ; i<40 ; i++) + _ticks.add(1); + + for (int i=0 ; i<20 ; i++) + _ticks.add(2); + + for (int i=0 ; i<10 ; i++) + _ticks.add(4); + + for (int i=0 ; i<4 ; i++) + _ticks.add(6); + + for (int i=0 ; i<3 ; i++) + _ticks.add(8); + + if (Math.random() > 0.5) + { + _ticks.add(12); + } + + _stopSpinnerAt = _ticks.size(); + + //Create Rewards + _rewards = new Reward[_stopSpinnerAt+10]; //Adding 10, so theres items to the right still. + for (int i = 0; i < _stopSpinnerAt+10 ; i++) + { + if (i != _stopSpinnerAt + 4) + { + _rewards[i] = rewardManager.nextReward(player, null, false, RewardType.SpinnerFiller, true); + } + else + { + _rewards[i] = rewardManager.nextReward(player, null, false, RewardType.SpinnerReal, true); + _reward = _rewards[i]; + } + } + + _rewardData = _reward.giveReward("Carls Spinner", getPlayer()); + } + + private void tick() + { + + if(_stopped) + return; + + _ticksThisSwap++; + + // Swap + if (_ticksThisSwap >= _ticksPerSwap) + { + _ticksThisSwap = 0; + _swapCount++; + + if(_pitch == 1) + _pitch = (float) 1.5; + else if(_pitch == 1.5) + _pitch = 2; + else if(_pitch == 2) + _pitch = 1; + + getPlayer().playSound(getPlayer().getEyeLocation(), Sound.NOTE_PLING, 1, _pitch); + + _currentRewardIndex++; + + updateGui(); + + // Slow + _ticksPerSwap = _ticks.get(_currentRewardIndex - 1); + + if(_currentRewardIndex == _stopSpinnerAt) + _stopped = true; + + } + + _tickCount++; + } + + public void updateGui() + { + for (int i = 0; i < 9; i++) + { + int index = _currentRewardIndex + i; + + int slot = 9 + i; + RewardData data = _rewards[index].getFakeRewardData(getPlayer()); + setItem(slot, new RewardButton(data)); + + // Glass Panes + for (int j = 0; j < LINE_NUMS.length; j++) + { + int paneSlot = slot + LINE_NUMS[j]; + if (paneSlot == HOPPER_SLOT) + continue; + + setItem(paneSlot, new DisplayItem(data.getRarity().getItemStack())); + } + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + tick(); + checkIfDone(); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void close(InventoryCloseEvent event) + { + if(_rewarded) + return; + + if(event.getPlayer() != getPlayer()) + return; + + _manager.addPendingExplosion(getPlayer(), _reward); + + if (_reward.getRarity() == RewardRarity.RARE) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(event.getPlayer().getName()) + " won " + C.cPurple + "Rare " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else if (_reward.getRarity() == RewardRarity.LEGENDARY) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(event.getPlayer().getName()) + " won " + C.cGreen + "Legendary " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else if (_reward.getRarity() == RewardRarity.MYTHICAL) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(event.getPlayer().getName()) + " won " + C.cRed + "Mythical " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else + { + UtilPlayer.message(getPlayer(), F.main("Carl's Spinner", "You won " + _rewardData.getRarity().getColor() + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + } + + @EventHandler + public void Glass(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + return; + + if(!_stopped) + return; + + if(!_rewarded) + return; + + if(_frame == 0) + { + setItem(CARL_SLOT, new DisplayItem(_rewardData.getRarity().getItemStack())); + setItem(HOPPER_SLOT, new DisplayItem(_rewardData.getRarity().getItemStack())); + _frame++; + } + else if(_frame < 5) + { + setItem(HOPPER_SLOT + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + setItem(HOPPER_SLOT - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + + setItem(CARL_SLOT + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + setItem(CARL_SLOT - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + + setItem(13 + _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + setItem(13 - _frame, new DisplayItem(_rewardData.getRarity().getItemStack())); + _frame++; + } + if(_frame == 6) + { + + } + } + + public void checkIfDone() + { + if(!_stopped) + return; + + if(_rewarded) + return; + + _manager.addPendingExplosion(getPlayer(), _reward); + if (_reward.getRarity() == RewardRarity.RARE) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(getPlayer().getName()) + " won " + C.cPurple + "Rare " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else if (_reward.getRarity() == RewardRarity.LEGENDARY) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(getPlayer().getName()) + " won " + C.cGreen + "Legendary " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else if (_reward.getRarity() == RewardRarity.MYTHICAL) + { + Bukkit.broadcastMessage(F.main("Treasure", F.name(getPlayer().getName()) + " won " + C.cRed + "Mythical " + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + else + { + UtilPlayer.message(getPlayer(), F.main("Carl's Spinner", "You won " + _rewardData.getRarity().getColor() + _rewardData.getFriendlyName() + C.cGray + " from Carl's Spinner.")); + } + ItemStack item = getInventory().getItem(13); + getInventory().setItem(13, ItemStackFactory.Instance.CreateStack(item.getType(), (byte) 0, 1, _rewardData.getFriendlyName())); + _rewarded = true; + + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java new file mode 100644 index 000000000..006135c5d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/CarlSpinButton.java @@ -0,0 +1,85 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import mineplex.core.common.util.C; +import mineplex.core.gui.GuiItem; +import mineplex.core.reward.RewardManager; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.bonuses.BonusClientData; +import mineplex.core.bonuses.BonusManager; + +public class CarlSpinButton implements GuiItem +{ + private Plugin _plugin; + private Player _player; + private BonusManager _bonusManager; + private RewardManager _rewardManager; + + public CarlSpinButton(Plugin plugin, Player player, BonusManager bonusManager, RewardManager rewardManager) + { + _plugin = plugin; + _player = player; + _bonusManager = bonusManager; + _rewardManager = rewardManager; + } + + @Override + public void setup() + { + } + + @Override + public void close() + { + + } + + @Override + public void click(ClickType clickType) + { + BonusClientData client = _bonusManager.Get(_player); + int tickets = client.getTickets(); + + if (tickets > 0) + { + _bonusManager.attemptCarlSpin(_player); + } + +// new SpinGui(_plugin, _player, _rewardManager).openInventory(); + } + + @Override + public ItemStack getObject() + { + BonusClientData client = _bonusManager.Get(_player); + int tickets = client.getTickets(); + + String name = (tickets > 0 ? C.cGreen : C.cRed) + C.Bold + "Carl's Spinner"; + ArrayList lore = new ArrayList(); + Material material = Material.SKULL_ITEM; + byte data = (byte) 4; + + lore.add(" "); + if (tickets > 0) + { + lore.add(ChatColor.RESET + "Click to Spin"); + } + else + { + lore.add(ChatColor.RESET + "You need a Carl Spin Ticket to Spin"); + } + + lore.add(" "); + lore.add(ChatColor.YELLOW + "Your Tickets: " + C.cWhite + tickets); + + return new ShopItem(material, data, name, lore.toArray(new String[0]), 1, false, false); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java new file mode 100644 index 000000000..76d58c807 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java @@ -0,0 +1,211 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.gui.GuiItem; +import mineplex.core.gui.ItemRefresher; +import mineplex.core.gui.pages.LoadingWindow; +import mineplex.core.gui.pages.TimedMessageWindow; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.bonuses.BonusAmount; +import mineplex.core.bonuses.BonusClientData; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.StreakRecord; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class DailyBonusButton implements GuiItem, Listener +{ + + private ItemStack _item; + + private Player _player; + private Plugin _plugin; + private ItemRefresher _gui; + + private BonusManager _bonusManager; + + public DailyBonusButton(Plugin plugin, Player player, ItemRefresher gui, BonusManager bonusManager) + { + this._bonusManager = bonusManager; + this._player = player; + this._plugin = plugin; + this._gui = gui; + } + + @Override + public void setup() + { + Bukkit.getPluginManager().registerEvents(this, getPlugin()); + setItem(); + } + + @Override + public void close() + { + HandlerList.unregisterAll(this); + } + + @Override + public void click(ClickType clickType) + { + if (isAvailable()) { + _item = ItemStackFactory.Instance.CreateStack(Material.LAPIS_BLOCK, (byte)0, 1, ChatColor.BLUE + "Processing..."); + refreshItem(); + new LoadingWindow(getPlugin(), getPlayer(), 6*9); + _bonusManager.attemptDailyBonus(getPlayer(), _bonusManager.getDailyBonusAmount(_player), new Callback() { + @Override + public void run(Boolean t) + { + if (t) { + + setItem(); + + if (getPlayer().getOpenInventory() != null) { + new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.LIME.getData(), 1, ChatColor.GREEN + "Bonus collected!"), "Bonus collected!", 6*9, 20*3, getGui()).openInventory(); + } else { + UtilPlayer.message(getPlayer(), F.main("Bonus", "Bonus collected!")); + } + _bonusManager.addPendingExplosion(getPlayer(), "DAILY"); + getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); + } else { + if (getPlayer().getOpenInventory() != null) { + new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "Failed to collect bonus!"), "Failed to collect bonus!", 6*9, 20*3, getGui()).openInventory(); + } else { + UtilPlayer.message(getPlayer(), F.main("Bonus", "Failed to collect bonus!")); + } + getPlayer().playSound(getPlayer().getLocation(), Sound.ENDERDRAGON_GROWL, 1, 10); + } + getPlayer().closeInventory(); + } + }); + } else + getPlayer().playSound(getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 10); + return; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!event.getType().equals(UpdateType.SEC)) + return; +// refreshItem(); // Todo Unnecessary? + } + + private void setItem() + { + ArrayList lore = new ArrayList(); + Material material; + String itemName; + byte data = 0; + + if (isAvailable()) + { + material = Material.CHEST; + itemName = C.cGreen + C.Bold + "Daily Reward"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Click to Claim!"); + } + else + { + material = Material.REDSTONE_BLOCK; + itemName = C.cRed + C.Bold + "Daily Reward"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Next reward in " + UtilTime.convertString(timeLeft(), 0, TimeUnit.FIT) + "!"); + } + + lore.add(" "); + + BonusClientData client = _bonusManager.Get(_player); + + BonusAmount bonusAmount = _bonusManager.getDailyBonusAmount(_player); + bonusAmount.addLore(lore); + lore.add(" "); + + lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak()); + lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + _bonusManager.getDailyMultiplier(_player) + "%"); + lore.add(" "); + lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak()); + + if (client.getDailyTime() != null) + { + long lastBonus = _bonusManager.getLocalTime(client.getDailyTime().getTime()); + long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME); + + if (timeLeft > 0) + { + lore.add(C.cYellow + "Streak Reset: " + C.cWhite + UtilTime.convertString(timeLeft, 1, TimeUnit.FIT)); + } + } + + StreakRecord streakRecord = _bonusManager.getDailyStreak(); + if (streakRecord != null) + { + lore.add(" "); + lore.add(C.cYellow + "Record: " + C.cWhite + streakRecord.getPlayerName()); + lore.add(C.cYellow + "Streak: " + C.cWhite + streakRecord.getStreak()); + } + + + _item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false); + } + + @Override + public ItemStack getObject() + { + return _item; + } + + public void refreshItem() + { + getGui().refreshItem(this); + } + + public long timeLeft() + { + long timeLeft = _bonusManager.nextDailyBonus(getPlayer()) - System.currentTimeMillis(); + return timeLeft; + } + + public boolean isAvailable() + { + return (timeLeft() <= 0); + } + + public Plugin getPlugin() + { + return _plugin; + } + + public Player getPlayer() + { + return _player; + } + + public ItemRefresher getGui() + { + return _gui; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PollButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PollButton.java new file mode 100644 index 000000000..8124e6292 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PollButton.java @@ -0,0 +1,211 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; +import java.util.HashMap; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilText; +import mineplex.core.gui.GuiInventory; +import mineplex.core.gui.GuiItem; +import mineplex.core.gui.SimpleGui; +import mineplex.core.gui.SimpleGuiItem; +import mineplex.core.gui.botton.BackBotton; +import mineplex.core.gui.pages.TimedMessageWindow; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.poll.Poll; +import mineplex.core.poll.PollManager; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class PollButton extends SimpleGui implements GuiItem { + + protected boolean _create; + + private PollManager _pollManager; + private BonusManager _bonusManager; + private CoreClientManager _clientManager; + private GuiInventory _master; + + private HashMap hard = new HashMap(); + + private Poll _poll; + + public PollButton(Plugin plugin, Player player, PollManager pollManager, CoreClientManager clientManager, GuiInventory master, BonusManager bonusManager) + { + super(plugin, player, "Poll:", 6 * 9); + this._create = true; + this._master = master; + this._clientManager = clientManager; + this._pollManager = pollManager; + hard.put(0, new BackBotton(master)); + _bonusManager = bonusManager; + } + + @Override + public void setup() + { + if (_create) + { + this._poll = _pollManager.getNextPoll(_pollManager.Get(getPlayer()), _clientManager.Get(getPlayer()).GetRank()); + + if (_poll != null) + { + + setItem(13, getQuestionItem(_poll.getQuestion())); + + int[] slots = even(9, _poll.getAnswers().length); + + for (int i = 0; i < slots.length; i++) + { + AnswerItem item = new AnswerItem(_poll, i); + setItem(9 * 3 + slots[i], item); + } + } + } + } + + @Override + public ItemStack getObject() + { + ArrayList lore = new ArrayList<>(); + if (_poll == null) + { + lore.add(""); + lore.add(C.cWhite + "You've voted on all of the polls!"); + return ItemStackFactory.Instance.CreateStack(Material.REDSTONE_BLOCK, (byte) 0, 1, ChatColor.RED + C.Bold + "Vote on Poll", lore); + } + else + { + lore.add(""); + lore.add(C.cWhite + _poll.getQuestion()); + lore.add(""); + int i = 1; + for(String str : _poll.getAnswers()) + { + lore.add(C.cAqua + "" + i + ".) " + C.cWhite + str); + i++; + } + lore.add(""); + lore.add(C.cYellow + "Reward:" + C.cWhite + " 500 Gems"); + lore.add(""); + lore.add(C.cGreen + "Click to go to the vote page!"); + return ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, C.cGreen + C.Bold + "Vote on Poll", lore); + } + } + + @Override + public void click(ClickType clickType) + { + if (_poll == null) + { + getPlayer().playSound(getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 1.6f); + } + else + { + getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); + openInventory(); + } + } + + public GuiItem getQuestionItem(String question) + { + + ArrayList lore = new ArrayList<>(); + lore.add(""); + for (String string : wrap(question)) + lore.add(C.cWhite + string); + lore.add(""); + int i = 1; + for(String str : _poll.getAnswers()) + { + lore.add(C.cAqua + "" + i + ".) " + C.cWhite + str); + i++; + } + lore.add(""); + lore.add(C.cYellow + "Reward:" + C.cWhite + " 500 Gems"); + + return new SimpleGuiItem(ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, ChatColor.GREEN + C.cGreen + C.Bold + "Vote on Poll", + lore)); + } + + public static String[] wrap(String text) + { + return UtilText.wrap(text, 40); + } + + public static int[] even(int size, int amount) + { + int[] list = new int[amount]; + + float interval = (size / amount); + float offset = -(interval / 2); + + for (int i = 1; i <= amount; i++) + { + list[i - 1] = (int) (Math.ceil(i * interval) + offset); + } + return list; + } + + public Poll getPoll() + { + return _poll; + } + + public GuiInventory getMaster() + { + return _master; + } + + private class AnswerItem implements GuiItem + { + + private int num; + + private AnswerItem(Poll poll, int num) + { + this.num = num; + } + + @Override + public ItemStack getObject() + { + ArrayList lore = new ArrayList<>(); + lore.add(""); + lore.add(C.cWhite + getPoll().getAnswers()[num]); + return ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte) 0, 1, ChatColor.GREEN + "Option " + (num + 1), lore); + } + + @Override + public void click(ClickType clickType) + { + _create = true; + + _pollManager.answerPoll(getPlayer(), _poll, num); + + getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); + + new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.EMERALD_BLOCK, (byte) 0, 1, ChatColor.GREEN + "Your anwser:", wrap(getPoll().getAnswers()[num])), ChatColor.GREEN + "Moo", 6 * 9, 50, getMaster()).openInventory(); + _bonusManager.addPendingExplosion(getPlayer(), "POLL"); + getPlayer().closeInventory(); + } + + @Override + public void setup() {} + + @Override + public void close() {} + + } + + @Override + public void close() {} +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RankBonusButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RankBonusButton.java new file mode 100644 index 000000000..489b257fd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RankBonusButton.java @@ -0,0 +1,230 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.gui.GuiItem; +import mineplex.core.gui.ItemRefresher; +import mineplex.core.gui.pages.LoadingWindow; +import mineplex.core.gui.pages.TimedMessageWindow; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.bonuses.BonusAmount; +import mineplex.core.bonuses.BonusManager; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class RankBonusButton implements GuiItem, Listener { + + private boolean hasRank; + + private ItemStack _item; + + private Player _player; + private Plugin _plugin; + private ItemRefresher _gui; + + private BonusManager _bonusManager; + + public RankBonusButton(Plugin plugin, Player player, ItemRefresher gui, BonusManager bonusManager) + { + this._bonusManager = bonusManager; + this._player = player; + this._plugin = plugin; + this._gui = gui; + } + + @Override + public void setup() + { + if (_bonusManager.getRankBonusAmount(getPlayer()).isGreaterThanZero()) + { + this.hasRank = true; + Bukkit.getPluginManager().registerEvents(this, getPlugin()); + } + else + { + this.hasRank = false; + } + + setItem(); + } + + @Override + public void close() + { + HandlerList.unregisterAll(this); + } + + + @Override + public void click(ClickType clickType) + { + if (isAvailable()) { + _item = ItemStackFactory.Instance.CreateStack(Material.LAPIS_BLOCK, (byte)0, 1, ChatColor.BLUE + "Processing..."); + refreshItem(); + new LoadingWindow(getPlugin(), getPlayer(), 6*9); + _bonusManager.attemptRankBonus(getPlayer(), new Callback() + { + @Override + public void run(Boolean t) + { + setItem(); + + if (t) + { + if (getPlayer().getOpenInventory() != null) + { + new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.LIME.getData(), 1, ChatColor.GREEN + "Bonus collected!"), "Bonus collected!", 6 * 9, 20 * 3, getGui()).openInventory(); + } + else + { + UtilPlayer.message(getPlayer(), F.main("Bonus", "Bonus collected!")); + } + _bonusManager.addPendingExplosion(getPlayer(), "RANK"); + getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); + } + else + { + if (getPlayer().getOpenInventory() != null) + { + new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "Failed to collect bonus!"), "Failed to collect bonus!", 6 * 9, 20 * 3, getGui()).openInventory(); + } + else + { + UtilPlayer.message(getPlayer(), F.main("Bonus", "Failed to collect bonus!")); + } + getPlayer().playSound(getPlayer().getLocation(), Sound.ENDERDRAGON_GROWL, 1, 10); + } + getPlayer().closeInventory(); + } + }); + } else + getPlayer().playSound(getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 10); + return; + + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!event.getType().equals(UpdateType.SEC)) + return; +// refreshItem(); // Todo Unnecessary? + } + + @Override + public ItemStack getObject() + { + return _item; + } + + private void setItem() + { + ArrayList lore = new ArrayList(); + Material material; + String itemName; + byte data = 0; + + if (!hasRank) + { + material = Material.REDSTONE_BLOCK; + itemName = C.cRed + ChatColor.BOLD + "Rank Monthly Bonus"; + lore.add(" "); + lore.add(ChatColor.WHITE + "Players with a Rank get a Monthly Bonus!"); + lore.add(ChatColor.WHITE + ""); + lore.add(ChatColor.AQUA + "Ultra receives 7500 Coins Monthly"); + lore.add(ChatColor.LIGHT_PURPLE + "Hero receives 15000 Coins Monthly"); + lore.add(ChatColor.GREEN + "Legend receives 30000 Coins Monthly"); + lore.add(ChatColor.WHITE + ""); + lore.add(ChatColor.WHITE + "Purchase a Rank at;"); + lore.add(ChatColor.WHITE + "www.mineplex.com/shop"); + } + else + { + if (isAvailable()) + { + material = Material.ENDER_CHEST; + itemName = C.cGreen + C.Bold + "Rank Monthly Bonus"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Click to Claim!"); + } + else + { + material = Material.REDSTONE_BLOCK; + itemName = C.cRed + C.Bold + "Rank Monthly Bonus"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Next reward in " + UtilTime.convertString(timeLeft(), 0, TimeUnit.FIT) + "!"); + } + + lore.add(" "); + lore.add(C.cYellow + "Rank: " + C.cWhite + _bonusManager.getClientManager().Get(_player).GetRank().Name); + BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player); + bonusAmount.addLore(lore); + } + + _item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false); + } + + public void refreshItem() + { + _gui.refreshItem(this); + } + + public long timeLeft() + { + return _bonusManager.nextRankBonus(getPlayer()) - System.currentTimeMillis(); + } + + public boolean isAvailable() + { + if (!hasRank) + { + UtilPlayer.message(getPlayer(), "----------------------------------------"); + UtilPlayer.message(getPlayer(), ""); + UtilPlayer.message(getPlayer(), "Purchase a Rank at the Mineplex Shop:"); + UtilPlayer.message(getPlayer(), C.cGreen + "www.mineplex.com/shop"); + UtilPlayer.message(getPlayer(), ""); + UtilPlayer.message(getPlayer(), "----------------------------------------"); + + getPlayer().closeInventory(); + return false; + } + return (timeLeft() <= 0); + } + + public Plugin getPlugin() + { + return _plugin; + } + + public Player getPlayer() + { + return _player; + } + + public ItemRefresher getGui() + { + return _gui; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RewardButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RewardButton.java new file mode 100644 index 000000000..73ff6c9cc --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/RewardButton.java @@ -0,0 +1,46 @@ +package mineplex.core.bonuses.gui.buttons; + +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import mineplex.core.gui.GuiItem; +import mineplex.core.reward.RewardData; + +public class RewardButton implements GuiItem +{ + private RewardData _data; + + public RewardButton(RewardData data) + { + _data = data; + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + + @Override + public void click(ClickType clickType) + { + // Do nothing + } + + @Override + public ItemStack getObject() + { + ItemStack stack = _data.getDisplayItem(); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(_data.getFriendlyName()); + stack.setItemMeta(meta); + return stack; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java new file mode 100644 index 000000000..7b6118f70 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java @@ -0,0 +1,188 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; + +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.gui.GuiItem; +import mineplex.core.gui.ItemRefresher; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.bonuses.BonusAmount; +import mineplex.core.bonuses.BonusClientData; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.bonuses.StreakRecord; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class VoteButton implements GuiItem, Listener { + + private ItemStack _item; + + private String _url; + + private Player _player; + private Plugin _plugin; + private ItemRefresher _gui; + + private BonusManager _bonusManager; + + public VoteButton(Plugin plugin, Player player, ItemRefresher gui, BonusManager bonusManager) + { + this._bonusManager = bonusManager; + this._player = player; + this._plugin = plugin; + this._gui = gui; + } + + @Override + public void setup() + { + //TODO get url from db + _url = "http://minecraftservers.org/vote/121070"; + + setItem(); + Bukkit.getPluginManager().registerEvents(this, getPlugin()); + } + + @Override + public void close() + { + HandlerList.unregisterAll(this); + } + + @Override + public void click(ClickType clickType) + { + if (isAvailable()) + { + getPlayer().closeInventory(); + + getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f); + + UtilPlayer.message(getPlayer(), "----------------------------------------"); + UtilPlayer.message(getPlayer(), ""); + + new JsonMessage("Click to Open in Web Browser").click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer()); + new JsonMessage(C.cGreen + _url).click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer()); + + UtilPlayer.message(getPlayer(), ""); + UtilPlayer.message(getPlayer(), "----------------------------------------"); + + + + getPlayer().closeInventory(); + + } + else + { + getPlayer().playSound(getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 10); + } + } + + @Override + public ItemStack getObject() + { + return _item; + } + + private void setItem() + { + ArrayList lore = new ArrayList(); + Material material; + String itemName; + byte data = 0; + + if (isAvailable()) + { + material = Material.JUKEBOX; + itemName = C.cGreen + C.Bold + "Vote for Mineplex"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Click to Vote!"); + } + else + { + material = Material.REDSTONE_BLOCK; + itemName = C.cRed + C.Bold + "Vote for Mineplex"; + + lore.add(" "); + lore.add(ChatColor.RESET + "Next vote in " + UtilTime.convertString(timeLeft(), 0, TimeUnit.FIT) + "!"); + } + + lore.add(" "); + + BonusClientData client = _bonusManager.Get(_player); + + BonusAmount bonusAmount = _bonusManager.getVoteBonusAmount(_player); + bonusAmount.addLore(lore); + lore.add(" "); + + lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak()); + lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getVoteMultiplyer(client) + "%"); + if (client.getVoteTime() != null) + { + long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime()); + long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME); + + if (timeLeft > 0) + { + lore.add(C.cYellow + "Streak Reset: " + C.cWhite + UtilTime.convertString(timeLeft, 1, TimeUnit.FIT)); + } + } + + lore.add(" "); + lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak()); + + StreakRecord streakRecord = _bonusManager.getVoteStreak(); + if (streakRecord != null) + { + lore.add(" "); + lore.add(C.cYellow + "Record: " + C.cWhite + streakRecord.getPlayerName()); + lore.add(C.cYellow + "Streak: " + C.cWhite + streakRecord.getStreak()); + } + + _item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false); + } + + public long timeLeft() + { + return _bonusManager.nextVoteTime(getPlayer()) - System.currentTimeMillis(); + } + + public boolean isAvailable() + { + if (_url == null) + return false; + System.out.println(timeLeft()); + + return (timeLeft() <= 0); + } + + public Plugin getPlugin() + { + return _plugin; + } + + public Player getPlayer() + { + return _player; + } + + public ItemRefresher getGui() + { + return _gui; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index ca1a57c4b..2d083f5f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -13,6 +13,9 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.database.column.Column; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import org.jooq.DSLContext; +import org.jooq.SQLDialect; +import org.jooq.impl.DSL; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -61,6 +64,11 @@ public abstract class RepositoryBase implements Listener { return _dataSource; } + + protected DSLContext jooq() + { + return DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); + } /** * Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool! diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 3c518f35a..54a3ea799 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -92,7 +92,7 @@ public class GadgetManager extends MiniPlugin addGadget(new ItemTNT(this)); addGadget(new ItemMelonLauncher(this)); addGadget(new ItemFleshHook(this)); - //addGadget(new ItemPaintballGun(this)); + addGadget(new ItemPaintballGun(this)); addGadget(new ItemBatGun(this)); addGadget(new ItemCoinBomb(this)); addGadget(new ItemPaintbrush(this)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemPaintballGun.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemPaintballGun.java index 34d4ed557..e1b1b6c39 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemPaintballGun.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemPaintballGun.java @@ -61,45 +61,6 @@ public class ItemPaintballGun extends ItemGadget Location loc = event.getEntity().getLocation().add(event.getEntity().getVelocity()); loc.getWorld().playEffect(loc, Effect.STEP_SOUND, 49); - - byte color = 2; - double r = Math.random(); - if (r > 0.8) color = 4; - else if (r > 0.6) color = 5; - else if (r > 0.4) color = 9; - else if (r > 0.2) color = 14; - - for (Block block : UtilBlock.getInRadius(loc, 3d).keySet()) - { - if (block.getType() == Material.PORTAL) - return; - - if (block.getType() == Material.CACTUS) - return; - - if (block.getType() == Material.SUGAR_CANE_BLOCK) - return; - } - - List blocks = new ArrayList(); - blocks.addAll(UtilBlock.getInRadius(loc, 1.5d).keySet()); - - GadgetBlockEvent gadgetEvent = new GadgetBlockEvent(this, blocks); - Bukkit.getServer().getPluginManager().callEvent(gadgetEvent); - - if (gadgetEvent.isCancelled()) - return; - - for (Block block : gadgetEvent.getBlocks()) - { - if (!UtilBlock.solid(block)) - continue; - - if (block.getType() == Material.CARPET) - Manager.getBlockRestore().Add(block, 171, color, 4000); - else - Manager.getBlockRestore().Add(block, 35, color, 4000); - } } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/ClickExecutor.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/ClickExecutor.java new file mode 100644 index 000000000..18c9fbf2b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/ClickExecutor.java @@ -0,0 +1,8 @@ +package mineplex.core.gui; + +import org.bukkit.event.inventory.ClickType; + +public interface ClickExecutor +{ + public void click(ClickType clickType); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/Container.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/Container.java new file mode 100644 index 000000000..9ad939f28 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/Container.java @@ -0,0 +1,5 @@ +package mineplex.core.gui; + +public interface Container { + public T getObject(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/DisplayItem.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/DisplayItem.java new file mode 100644 index 000000000..87e844b1c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/DisplayItem.java @@ -0,0 +1,40 @@ +package mineplex.core.gui; + +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.gui.GuiItem; + +public class DisplayItem implements GuiItem +{ + private ItemStack _item; + + public DisplayItem(ItemStack item) + { + _item = item; + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + + @Override + public void click(ClickType clickType) + { + + } + + @Override + public ItemStack getObject() + { + return _item; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiInventory.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiInventory.java new file mode 100644 index 000000000..68d347477 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiInventory.java @@ -0,0 +1,9 @@ +package mineplex.core.gui; + +import org.bukkit.inventory.Inventory; + + +public interface GuiInventory { + public void openInventory(); + public Inventory getInventory(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiItem.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiItem.java new file mode 100644 index 000000000..cae592783 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/GuiItem.java @@ -0,0 +1,9 @@ +package mineplex.core.gui; + +import org.bukkit.inventory.ItemStack; + +public interface GuiItem extends ClickExecutor, Container +{ + public void setup(); + public void close(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/ItemRefresher.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/ItemRefresher.java new file mode 100644 index 000000000..e736a72bc --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/ItemRefresher.java @@ -0,0 +1,6 @@ +package mineplex.core.gui; + +public interface ItemRefresher extends GuiInventory +{ + public void refreshItem(GuiItem item); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGui.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGui.java new file mode 100644 index 000000000..0029d1864 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGui.java @@ -0,0 +1,241 @@ +package mineplex.core.gui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; + +import mineplex.core.common.util.UtilPlayer; + +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class SimpleGui implements ItemRefresher, Listener +{ +// private Map _buttonMap = new HashMap(); + private GuiItem[] _items; + + private Player _player; + private Plugin _plugin; + private int _size; + private String _title; + private Inventory _inv; + + public SimpleGui(Plugin plugin, Player player) + { + this(plugin, player, null, 0); + } + + public SimpleGui(Plugin plugin, Player player, int size) + { + this(plugin, player, null, size); + } + + public SimpleGui(Plugin plugin, Player player, String title) + { + this(plugin, player, title, 0); + } + + public SimpleGui(Plugin plugin, Player player, String title, int size) + { + + Validate.notNull(plugin, "The plugin cannot be null!"); + Validate.notNull(player, "The player cannot be null!"); + + this._plugin = plugin; + this._player = player; + + if (size == 0) + setSize(9); + else + setSize(size); + + if (title == null) + setTitle(" "); + else + setTitle(title); + + updateArray(); + + _inv = createInventory(); + refreshInventory(); + } + + private void updateArray() + { + _items = new GuiItem[_size]; + } + + public void setItem(int i, GuiItem item) + { + Validate.isTrue(i >= 0 && i < _size, "Tried to add a gui item outside of inventory range"); + + GuiItem oldItem = getItem(i); + if (oldItem != null) oldItem.close(); + + if (item != null) + { + _items[i] = item; + item.setup(); + } + + refreshItem(i); + } + + public GuiItem getItem(int i) + { + return _items[i]; + } + + @Override + public void openInventory() + { + refreshInventory(); + UtilPlayer.swapToInventory(_player, _inv); + Bukkit.getPluginManager().registerEvents(this, _plugin); + } + + public Inventory createInventory() + { + Inventory inv = Bukkit.createInventory(_player, getSize(), getTitle()); + return inv; + } + + public void refreshInventory() + { + for (int i = 0; i < _size; i++) + { + refreshItem(i); + } + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + if (!event.getWhoClicked().equals(_player) || !event.getInventory().equals(_inv)) + return; + + if (event.getSlot() >= 0 && event.getSlot() < _size) + { + GuiItem item = getItem(event.getSlot()); + if (item == null) + return; + + event.setCancelled(true); + + item.click(event.getClick()); + } + } + + @EventHandler + public void teleport(PlayerTeleportEvent event) + { + if (!event.getPlayer().equals(_player)) + return; + + close(); + } + + @EventHandler + public void inventoryClose(InventoryCloseEvent event) + { + if (!event.getPlayer().equals(_player)) + return; + + close(); + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + if (!event.getPlayer().equals(_player)) + return; + + close(); + } + + private void close() + { +// _inv = null; // TODO - do we really need to null the inventory? + HandlerList.unregisterAll(this); + + for (int i = 0; i < _size; i++) + { + GuiItem item = getItem(i); + if (item != null) item.close(); + } + } + + @Override + @Deprecated + public void refreshItem(GuiItem item) + { + if (_inv == null) + return; + + for (int i = 0; i < _size; i++) + { + if (item.equals(getItem(i))) + refreshItem(i); + } + } + + public void refreshItem(int slot) + { + GuiItem gi = getItem(slot); + + ItemStack itemStack = null; + if (gi != null) itemStack = gi.getObject(); + + _inv.setItem(slot, itemStack); + } + + public int getSize() + { + return _size; + } + + public String getTitle() + { + return _title; + } + + public Player getPlayer() + { + return _player; + } + + public Plugin getPlugin() + { + return _plugin; + } + + public void setTitle(String title) + { + this._title = title; + } + + @Override + public Inventory getInventory() + { + return _inv; + } + + public void setSize(int size) + { + Validate.isTrue(size % 9 == 0, "The size " + size + " is not divisible by 9"); + this._size = size; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGuiItem.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGuiItem.java new file mode 100644 index 000000000..187aa259f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/SimpleGuiItem.java @@ -0,0 +1,50 @@ +package mineplex.core.gui; + +import org.bukkit.Material; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +public class SimpleGuiItem extends ItemStack implements GuiItem { + + public SimpleGuiItem(Material type, int amount, short damage) + { + super(type, amount, damage); + } + + public SimpleGuiItem(Material type, int amount) + { + super(type, amount); + } + + public SimpleGuiItem(Material type) + { + super(type); + } + + public SimpleGuiItem(ItemStack itemStack) + { + super(itemStack); + } + + @Override + public void click(ClickType clickType) + { + } + + @Override + public ItemStack getObject() + { + return this; + } + + @Override + public void setup() + { + } + + @Override + public void close() + { + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/botton/BackBotton.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/botton/BackBotton.java new file mode 100644 index 000000000..4335408eb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/botton/BackBotton.java @@ -0,0 +1,36 @@ +package mineplex.core.gui.botton; + +import mineplex.core.gui.GuiInventory; +import mineplex.core.gui.SimpleGuiItem; +import mineplex.core.itemstack.ItemStackFactory; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +public class BackBotton extends SimpleGuiItem { + + private GuiInventory _gui; + + public BackBotton(GuiInventory gui) { + this(ItemStackFactory.Instance.CreateStack(Material.BED, (byte) 0, 1, ChatColor.DARK_GRAY + "<-- Go Back"), gui); + } + + public BackBotton(ItemStack itemStack, GuiInventory gui) + { + super(itemStack); + this._gui = gui; + } + + @Override + public void click(ClickType clickType) + { + getGui().openInventory(); + } + + public GuiInventory getGui() + { + return _gui; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java new file mode 100644 index 000000000..6398b4e6b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/LoadingWindow.java @@ -0,0 +1,238 @@ +package mineplex.core.gui.pages; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.itemstack.ItemStackFactory; + +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; + +public class LoadingWindow implements Runnable, Listener { + + public static String[] messages = new String[]{"Sending Carrier Pigeons...", "#BlameChiss", "Converting to Morse Code...", "Training monkeys..."}; + public static long defaultWait = 30; + + public ItemStack _background; + public ItemStack _barLoading; + public ItemStack _barBack; + + private Inventory _inv; + private final InventoryView _currentInventory; + + private final int _id; + + private final Plugin _plugin; + private final UUID _playersUUID; + + private String _message; + private String _title; + + private final int _size; + + private final int[] _activeRows; + + private long _ticker = 0; + + public LoadingWindow(Plugin plugin, Player player, int size) { + this(plugin, player, null, size, null, null); + } + + public LoadingWindow(Plugin plugin, Player player, long startTime, int size) { + this(plugin, player, startTime, size, null, null); + } + + public LoadingWindow(Plugin plugin, Player player, long startTime, int size, String message) + { + this(plugin, player, startTime, size, message, message); + } + + @SuppressWarnings("deprecation") + public LoadingWindow(Plugin plugin, Player player, Long startTime, int size, String title, String message) + { + Validate.notNull(plugin, "The plugin can not be null!"); + Validate.notNull(player, "The player can not be null!"); + + _currentInventory = player.getOpenInventory(); + + _size = size; + _activeRows = getActiveRows(size / 9); + + _plugin = plugin; + _playersUUID = player.getUniqueId(); + + + _background = ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.BLACK.getData(), 1, _message); + _barLoading = ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.LIME.getData(), 1, _message); + _barBack = ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.WHITE.getData(), 1, _message); + + + if (title == null && message == null) + { + String randomName = UtilMath.randomElement(messages); + title = randomName; + message = randomName; + } + else if (title == null) + { + title = " "; + } + else if (message == null) + { + message = UtilMath.randomElement(messages); + } + if (startTime == null) + startTime = defaultWait; + + + _title = title; + setMessage(message); + _id = Bukkit.getScheduler().runTaskTimer(plugin, this, startTime, 5).getTaskId(); + } + + public void setMessage(String message) { + _message = message; + ItemMeta im =_background.getItemMeta(); + im.setDisplayName(_message); + _background.setItemMeta(im); + _barBack.setItemMeta(im); + _barLoading.setItemMeta(im); + + setBackGround(); + setLoadingBarItems(); + } + + public void setTitle(String title) { + _title = title; + + Player player = Bukkit.getPlayer(_playersUUID); + if (_inv == null || player == null) + return; + + ItemStack[] con = _inv.getContents(); + + _inv = Bukkit.createInventory(null, _size, _title); + _inv.setContents(con); + UtilPlayer.swapToInventory(player, _inv); + } + + @EventHandler + public void onClick(InventoryClickEvent event) { + if (event.getWhoClicked().getUniqueId().equals(_playersUUID) && event.getInventory().equals(_inv)) { + event.setCancelled(true); + } + } + + @EventHandler + public void inventoryClose(InventoryCloseEvent event) { + if (event.getPlayer().getUniqueId().equals(_playersUUID) && event.getInventory().equals(_inv)) { + end(); + } + } + + @Override + public void run() + { + Player player = Bukkit.getPlayer(_playersUUID); + + if (player == null || _inv == null ? !player.getOpenInventory().equals(_currentInventory) : (_inv != null && !player.getOpenInventory().getTopInventory().equals(_inv))) { + end(); + return; + } + if (_inv == null) { + _inv = Bukkit.createInventory(null, _size, _title); + + setBackGround(); + setLoadingBarItems(); + UtilPlayer.swapToInventory(player, _inv); + Bukkit.getPluginManager().registerEvents(this, _plugin); + } else + setLoadingBarItems(); + + _ticker++; + } + + public void end() { + HandlerList.unregisterAll(this); + Bukkit.getScheduler().cancelTask(_id); + _inv = null; + } + + private void setBackGround() { + if (_inv == null) + return; + + List ignore = new ArrayList(); + + for (int row : _activeRows) { + + int rowStart = row * 9; + int rowEnd = rowStart + 9; + + for (int i = rowStart; i < rowEnd; i++) { + ignore.add(i); + } + } + + for (int i = 0; i < _size; i++) { + if (!ignore.contains(i)) + _inv.setItem(i, _background); + } + } + + private void setLoadingBarItems() { + if (_inv == null) + return; + ItemStack[] loadingBar = getLoadingBar(); + + for (int row : _activeRows) { + int rowStart = row * 9; + for (int i = 0; i < 9; i++) { + _inv.setItem(i + rowStart, loadingBar[i]); + } + } + } + + public ItemStack[] getLoadingBar() + { + ItemStack[] loadingBar = new ItemStack[9]; + + int barStart = (int) (_ticker % 9); + int barEnd = (barStart + 3) % 9; + + boolean endAfter = barEnd > barStart; + + for (int i = 0; i < loadingBar.length; i++) { + if (endAfter ? (i >= barStart && i < barEnd) : (i >= barStart || i < barEnd)) + loadingBar[i] = _barLoading; + else + loadingBar[i] = _barBack; + } + return loadingBar; + } + + private static int[] getActiveRows(int rows) + { + float mid = rows / 2.0f; + if (mid == (int) mid) + return new int[] { (int) mid , (int) mid -1}; + else + return new int[] { (int) Math.floor(mid)}; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/MessageWindow.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/MessageWindow.java new file mode 100644 index 000000000..d51bbcf79 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/MessageWindow.java @@ -0,0 +1,87 @@ +package mineplex.core.gui.pages; + +import java.util.UUID; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.gui.GuiInventory; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class MessageWindow implements Listener, GuiInventory { + + private UUID _playersUUID; + private Plugin _plugin; + private Inventory _inv; + + public MessageWindow(Plugin plugin, Player player, ItemStack is, String title, int size) + { + _plugin = plugin; + + this._playersUUID = player.getUniqueId(); + + _inv = Bukkit.createInventory(null, size, title); + + for (int i = 0; i < size; i++) { + _inv.setItem(i, is); + } + } + + @EventHandler(ignoreCancelled = true) + public void onClick(InventoryClickEvent e) + { + if (!e.getWhoClicked().getUniqueId().equals(_playersUUID)) + return; + e.setCancelled(true); + } + + @EventHandler + public void onClose(InventoryCloseEvent e) + { + if (!e.getPlayer().getUniqueId().equals(_playersUUID)) + return; + HandlerList.unregisterAll(this); + close(); + } + + @Override + public void openInventory() + { + Player player = Bukkit.getPlayer(_playersUUID); + + if (player == null || player.getOpenInventory().getTopInventory().equals(_inv)) + return; + + UtilPlayer.swapToInventory(player, _inv); + Bukkit.getPluginManager().registerEvents(this, _plugin); + open(); + } + + @Override + public Inventory getInventory() + { + return _inv; + } + public UUID getPlayersUUID() + { + return _playersUUID; + } + public Plugin getPlugin() + { + return _plugin; + } + public void open() { + + } + public void close() { + + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/TimedMessageWindow.java b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/TimedMessageWindow.java new file mode 100644 index 000000000..d84b3bdfa --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gui/pages/TimedMessageWindow.java @@ -0,0 +1,65 @@ +package mineplex.core.gui.pages; + +import mineplex.core.gui.GuiInventory; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +public class TimedMessageWindow extends MessageWindow implements Runnable { + private GuiInventory _gui; + private int _id; + private long _time; + + public TimedMessageWindow(Plugin plugin, Player player, ItemStack is, String title, int size, long time) + { + this(plugin, player, is, title, size, time, null); + } + + public TimedMessageWindow(Plugin plugin, Player player, ItemStack is, String title, int size, long time, GuiInventory gui) + { + super(plugin, player, is, title, size); + + this._gui = gui; + this._time = time; + } + + @Override + @EventHandler + public void onClick(InventoryClickEvent e) + { + super.onClick(e); + if (e.isCancelled() && _gui != null && (e.getWhoClicked() instanceof Player)) { + _gui.openInventory(); + } + } + + @Override + public void open() + { + this._id = Bukkit.getScheduler().runTaskLater(getPlugin(), this, _time).getTaskId(); + } + + @Override + public void close() + { + Bukkit.getScheduler().cancelTask(_id); + } + + @Override + public void run() + { + Player player = Bukkit.getPlayer(getPlayersUUID()); + if (player == null) + return; + + if (_gui != null) { + _gui.openInventory(); + } else + player.closeInventory(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java index 342d7b840..a2214adb2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/notifier/NotificationManager.java @@ -42,8 +42,8 @@ public class NotificationManager extends MiniPlugin if (!_enabled) return; -// if (event.getType() == UpdateType.MIN_08) -// hugeSale(); + if (event.getType() == UpdateType.MIN_08) + hugeSale(); // if (event.getType() == UpdateType.MIN_16) // sale(); @@ -95,17 +95,17 @@ public class NotificationManager extends MiniPlugin if (rank == Rank.ALL) { UtilPlayer.message(player, C.cWhite + " " + player.getName() + ", you can get 75% Off " + C.cAqua + C.Bold + "All Lifetime Ranks" + C.cWhite + "!"); - UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, available " + C.cRed + C.Line + "this weekend only" + C.cWhite + "!"); + UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, " + C.cRed + C.Line + "ends Sunday 16th" + C.cWhite + "!"); } else if (rank == Rank.ULTRA) { UtilPlayer.message(player, C.cWhite + " Hello " + player.getName() + ", upgrade to " + C.cPurple + C.Bold + "HERO RANK" + C.cWhite + " for only $7.50!"); - UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, available " + C.cRed + C.Line + "this weekend only" + C.cWhite + "!"); + UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, " + C.cRed + C.Line + "ends Sunday 16th" + C.cWhite + "!"); } else if (rank == Rank.HERO) { UtilPlayer.message(player, C.cWhite + " Hello " + player.getName() + ", upgrade to " + C.cGreen + C.Bold + "LEGEND RANK" + C.cWhite + " for only $7.50!"); - UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, available " + C.cRed + C.Line + "this weekend only" + C.cWhite + "!"); + UtilPlayer.message(player, C.cWhite + " This is our biggest sale ever, " + C.cRed + C.Line + "ends Sunday 16th" + C.cWhite + "!"); } UtilPlayer.message(player, " "); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java index e58b10020..d92a8690e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java @@ -161,6 +161,17 @@ public class NpcManager extends MiniPlugin return _npcMap.get(uuid); } + public Npc getNpcByName(String name) + { + for (Npc npc : _npcs) + { + if (npc.getDatabaseRecord().getName() != null && npc.getDatabaseRecord().getName().contains(name)) + return npc; + } + + return null; + } + public Npc getNpcByEntity(Entity entity) { if (entity == null) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java index dbf091299..8fe9045d6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/HostServerCommand.java @@ -12,7 +12,7 @@ public class HostServerCommand extends CommandBase { public HostServerCommand(PersonalServerManager plugin) { - super(plugin, Rank.LEGEND, "hostserver"); + super(plugin, Rank.LEGEND, "hostserver", "mps"); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java index 2030044e5..3896622be 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/personalServer/PersonalServerManager.java @@ -59,7 +59,6 @@ public class PersonalServerManager extends MiniPlugin { if (_giveInterfaceItem) { - event.getPlayer().getInventory().setItem(_interfaceSlot, _interfaceItem); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/DisplayType.java similarity index 91% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/DisplayType.java index 3045f5277..c593307e9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/DisplayType.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll; +package mineplex.core.poll; import mineplex.core.common.Rank; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PlayerPollData.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PlayerPollData.java similarity index 97% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/PlayerPollData.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/PlayerPollData.java index e0de0ec32..3465fae3b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PlayerPollData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PlayerPollData.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll; +package mineplex.core.poll; import mineplex.core.common.util.NautHashMap; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/Poll.java similarity index 95% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/Poll.java index 1998173ff..715b1f275 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/Poll.java @@ -1,6 +1,4 @@ -package mineplex.hub.poll; - -import mineplex.core.common.Rank; +package mineplex.core.poll; /** * Created by Shaun on 8/16/2014. diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java similarity index 96% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java index 8820efd46..fa0b5daa0 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll; +package mineplex.core.poll; import java.sql.ResultSet; import java.sql.SQLException; @@ -23,9 +23,7 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.hub.poll.command.PollCommand; +import mineplex.core.poll.command.PollCommand; public class PollManager extends MiniDbClientPlugin { @@ -64,7 +62,7 @@ public class PollManager extends MiniDbClientPlugin pollData.setPollCooldown(5000); } - @EventHandler + /*@EventHandler public void update(UpdateEvent event) { if (event.getType() != UpdateType.SLOW) @@ -88,7 +86,7 @@ public class PollManager extends MiniDbClientPlugin pollData.updatePollCooldown(); } } - } + }*/ public Poll getNextPoll(PlayerPollData pollData, Rank playerRank) { @@ -101,6 +99,11 @@ public class PollManager extends MiniDbClientPlugin return null; } + public boolean hasPoll(Player player) + { + return getNextPoll(Get(player), getClientManager().Get(player).GetRank()) != null; + } + public void displayPoll(Player player, Poll poll) { String[] answers = poll.getAnswers(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java similarity index 99% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java index e38e980ec..53884c66f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll; +package mineplex.core.poll; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollStats.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollStats.java similarity index 97% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollStats.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/PollStats.java index 591302c01..5f3ecdb2a 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollStats.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollStats.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll; +package mineplex.core.poll; /** * Created by Shaun on 8/26/2014. diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/command/PollCommand.java similarity index 96% rename from Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java rename to Plugins/Mineplex.Core/src/mineplex/core/poll/command/PollCommand.java index fe5997c79..bafdb1dbe 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/command/PollCommand.java @@ -1,4 +1,4 @@ -package mineplex.hub.poll.command; +package mineplex.core.poll.command; import java.text.DecimalFormat; import java.util.List; @@ -13,10 +13,10 @@ import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.hub.poll.PlayerPollData; -import mineplex.hub.poll.Poll; -import mineplex.hub.poll.PollManager; -import mineplex.hub.poll.PollStats; +import mineplex.core.poll.PlayerPollData; +import mineplex.core.poll.Poll; +import mineplex.core.poll.PollManager; +import mineplex.core.poll.PollStats; /** * Created by Shaun on 8/17/2014. diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java index 6a96dcd16..c69ab7bed 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java @@ -4,6 +4,19 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map.Entry; +import mineplex.core.MiniDbClientPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.NautHashMap; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilInv; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.preferences.command.PreferencesCommand; +import mineplex.core.preferences.ui.PreferencesShop; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -11,18 +24,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.MiniDbClientPlugin; -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.donation.DonationManager; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.preferences.command.PreferencesCommand; -import mineplex.core.preferences.ui.PreferencesShop; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; - public class PreferencesManager extends MiniDbClientPlugin { private PreferencesRepository _repository; @@ -53,6 +58,27 @@ public class PreferencesManager extends MiniDbClientPlugin _saveBuffer.put(caller.getUniqueId().toString(), Get(caller)); } + @EventHandler + public void givePlayerItem(PlayerJoinEvent event) + { + if (!GiveItem) + return; + + Player player = event.getPlayer(); + + if (!UtilGear.isMat(player.getInventory().getItem(8), Material.SKULL_ITEM)) + { + ItemStack item = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, ChatColor.RESET + C.cGreen + "My Profile"); + SkullMeta meta = ((SkullMeta) item.getItemMeta()); + meta.setOwner(player.getName()); + item.setItemMeta(meta); + + player.getInventory().setItem(8, item); + + UtilInv.Update(player); + } + } + @EventHandler public void storeBuffer(UpdateEvent event) { @@ -76,15 +102,6 @@ public class PreferencesManager extends MiniDbClientPlugin } }); } - - @EventHandler - public void givePlayerItem(PlayerJoinEvent event) - { - if (!GiveItem) - return; - - event.getPlayer().getInventory().setItem(8, ItemStackFactory.Instance.CreateStack(Material.REDSTONE_COMPARATOR.getId(), (byte)0, 1, ChatColor.GREEN + "/prefs")); - } @EventHandler(priority = EventPriority.LOWEST) public void playerInteract(PlayerInteractEvent event) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java index 67659dc64..3bd5e8202 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java @@ -27,6 +27,8 @@ public abstract class Reward protected abstract RewardData giveRewardCustom(Player player); + public abstract RewardData getFakeRewardData(Player player); + public abstract boolean canGiveReward(Player player); public RewardRarity getRarity() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java index 77f8b91e3..0a20e5ccf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java @@ -9,11 +9,13 @@ public class RewardData { private final String _friendlyName; private final ItemStack _displayItem; + private final RewardRarity _rarity; - public RewardData(String friendlyName, ItemStack displayItem) + public RewardData(String friendlyName, ItemStack displayItem, RewardRarity rarity) { _friendlyName = friendlyName; _displayItem = displayItem; + _rarity = rarity; } public String getFriendlyName() @@ -26,4 +28,9 @@ public class RewardData return _displayItem; } + public RewardRarity getRarity() + { + return _rarity; + } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java index 539e9e124..8932c3658 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java @@ -18,10 +18,13 @@ import mineplex.core.donation.DonationManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.pet.PetManager; import mineplex.core.reward.rewards.CoinReward; +import mineplex.core.reward.rewards.ExperienceReward; +import mineplex.core.reward.rewards.GemReward; import mineplex.core.reward.rewards.InventoryReward; import mineplex.core.reward.rewards.PetReward; import mineplex.core.reward.rewards.RankReward; import mineplex.core.reward.rewards.UnknownPackageReward; +import mineplex.core.stats.StatsManager; import mineplex.core.timing.TimingManager; public class RewardManager @@ -29,17 +32,18 @@ public class RewardManager private JavaPlugin _plugin; private HashMap> _treasureMap; private Random _random; - + private boolean _carlSpinner; + private CoreClientManager _clientManager; - + private boolean _doubleGadgetValue; - - public RewardManager(CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, - int commonValueMin, int commonValueMax, - int uncommonValueMin, int uncommonValueMax, - int rareValueMin, int rareValueMax, - int legendValueMin, int legendValueMax, - boolean doubleGadgetValue) + + public RewardManager(CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, + int commonValueMin, int commonValueMax, + int uncommonValueMin, int uncommonValueMax, + int rareValueMin, int rareValueMax, + int legendValueMin, int legendValueMax, + boolean doubleGadgetValue, boolean carlSpinner) { _plugin = donationManager.getPlugin(); _treasureMap = new HashMap>(); @@ -49,23 +53,33 @@ public class RewardManager { _treasureMap.put(rarity, new ArrayList()); } - - _clientManager = clientManager; - - _doubleGadgetValue = doubleGadgetValue; - addCommon(donationManager, inventoryManager, petManager, commonValueMin, commonValueMax); - addUncommon(donationManager, inventoryManager, petManager, uncommonValueMin, uncommonValueMax); - addRare(donationManager, inventoryManager, petManager, rareValueMin, rareValueMax); - addLegendary(donationManager, inventoryManager, petManager, legendValueMin, legendValueMax); + _clientManager = clientManager; + + _doubleGadgetValue = doubleGadgetValue; + _carlSpinner = carlSpinner; + + addCommon(donationManager, inventoryManager, petManager, statsManager, commonValueMin, commonValueMax); + addUncommon(donationManager, inventoryManager, petManager, statsManager, uncommonValueMin, uncommonValueMax); + addRare(donationManager, inventoryManager, petManager, statsManager, rareValueMin, rareValueMax); + addLegendary(donationManager, inventoryManager, petManager, statsManager, legendValueMin, legendValueMax); } - public void addCommon(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, double minValue, double maxValue) + public void addCommon(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, double minValue, double maxValue) { RewardRarity rarity = RewardRarity.COMMON; // Coins - addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 1, rarity)); + if (_carlSpinner) + { + addReward(new GemReward(donationManager, (int)minValue, (int)maxValue, 25, rarity)); + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 25, rarity)); + addReward(new ExperienceReward(statsManager, (int)minValue*5, (int)maxValue*5, 25, rarity)); + } + else + { + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 5, rarity)); + } //Increase Value if (_doubleGadgetValue) @@ -73,43 +87,54 @@ public class RewardManager minValue *= 2; maxValue *= 2; } - + // Gadgets addReward(new InventoryReward(inventoryManager, "Paintballs", "Paintball Gun", (int)(100*(minValue/500)), (int)(100*(maxValue/500)), new ItemStack(Material.GOLD_BARDING), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "Fireworks", "Fireworks", (int)(50*(minValue/500)), (int)(50*(maxValue/500)), new ItemStack(Material.FIREWORK), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "Melons", "Melon Launcher", (int)(50*(minValue/500)), (int)(50*(maxValue/500)), new ItemStack(Material.MELON_BLOCK), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "Flesh Hooks", "Flesh Hook", (int)(40*(minValue/500)), (int)(40*(maxValue/500)), new ItemStack(Material.getMaterial(131)), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "Pearls", "Ethereal Pearl", (int)(30*(minValue/500)), (int)(30*(maxValue/500)), new ItemStack(Material.ENDER_PEARL), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "Bat Swarms", "Bat Blaster", (int)(20*(minValue/500)), (int)(20*(maxValue/500)), new ItemStack(Material.IRON_BARDING), rarity, 10)); - + addReward(new InventoryReward(inventoryManager, "TNT", "TNT", (int)(20*(minValue/500)), (int)(20*(maxValue/500)), new ItemStack(Material.TNT), rarity, 10)); + + } - public void addUncommon(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, double minValue, double maxValue) + public void addUncommon(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, double minValue, double maxValue) { RewardRarity rarity = RewardRarity.UNCOMMON; // Coins - addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 250, RewardRarity.UNCOMMON)); + if (_carlSpinner) + { + addReward(new GemReward(donationManager, (int)minValue, (int)maxValue, 1200, rarity)); + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 1200, rarity)); + addReward(new ExperienceReward(statsManager, (int)minValue*5, (int)maxValue*5, 1200, rarity)); + } + else + { + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 250, RewardRarity.UNCOMMON)); + } //Increase Value if (_doubleGadgetValue) @@ -117,32 +142,32 @@ public class RewardManager minValue *= 2; maxValue *= 2; } - + // Gadgets addReward(new InventoryReward(inventoryManager, "Paintballs", "Paintball Gun", (int)(100*(minValue/500)), (int)(100*(maxValue/500)), new ItemStack(Material.GOLD_BARDING), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "Fireworks", "Fireworks", (int)(50*(minValue/500)), (int)(50*(maxValue/500)), new ItemStack(Material.FIREWORK), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "Melons", "Melon Launcher", (int)(50*(minValue/500)), (int)(50*(maxValue/500)), new ItemStack(Material.MELON_BLOCK), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "Flesh Hooks", "Flesh Hook", (int)(40*(minValue/500)), (int)(40*(maxValue/500)), new ItemStack(Material.getMaterial(131)), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "Pearls", "Ethereal Pearl", (int)(30*(minValue/500)), (int)(30*(maxValue/500)), new ItemStack(Material.ENDER_PEARL), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "Bat Swarms", "Bat Blaster", (int)(20*(minValue/500)), (int)(20*(maxValue/500)), new ItemStack(Material.IRON_BARDING), rarity, 250)); - + addReward(new InventoryReward(inventoryManager, "TNT", "TNT", (int)(20*(minValue/500)), (int)(20*(maxValue/500)), new ItemStack(Material.TNT), rarity, 250)); @@ -190,12 +215,22 @@ public class RewardManager new ItemStack(2267), rarity, 25)); } - public void addRare(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, double minValue, double maxValue) + public void addRare(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, double minValue, double maxValue) { RewardRarity rarity = RewardRarity.RARE; // Coins - addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 100, RewardRarity.RARE)); + if (_carlSpinner) + { + addReward(new GemReward(donationManager, (int)minValue, (int)maxValue, 150, rarity)); + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 150, rarity)); + addReward(new ExperienceReward(statsManager, (int)minValue*5, (int)maxValue*5, 150, rarity)); + } + else + { + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 100, RewardRarity.RARE)); + } + // Mounts addReward(new UnknownPackageReward(donationManager, "Mount Mule", "Mount Mule", @@ -216,7 +251,7 @@ public class RewardManager new ItemStack(Material.FEATHER), rarity, 50)); addReward(new UnknownPackageReward(donationManager, "Enderman Morph", "Enderman Morph", new ItemStack(Material.ENDER_PEARL), rarity, 33)); - + // Gadgets addReward(new InventoryReward(inventoryManager, "Coin Party Bomb", "Coin Party Bomb", 1, 1, @@ -239,15 +274,23 @@ public class RewardManager new ItemStack(Material.GOLD_LEGGINGS), rarity, 50)); addReward(new UnknownPackageReward(donationManager, "Space Boots", "Space Boots", new ItemStack(Material.GOLD_BOOTS), rarity, 50)); - } - public void addLegendary(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, double minValue, double maxValue) + public void addLegendary(DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, double minValue, double maxValue) { RewardRarity rarity = RewardRarity.LEGENDARY; // Coins - addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 25, RewardRarity.LEGENDARY)); + if (_carlSpinner) + { + addReward(new GemReward(donationManager, (int)minValue, (int)maxValue, 10, rarity)); + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 10, rarity)); + addReward(new ExperienceReward(statsManager, (int)minValue*5, (int)maxValue*5, 10, rarity)); + } + else + { + addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 25, rarity)); + } // Mounts addReward(new UnknownPackageReward(donationManager, "Infernal Horror", "Infernal Horror", @@ -276,6 +319,8 @@ public class RewardManager new ItemStack(Material.APPLE), rarity, 4)); addReward(new UnknownPackageReward(donationManager, "Heart Particles", "I Heart You", new ItemStack(Material.BLAZE_POWDER), rarity, 2)); + + } public void addReward(Reward reward) @@ -307,13 +352,13 @@ public class RewardManager { hasUncommon = true; } - + //Only allow 1 Mythical if (reward.getRarity().ordinal() >= RewardRarity.MYTHICAL.ordinal()) { canGiveMythical = false; } - + rewards[currentReward] = reward; currentReward++; } @@ -340,7 +385,7 @@ public class RewardManager public Reward nextReward(Player player, Reward[] excludedRewards, boolean requiresUncommon, RewardType type, boolean canGiveMythical) { RewardRarity rarity = type.generateRarity(requiresUncommon); - + //Dont give Rank Upgrade if already has Legend if (rarity == RewardRarity.MYTHICAL) { @@ -353,7 +398,7 @@ public class RewardManager return new RankReward(_clientManager, 0, rarity); } } - + List treasureList = _treasureMap.get(rarity); int totalWeight = 0; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java index fc186ed03..1f56de46a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRarity.java @@ -1,5 +1,9 @@ package mineplex.core.reward; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + import mineplex.core.common.util.C; import static mineplex.core.common.util.C.*; @@ -14,20 +18,31 @@ public enum RewardRarity * (Fireworks, sounds, etc) */ - OTHER("Other", cWhite), - COMMON("Common", cWhite), - UNCOMMON("Uncommon", cAqua), - RARE("Rare", cPurple), - LEGENDARY("Legendary", cGreen), - MYTHICAL("Mythical", cRed); + OTHER("Other", cWhite, Material.STAINED_GLASS_PANE, (byte) 0), + COMMON("Common", cWhite, Material.STAINED_GLASS_PANE, (byte) 0), + GAME("Game", cYellow, Material.STAINED_GLASS_PANE, (byte) 4), + UNCOMMON("Uncommon", cAqua, Material.STAINED_GLASS_PANE, (byte) 3), + RARE("Rare", cPurple, Material.STAINED_GLASS_PANE, (byte) 10), + LEGENDARY("Legendary", cGreen, Material.STAINED_GLASS_PANE, (byte) 5), + MYTHICAL("Mythical", cRed, Material.STAINED_GLASS_PANE, (byte) 14); private String _name; private String _color; + private Material _material; + private byte _data; + private ItemStack _stack; - RewardRarity(String name, String color) + RewardRarity(String name, String color, Material material, byte data) { _name = name; _color = color; + _material = material; + _data = data; + + _stack = new ItemStack(getMaterial(), 1, (short) 0, getData()); + ItemMeta meta = _stack.getItemMeta(); + meta.setDisplayName(_color + _name); + _stack.setItemMeta(meta); } public String getColor() @@ -40,4 +55,19 @@ public enum RewardRarity return _name; } + public Material getMaterial() + { + return _material; + } + + public byte getData() + { + return _data; + } + + public ItemStack getItemStack() + { + return _stack; + } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java index b40559d74..b226448c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java @@ -4,15 +4,19 @@ public enum RewardType { //% Chances Mythic Legend Rare Uncommon GameLoot( 0.000001, 0.00001, 0.0001, 3), + OldChest( 0, 0.05, 0.4, 5), AncientChest( 0, 1, 4, 25), - MythicalChest( 0.4, 3, 12, 75); + MythicalChest( 0.4, 3, 12, 75), + SpinnerFiller( 0.1, 1, 4, 20), + SpinnerReal( 0.000001, 0.05, 0.4, 5); + private double _mythicalChance; private double _legendaryChance; private double _rareChance; private double _uncommonChance; - + RewardType(double mythical, double legend, double rare, double uncommon) { _mythicalChance = (mythical / 100d); @@ -24,9 +28,9 @@ public enum RewardType public RewardRarity generateRarity(boolean requiresUncommon) { double rand = Math.random(); - + RewardRarity rarity = RewardRarity.COMMON; - + if (rand <= _mythicalChance) rarity = RewardRarity.MYTHICAL; else if (rand <= _legendaryChance) rarity = RewardRarity.LEGENDARY; else if (rand <= _rareChance) rarity = RewardRarity.RARE; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java index a0023e137..1bf59afb9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java @@ -37,7 +37,7 @@ public class CoinReward extends Reward @Override public RewardData giveRewardCustom(Player player) { - int gemsToReward = _random.nextInt(_maxCoinCount - _minCoinCount) + _minCoinCount; + int coinsToReward = _random.nextInt(_maxCoinCount - _minCoinCount) + _minCoinCount; _donationManager.RewardCoins(new Callback() { @@ -46,9 +46,15 @@ public class CoinReward extends Reward { } - }, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), gemsToReward); + }, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), coinsToReward); - return new RewardData(getRarity().getColor() + gemsToReward + " Coins", new ItemStack(175)); + return new RewardData(getRarity().getColor() + coinsToReward + " Coins", new ItemStack(175), getRarity()); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getColor() + "Coins", new ItemStack(175), getRarity()); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java new file mode 100644 index 000000000..a96245c6f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/ExperienceReward.java @@ -0,0 +1,52 @@ +package mineplex.core.reward.rewards; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.reward.RewardRarity; +import mineplex.core.stats.StatsManager; + +public class ExperienceReward extends Reward +{ + private StatsManager _statsManager; + private Random _random; + private int _minExperience; + private int _maxExperience; + + public ExperienceReward(StatsManager statsManager, int minExperience, int maxExperience, int weight, RewardRarity rarity) + { + super(rarity, weight); + + _statsManager = statsManager; + _random = new Random(); + _minExperience = minExperience; + _maxExperience = maxExperience; + } + + @Override + protected RewardData giveRewardCustom(Player player) + { + int experience = _random.nextInt(_maxExperience - _minExperience) + _minExperience; + + _statsManager.incrementStat(player, "Global.ExpEarned", experience); + + return new RewardData(getRarity().getColor() + experience + " Experience", new ItemStack(Material.EXP_BOTTLE), RewardRarity.GAME); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getColor() + "Experience", new ItemStack(Material.EXP_BOTTLE), RewardRarity.GAME); + } + + @Override + public boolean canGiveReward(Player player) + { + return true; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java new file mode 100644 index 000000000..26e695abb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GemReward.java @@ -0,0 +1,75 @@ +package mineplex.core.reward.rewards; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.reward.RewardManager; +import mineplex.core.reward.RewardRarity; + +public class GemReward extends Reward +{ + private DonationManager _donationManager; + private Random _random; + private int _minGemCount; + private int _maxGemCount; + + public GemReward(DonationManager donationManager, int minGemCount, int maxGemCount, int weight, RewardRarity rarity) + { + this(donationManager, minGemCount, maxGemCount, weight, rarity, RANDOM); + } + + public GemReward(DonationManager donationManager, int minGemCount, int maxGemCount, int weight, RewardRarity rarity, Random random) + { + super(rarity, weight); + _donationManager = donationManager; + _minGemCount = minGemCount; + _maxGemCount = maxGemCount; + + _random = random; + } + + @Override + public RewardData giveRewardCustom(Player player) + { + int GemsToReward = _random.nextInt(_maxGemCount - _minGemCount) + _minGemCount; + + _donationManager.RewardGems(new Callback() + { + @Override + public void run(Boolean data) + { + + } + }, "Treasure Chest", player.getName(), player.getUniqueId(), GemsToReward); + + return new RewardData(getRarity().getColor() + GemsToReward + " Gems", new ItemStack(Material.EMERALD), getRarity()); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getColor() + "Gems", new ItemStack(Material.EMERALD), getRarity()); + } + + @Override + public boolean canGiveReward(Player player) + { + return true; + } + + @Override + public boolean equals(Object obj) + { + if (obj instanceof GemReward) + return true; + + return false; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java index 83c219e1c..0eb1504e0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/InventoryReward.java @@ -59,7 +59,13 @@ public class InventoryReward extends Reward _inventoryManager.addItemToInventory(player, "Item", _packageName, amountToGive); - return new RewardData(getRarity().getColor() + amountToGive + " " + _name, _itemStack); + return new RewardData(getRarity().getColor() + amountToGive + " " + _name, _itemStack, getRarity()); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getColor() + _name, _itemStack, getRarity()); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java index 815edb705..6c3ce1a6a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/RankReward.java @@ -33,12 +33,26 @@ public class RankReward extends Reward else if (_clientManager.Get(player).GetRank() == Rank.HERO) rank = Rank.LEGEND; if (rank == null) - return new RewardData(getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER)); + return new RewardData(getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER), getRarity()); _clientManager.Get(player).SetRank(rank); _clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), rank, true); - return new RewardData(getRarity().getColor() + rank.Name + " Rank", new ItemStack(Material.NETHER_STAR)); + return new RewardData(getRarity().getColor() + rank.Name + " Rank", new ItemStack(Material.NETHER_STAR), getRarity()); + } + + @Override + public RewardData getFakeRewardData(Player player) + { + Rank rank = null; + if (_clientManager.Get(player).GetRank() == Rank.ALL) rank = Rank.ULTRA; + else if (_clientManager.Get(player).GetRank() == Rank.ULTRA) rank = Rank.HERO; + else if (_clientManager.Get(player).GetRank() == Rank.HERO) rank = Rank.LEGEND; + + if (rank == null) + return new RewardData(getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER), getRarity()); + + return new RewardData(getRarity().getColor() + rank.Name + " Rank", new ItemStack(Material.NETHER_STAR), getRarity()); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java index 6e041ee9b..af27a817e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java @@ -33,7 +33,7 @@ public class UnknownPackageReward extends Reward { _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _packageName, true, 0, true); - return new RewardData(getRarity().getColor() + _name, _itemStack); + return new RewardData(getRarity().getColor() + _name, _itemStack, getRarity()); } @Override @@ -48,6 +48,12 @@ public class UnknownPackageReward extends Reward return !_donationManager.Get(player.getName()).OwnsUnknownPackage(_packageName); } + @Override + public RewardData getFakeRewardData(Player player) + { + return new RewardData(getRarity().getColor() + _name, _itemStack, getRarity()); + } + protected String getPackageName() { return _packageName; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index 39de66bf0..fbd14ea54 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -20,6 +20,7 @@ import mineplex.core.pet.PetManager; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardManager; import mineplex.core.reward.RewardType; +import mineplex.core.stats.StatsManager; /** * Created by Shaun on 8/27/2014. @@ -32,19 +33,19 @@ public class TreasureManager extends MiniPlugin private HologramManager _hologramManager; private List _treasureLocations; - public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager) + public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager, StatsManager statsManager) { super("Treasure", plugin); _inventoryManager = inventoryManager; _blockRestore = blockRestore; _hologramManager = hologramManager; - _rewardManager = new RewardManager(clientManager, donationManager, inventoryManager, petManager, + _rewardManager = new RewardManager(clientManager, donationManager, _inventoryManager, petManager, statsManager, 100, 250, 500, 1000, 4000, 6000, 12000, 32000, - true); + true, false); World world = Bukkit.getWorlds().get(0); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java index c3fbe6e62..a6b986660 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/Animation.java @@ -16,6 +16,8 @@ public abstract class Animation _treasure = treasure; _running = true; } + + public Animation() {} public void run() { @@ -50,5 +52,15 @@ public abstract class Animation { return _treasure; } + + public void setRunning(boolean b) + { + _running = b; + } + + public void setTicks(int ticks) + { + _ticks = ticks; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/votifier/VotifierCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/votifier/VotifierCommand.java new file mode 100644 index 000000000..0d8454d2d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/votifier/VotifierCommand.java @@ -0,0 +1,23 @@ +package mineplex.core.votifier; + +import java.util.UUID; + +import mineplex.serverdata.commands.ServerCommand; + +public class VotifierCommand extends ServerCommand +{ + private String _playerName; + + public VotifierCommand(String playerName, String... targetServer) + { + super(targetServer); + + _playerName = playerName; + } + + public String getPlayerName() + { + return _playerName; + } + +} diff --git a/Plugins/Mineplex.Database/src/mineplex/database/tables/Bonus.java b/Plugins/Mineplex.Database/src/mineplex/database/tables/Bonus.java index 93914d875..4547730a3 100644 --- a/Plugins/Mineplex.Database/src/mineplex/database/tables/Bonus.java +++ b/Plugins/Mineplex.Database/src/mineplex/database/tables/Bonus.java @@ -16,7 +16,7 @@ package mineplex.database.tables; @java.lang.SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Bonus extends org.jooq.impl.TableImpl implements java.io.Serializable, java.lang.Cloneable { - private static final long serialVersionUID = -524321170; + private static final long serialVersionUID = -384307684; /** * The reference instance of Account.bonus @@ -54,27 +54,27 @@ public class Bonus extends org.jooq.impl.TableImplAccount.bonus.dailyStreak. */ - public final org.jooq.TableField dailyStreak = createField("dailyStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final org.jooq.TableField dailyStreak = createField("dailyStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, ""); /** * The column Account.bonus.maxDailyStreak. */ - public final org.jooq.TableField maxDailyStreak = createField("maxDailyStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final org.jooq.TableField maxDailyStreak = createField("maxDailyStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, ""); /** * The column Account.bonus.voteStreak. */ - public final org.jooq.TableField voteStreak = createField("voteStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final org.jooq.TableField voteStreak = createField("voteStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, ""); /** * The column Account.bonus.maxVoteStreak. */ - public final org.jooq.TableField maxVoteStreak = createField("maxVoteStreak", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final org.jooq.TableField maxVoteStreak = createField("maxVoteStreak", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, ""); /** * The column Account.bonus.tickets. */ - public final org.jooq.TableField tickets = createField("tickets", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, ""); + public final org.jooq.TableField tickets = createField("tickets", org.jooq.impl.SQLDataType.INTEGER.defaulted(true), this, ""); /** * Create a Account.bonus table reference diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index b0bc33c67..8890b8e4b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -31,6 +31,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.PartyManager; import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.pet.PetManager; +import mineplex.core.poll.PollManager; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; @@ -39,7 +40,6 @@ import mineplex.core.recharge.Recharge; import mineplex.core.resourcepack.ResUnloadCheck; import mineplex.core.resourcepack.ResPackManager; import mineplex.core.serverConfig.ServerConfiguration; -import mineplex.core.spawn.Spawn; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.task.TaskManager; @@ -49,7 +49,6 @@ import mineplex.core.updater.Updater; import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.hub.modules.StackerManager; -import mineplex.hub.poll.PollManager; import mineplex.hub.queue.QueueManager; import mineplex.hub.server.ServerManager; import mineplex.minecraft.game.classcombat.Class.ClassManager; @@ -67,26 +66,26 @@ import mineplex.minecraft.game.core.fire.Fire; public class Hub extends JavaPlugin implements IRelation { private String WEB_CONFIG = "webServer"; - - @Override + + @Override public void onEnable() { getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); saveConfig(); - + String webServerAddress = getConfig().getString(WEB_CONFIG); - + //Logger.initialize(this); - + //Velocity Fix new VelocityFix(this); - + //Static Modules CommandCenter.Initialize(this); CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); CommandCenter.Instance.setClientManager(clientManager); - + ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); @@ -95,7 +94,7 @@ public class Hub extends JavaPlugin implements IRelation DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress); new ServerConfiguration(this, clientManager); - + //Other Modules PacketHandler packetHandler = new PacketHandler(this); DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler); @@ -105,31 +104,32 @@ public class Hub extends JavaPlugin implements IRelation NpcManager npcManager = new NpcManager(this, creature); PetManager petManager = new PetManager(this, clientManager, donationManager, disguiseManager, creature, blockRestore, webServerAddress); PollManager pollManager = new PollManager(this, clientManager, donationManager); - + //Main Modules ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); - + Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); AntiHack.Initialize(this, punish, portal, preferenceManager, clientManager); - + IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal); - FriendManager friendManager = new FriendManager(this, clientManager, preferenceManager, portal); - + FriendManager friendManager = new FriendManager(this, clientManager, preferenceManager, portal); + StatsManager statsManager = new StatsManager(this, clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager); - + PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); - - HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this), packetHandler); + + PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); + HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this), npcManager, personalServerManager, packetHandler); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager); new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, new StackerManager(hubManager), queueManager); Chat chat = new Chat(this, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); - new MemoryFix(this); + new MemoryFix(this); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new CustomTagFix(this, packetHandler); new TablistFix(this); @@ -141,25 +141,23 @@ public class Hub extends JavaPlugin implements IRelation } }); //new Replay(this, packetHandler); - new PersonalServerManager(this, clientManager); - + AprilFoolsManager.Initialize(this, clientManager, disguiseManager); - + CombatManager combatManager = new CombatManager(this); - + ProjectileManager throwManager = new ProjectileManager(this); SkillConditionManager conditionManager = new SkillConditionManager(this); - + DamageManager damage = new DamageManager(this, combatManager, npcManager, disguiseManager, conditionManager); Fire fire = new Fire(this, conditionManager, damage); - Teleport teleport = new Teleport(this); + Teleport teleport = new Teleport(this); Energy energy = new Energy(this); energy.setEnabled(false); - + ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager, webServerAddress); SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy, webServerAddress); ClassManager classManager = new ClassManager(this, clientManager, donationManager, skillManager, itemFactory, webServerAddress); - classManager.setEnabled(false); ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index e1cf08feb..8d58d26b1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -3,6 +3,43 @@ package mineplex.hub; import java.util.ArrayList; import java.util.HashMap; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; +import org.bukkit.entity.Egg; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +import org.bukkit.event.server.ServerListPingEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; + import mineplex.core.MiniClientPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; @@ -30,23 +67,26 @@ import mineplex.core.gadget.event.GadgetActivateEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; -import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.message.PrivateMessageEvent; import mineplex.core.mount.MountManager; import mineplex.core.mount.event.MountActivateEvent; import mineplex.core.notifier.NotificationManager; +import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.pet.PetManager; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; +import mineplex.core.reward.RewardManager; import mineplex.core.stats.StatsManager; import mineplex.core.task.TaskManager; import mineplex.core.treasure.TreasureManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.bonuses.BonusManager; import mineplex.hub.commands.DisguiseCommand; import mineplex.hub.commands.ForcefieldRadius; import mineplex.hub.commands.GadgetToggle; @@ -61,7 +101,8 @@ import mineplex.hub.modules.ParkourManager; import mineplex.hub.modules.SoccerManager; import mineplex.hub.modules.TextManager; import mineplex.hub.modules.WorldManager; -import mineplex.hub.poll.PollManager; +import mineplex.core.poll.PollManager; +import mineplex.hub.profile.gui.GUIProfile; import mineplex.hub.tutorial.TutorialManager; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent; @@ -70,69 +111,35 @@ import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.entity.Egg; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Snowball; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerVelocityEvent; -import org.bukkit.event.server.ServerListPingEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; - public class HubManager extends MiniClientPlugin { // ☃❅ Snowman! public HubType Type = HubType.Normal; - + private BlockRestore _blockRestore; private CoreClientManager _clientManager; private ConditionManager _conditionManager; private DonationManager _donationManager; private DisguiseManager _disguiseManager; - private PartyManager _partyManager; - private ForcefieldManager _forcefieldManager; - private Portal _portal; - private StatsManager _statsManager; + private PartyManager _partyManager; + private ForcefieldManager _forcefieldManager; + private PollManager _pollManager; + private Portal _portal; + private StatsManager _statsManager; private GadgetManager _gadgetManager; private MountManager _mountManager; - private HubVisibilityManager _visibilityManager; - private TutorialManager _tutorialManager; + private HubVisibilityManager _visibilityManager; + private TutorialManager _tutorialManager; private TextManager _textCreator; - private ParkourManager _parkour; - private PreferencesManager _preferences; + private ParkourManager _parkour; + private PreferencesManager _preferences; private InventoryManager _inventoryManager; private NewsManager _news; private AchievementManager _achievementManager; private TreasureManager _treasureManager; private PetManager _petManager; private PacketHandler _packetHandler; + private PersonalServerManager _personalServerManager; private Location _spawn; private int _scoreboardTick = 0; @@ -140,17 +147,17 @@ public class HubManager extends MiniClientPlugin private HashMap _scoreboards = new HashMap(); private String _serverName = ""; - + private boolean _shuttingDown; private HashMap _portalTime = new HashMap(); - + private HashMap> _creativeAdmin = new HashMap>(); //Admin private boolean _gadgetsEnabled = true; - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, PacketHandler packetHandler) + public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler) { super("Hub Manager", plugin); @@ -159,7 +166,9 @@ public class HubManager extends MiniClientPlugin _conditionManager = conditionManager; _donationManager = donationManager; _disguiseManager = disguiseManager; - + _pollManager = pollManager; + _personalServerManager = personalServerManager; + _portal = portal; _spawn = new Location(UtilWorld.getWorld("world"), 0.5, 74, 0.5); @@ -172,41 +181,46 @@ public class HubManager extends MiniClientPlugin new WorldManager(this); new JumpManager(this); //new TournamentInviter(this); - - + + _news = new NewsManager(this); _mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager); _inventoryManager = new InventoryManager(plugin, clientManager); new BenefitManager(plugin, clientManager, _inventoryManager); _gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager); - _treasureManager = new TreasureManager(_plugin, clientManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager); + + _treasureManager = new TreasureManager(_plugin, clientManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager, statsManager); new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager); new SoccerManager(this, _gadgetManager); new KothManager(this, _gadgetManager); - + _petManager = petManager; _partyManager = partyManager; _preferences = preferences; _tutorialManager = new TutorialManager(this, donationManager, taskManager, _textCreator); _visibilityManager = new HubVisibilityManager(this); - + _forcefieldManager = new ForcefieldManager(this); addCommand(new ForcefieldRadius(_forcefieldManager)); - + _statsManager = statsManager; _achievementManager = achievementManager; _achievementManager.setGiveInterfaceItem(true); _packetHandler = packetHandler; - + new NotificationManager(getPlugin(), clientManager); ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; + + new BonusManager(plugin, clientManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager); + + // NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager); // new MailManager(_plugin, notificationManager); - + _serverName = getPlugin().getConfig().getString("serverstatus.name"); _serverName = _serverName.substring(0, Math.min(16, _serverName.length())); } @@ -228,7 +242,7 @@ public class HubManager extends MiniClientPlugin event.setMotd("Restarting soon"); } } - + public boolean BumpDisabled(Entity ent) { if (ent == null) @@ -238,54 +252,54 @@ public class HubManager extends MiniClientPlugin { return !_preferences.Get((Player)ent).HubGames; } - + return true; } - + @EventHandler public void SnowballPickup(BlockDamageEvent event) { if (Type != HubType.Christmas) return; - + if (event.getBlock().getType() != Material.SNOW) return; - + Player player = event.getPlayer(); - + _gadgetManager.RemoveItem(player); - + player.getInventory().setItem(3, new ItemStack(Material.SNOW_BALL, 16)); } - + @EventHandler public void SnowballHit(CustomDamageEvent event) { if (Type != HubType.Christmas) return; - + Projectile proj = event.GetProjectile(); if (proj == null) return; if (!(proj instanceof Snowball)) return; - + event.SetCancelled("Snowball Cancel"); - + if (BumpDisabled(event.GetDamageeEntity())) return; - + if (BumpDisabled(event.GetDamagerEntity(true))) return; - - UtilAction.velocity(event.GetDamageeEntity(), UtilAlg.getTrajectory2d(event.GetDamagerEntity(true), event.GetDamageeEntity()), + + UtilAction.velocity(event.GetDamageeEntity(), UtilAlg.getTrajectory2d(event.GetDamagerEntity(true), event.GetDamageeEntity()), 0.4, false, 0, 0.2, 1, false); - + //No Portal SetPortalDelay(event.GetDamageeEntity()); } - + @EventHandler public void redirectStopCommand(PlayerCommandPreprocessEvent event) { @@ -380,7 +394,7 @@ public class HubManager extends MiniClientPlugin else event.getPlayer().setOp(false); } - + @EventHandler public void PlayerRespawn(PlayerRespawnEvent event) { @@ -399,29 +413,29 @@ public class HubManager extends MiniClientPlugin //Public Message event.setJoinMessage(null); - + // if (_clientManager.Get(player).GetRank() != Rank.LEGEND) // event.setJoinMessage(null); // else // { // event.setJoinMessage(C.cGreen + C.Bold + "Legend " + playerName + " has joined!"); // } - + //Teleport player.teleport(GetSpawn().add(0, 10, 0)); - + //Survival player.setGameMode(GameMode.SURVIVAL); - + //Clear Inv UtilInv.Clear(player); - + //Allow Double Jump player.setAllowFlight(true); - + //Health player.setHealth(20); - + //Scoreboard Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); player.setScoreboard(board); @@ -480,7 +494,7 @@ public class HubManager extends MiniClientPlugin _portalTime.remove(event.getPlayer().getName()); } - + @EventHandler public void playerPrivateMessage(PrivateMessageEvent event) { @@ -497,7 +511,7 @@ public class HubManager extends MiniClientPlugin { if (event.isCancelled()) return; - + //Dont Let Chat Near Spawn! if (UtilMath.offset2d(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).GetRank().Has(Rank.HELPER)) { @@ -505,16 +519,16 @@ public class HubManager extends MiniClientPlugin event.setCancelled(true); return; } - + Player player = event.getPlayer(); String playerName = player.getName(); - + // April Fools if (AprilFoolsManager.Instance.isActive()) playerName = AprilFoolsManager.Instance.getName(player); Rank rank = GetClients().Get(player).GetRank(); - + if(GetClients().Get(player).isDisguised()) rank = GetClients().Get(player).getDisguisedRank(); @@ -522,7 +536,7 @@ public class HubManager extends MiniClientPlugin //Level Prefix String levelStr = _achievementManager.getMineplexLevel(player, rank); - + //Rank Prefix String rankStr = ""; if (rank != Rank.ALL) @@ -557,7 +571,7 @@ public class HubManager extends MiniClientPlugin } return; - } + } else { for (Player other : UtilServer.getPlayers()) @@ -599,7 +613,7 @@ public class HubManager extends MiniClientPlugin event.getEntity().setHealth(20); event.getEntity().teleport(GetSpawn()); } - + @EventHandler public void combatDeath(CombatDeathEvent event) { @@ -688,14 +702,14 @@ public class HubManager extends MiniClientPlugin obj.setDisplayName(C.cWhite + C.Bold + Get(player).GetScoreboardText()); int line = 15; - + //Stacker obj.getScore(C.cAqua + C.Bold + "Server").setScore(line--); obj.getScore(_serverName).setScore(line--); - + //Space obj.getScore(" ").setScore(line--); - + //Gems obj.getScore(C.cGreen + C.Bold + "Gems").setScore(line--); // Remove Old/Add New @@ -711,16 +725,16 @@ public class HubManager extends MiniClientPlugin // Remove Old player.getScoreboard().resetScores(Get(player.getName()).GetLastCoinCount() + ""); - // Add New + // Add New obj.getScore(GetDonation().Get(player.getName()).getCoins() + "").setScore(line--); Get(player.getName()).SetLastCoinCount(GetDonation().Get(player.getName()).getCoins()); - + //Space obj.getScore(" ").setScore(line--); - - + + //Display Rank obj.getScore(C.cGold + C.Bold + "Rank").setScore(line--); if (GetClients().Get(player).GetRank().Has(Rank.ULTRA)) @@ -733,7 +747,7 @@ public class HubManager extends MiniClientPlugin obj.getScore("Single Ultra").setScore(line--); else obj.getScore("No Rank").setScore(line--); - + //Space obj.getScore(" ").setScore(line--); @@ -800,12 +814,12 @@ public class HubManager extends MiniClientPlugin { return _preferences; } - + public Location GetSpawn() { return _spawn.clone(); } - + public PetManager getPetManager() { return _petManager; @@ -825,7 +839,7 @@ public class HubManager extends MiniClientPlugin { return _visibilityManager; } - + @EventHandler(priority = EventPriority.MONITOR) public void gadgetCollide(GadgetCollideEntityEvent event) { @@ -883,7 +897,7 @@ public class HubManager extends MiniClientPlugin return _gadgetsEnabled; } - + public NewsManager GetNewsManager() { return _news; @@ -901,24 +915,24 @@ public class HubManager extends MiniClientPlugin public void ToggleGadget(Player caller) { _gadgetsEnabled = !_gadgetsEnabled; - + if (!_gadgetsEnabled) { GetMount().DisableAll(); GetGadget().DisableAll(); } - + for (Player player : UtilServer.getPlayers()) player.sendMessage(C.cWhite + C.Bold + "Gadgets/Mounts are now " + F.elem(_gadgetsEnabled ? C.cGreen + C.Bold + "Enabled" : C.cRed + C.Bold + "Disabled")); } - + @EventHandler public void GadgetActivate(GadgetActivateEvent event) { if (!_gadgetsEnabled) event.setCancelled(true); } - + @EventHandler public void MountActivate(MountActivateEvent event) { @@ -930,7 +944,7 @@ public class HubManager extends MiniClientPlugin { if (!_creativeAdmin.containsKey(caller.getName())) _creativeAdmin.put(caller.getName(), new ArrayList()); - + if (target.getGameMode() == GameMode.CREATIVE) { _creativeAdmin.get(caller.getName()).add(target.getName()); @@ -940,29 +954,38 @@ public class HubManager extends MiniClientPlugin _creativeAdmin.get(caller.getName()).remove(target.getName()); } } - + @EventHandler public void clearGameMode(PlayerQuitEvent event) { ArrayList creative = _creativeAdmin.remove(event.getPlayer().getName()); - + if (creative == null) return; - + for (String name : creative) { Player player = UtilPlayer.searchExact(name); if (player == null) continue; - + player.setGameMode(GameMode.SURVIVAL); - + UtilPlayer.message(player, F.main("Game Mode", event.getPlayer().getName() + " left the game. Creative Mode: " + F.tf(false))); } } - + public PacketHandler getPacketHandler() { return _packetHandler; } + + @EventHandler + public void openProfile(PlayerInteractEvent event) + { + if(event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM) + return; + + new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager, _personalServerManager).openInventory();; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java index bafd2df86..0eacb7d77 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java @@ -3,16 +3,20 @@ package mineplex.hub.modules; import java.util.ArrayList; import java.util.HashSet; +import org.bukkit.EntityEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Sound; +import org.bukkit.entity.Bat; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerVelocityEvent; @@ -349,6 +353,12 @@ public class SoccerManager extends MiniPlugin if (_ball != null && _ball.equals(ent)) continue; + + if (ent instanceof Bat) + { + ent.remove(); + continue; + } if (inPlayerArena(ent)) { @@ -491,4 +501,30 @@ public class SoccerManager extends MiniPlugin { _active.remove(event.getPlayer()); } + + @EventHandler(priority = EventPriority.HIGHEST) + public void allowDamage(EntityDamageByEntityEvent event) + { + if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)) + return; + + Player damager = (Player)event.getDamager(); + Player damagee = (Player)event.getEntity(); + + if (!_active.contains(damager) || !_active.contains(damagee)) + return; + + if (getTeamColor(damager) == null || getTeamColor(damagee) == null) + return; + + if (getTeamColor(damager) == getTeamColor(damagee)) + return; + + if (Recharge.Instance.use(damagee, "Football Damage", 800, false, false)) + { + UtilAction.velocity(damagee, UtilAlg.getTrajectory2d(damager, damagee), 0.6, false, 0, 0.3, 1, true); + + damagee.playEffect(EntityEffect.HURT); + } + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonMPS.java b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonMPS.java new file mode 100644 index 000000000..00135e777 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonMPS.java @@ -0,0 +1,60 @@ +package mineplex.hub.profile.buttons; + +import mineplex.core.common.util.C; +import mineplex.core.gui.GuiItem; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.hub.profile.gui.GUIProfile; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +public class ButtonMPS implements GuiItem +{ + + private GUIProfile _profile; + private Player _player; + + public ButtonMPS(GUIProfile profile, Player player) + { + _profile = profile; + _player = player; + } + + @Override + public void click(ClickType clickType) + { + _profile.getPersonalManager().showHostMessage(_player); + } + + @Override + public ItemStack getObject() + { + return ItemStackFactory.Instance.CreateStack(Material.SPECKLED_MELON, (byte)0, 1, + ChatColor.RESET + C.cYellow + "Mineplex Player Server", + new String[] + { + "", + C.cWhite + "Create a server where you are the Host.", + C.cWhite + "You can choose the game, map and much more!", + "", + C.cWhite + "Type " + C.cGreen + "/mps" + C.cWhite + " to access this anywhere!" + }); + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonPrefs.java b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonPrefs.java new file mode 100644 index 000000000..38652a7c7 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonPrefs.java @@ -0,0 +1,61 @@ +package mineplex.hub.profile.buttons; + +import mineplex.core.common.util.C; +import mineplex.core.gui.GuiItem; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.hub.profile.gui.GUIProfile; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +public class ButtonPrefs implements GuiItem +{ + + private GUIProfile _profile; + private Player _player; + + public ButtonPrefs(GUIProfile profile, Player player) + { + _profile = profile; + _player = player; + } + + @Override + public void click(ClickType clickType) + { + _profile.getPrefManager().openShop(_player); + } + + @Override + public ItemStack getObject() + { + return ItemStackFactory.Instance.CreateStack(Material.REDSTONE_COMPARATOR.getId(), (byte)0, 1, + ChatColor.RESET + C.cYellow + "Preferences", + new String[] + { + "", + C.cWhite + "Set your preferences to your liking", + C.cWhite + "so you can enjoy the game more!", + + "", + C.cWhite + "Type " + C.cGreen + "/prefs" + C.cWhite + " to access this anywhere!" + }); + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonStats.java b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonStats.java new file mode 100644 index 000000000..3e36c712d --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/buttons/ButtonStats.java @@ -0,0 +1,65 @@ +package mineplex.hub.profile.buttons; + +import mineplex.core.common.util.C; +import mineplex.core.gui.GuiItem; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.hub.profile.gui.GUIProfile; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +public class ButtonStats implements GuiItem +{ + + private GUIProfile _profile; + private Player _player; + + public ButtonStats(GUIProfile profile, Player player) + { + _profile = profile; + _player = player; + } + + @Override + public void click(ClickType clickType) + { + _profile.getAchievementManager().openShop(_player); + } + + @Override + public ItemStack getObject() + { + ItemStack item = ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 3, 1, + ChatColor.RESET + C.cYellow + "Stats and Achievements", + new String[] + { + "", + C.cWhite + "View your Statistics and Achievements", + C.cWhite + "for all of the games on Mineplex!", + + "", + C.cWhite + "Type " + C.cGreen + "/stats" + C.cWhite + " to access this anywhere!" + }); + SkullMeta meta = ((SkullMeta) item.getItemMeta()); + meta.setOwner(_player.getName()); + item.setItemMeta(meta); + return item; + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/profile/gui/GUIProfile.java b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/gui/GUIProfile.java new file mode 100644 index 000000000..a7dca223b --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/profile/gui/GUIProfile.java @@ -0,0 +1,48 @@ +package mineplex.hub.profile.gui; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import mineplex.core.achievement.AchievementManager; +import mineplex.core.gui.SimpleGui; +import mineplex.core.personalServer.PersonalServerManager; +import mineplex.core.preferences.PreferencesManager; +import mineplex.hub.profile.buttons.ButtonMPS; +import mineplex.hub.profile.buttons.ButtonPrefs; +import mineplex.hub.profile.buttons.ButtonStats; + +public class GUIProfile extends SimpleGui +{ + + private PreferencesManager _preferencesManager; + private AchievementManager _achievementManager; + private PersonalServerManager _personalServerManager; + + public GUIProfile(Plugin plugin, Player player, PreferencesManager preferencesManager, AchievementManager achievementManager, PersonalServerManager personalServerManager) + { + super(plugin, player, "My Profile", 9*3); + _preferencesManager = preferencesManager; + _achievementManager = achievementManager; + _personalServerManager = personalServerManager; + + setItem(11, new ButtonStats(this, player)); + setItem(13, new ButtonPrefs(this, player)); + setItem(15, new ButtonMPS(this, player)); + } + + public PreferencesManager getPrefManager() + { + return _preferencesManager; + } + + public AchievementManager getAchievementManager() + { + return _achievementManager; + } + + public PersonalServerManager getPersonalManager() + { + return _personalServerManager; + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/types/PartyTutorial.java b/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/types/PartyTutorial.java index e8c7d1a8c..8b995220b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/types/PartyTutorial.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/types/PartyTutorial.java @@ -17,8 +17,8 @@ public class PartyTutorial extends Tutorial double y = -manager.GetSpawn().getY(); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 10), - manager.GetSpawn().add(81, y+68.5, 10), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Parties", new String[] { @@ -32,8 +32,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Creating a Party", new String[] { @@ -47,8 +47,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Inviting and Suggesting Players", new String[] { @@ -61,8 +61,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Leaving Parties", new String[] { @@ -73,8 +73,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Kicking Players from Party", new String[] { @@ -87,8 +87,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Joining Games Together", new String[] { @@ -103,8 +103,8 @@ public class PartyTutorial extends Tutorial )); _phases.add(new TutorialPhase( - manager.GetSpawn().add(84, y+69, 9), - manager.GetSpawn().add(81, y+68.5, 9), + manager.GetSpawn().add(0, 65 + y, 0), + manager.GetSpawn().add(4, 66.5 + y, 0), "Party Chat", new String[] { diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/servers/ServerManager.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/servers/ServerManager.java index fbf5d563b..4ed251ae4 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/servers/ServerManager.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/servers/ServerManager.java @@ -20,8 +20,9 @@ import mineplex.serverdata.servers.ConnectionData.ConnectionType; * */ public class ServerManager -{ +{ public static final String SERVER_STATUS_LABEL = "ServerStatus"; // Label differentiating ServerStatus related servers + private static final String DEFAULT_CONFIG = "redis-config.dat"; // Configuration determining connection information private static RedisConfig _config; @@ -74,7 +75,7 @@ public class ServerManager public static ConnectionData getConnection(boolean writeable, String name) { - return getConfig().getConnection(writeable, name); + return getConfig(DEFAULT_CONFIG).getConnection(writeable, name); } /** @@ -89,13 +90,13 @@ public class ServerManager /** * @return the {@link RedisConfig} associated with this manager, providing appropriate connections. */ - public static RedisConfig getConfig() + public static RedisConfig getConfig(String fileName) { if (_config == null) { try { - File configFile = new File("redis-config.dat"); + File configFile = new File(fileName); if (configFile.exists()) { @@ -113,7 +114,7 @@ public class ServerManager } else { - log("redis-config.dat not found at " + configFile.toPath().toString()); + log(fileName + " not found at " + configFile.toPath().toString()); _config = new RedisConfig(); } } diff --git a/Plugins/Mineplex.Votifier/Mineplex.Votifier.iml b/Plugins/Mineplex.Votifier/Mineplex.Votifier.iml new file mode 100644 index 000000000..c5e840788 --- /dev/null +++ b/Plugins/Mineplex.Votifier/Mineplex.Votifier.iml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Plugins/Mineplex.Votifier/plugin.yml b/Plugins/Mineplex.Votifier/plugin.yml new file mode 100644 index 000000000..75a40f893 --- /dev/null +++ b/Plugins/Mineplex.Votifier/plugin.yml @@ -0,0 +1,3 @@ +name: MineplexVotifier +main: mineplex.votifier.Votifier +version: 0.1 \ No newline at end of file diff --git a/Plugins/Mineplex.Votifier/src/mineplex/votifier/Votifier.java b/Plugins/Mineplex.Votifier/src/mineplex/votifier/Votifier.java new file mode 100644 index 000000000..f3fd02c9a --- /dev/null +++ b/Plugins/Mineplex.Votifier/src/mineplex/votifier/Votifier.java @@ -0,0 +1,34 @@ +package mineplex.votifier; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.command.CommandCenter; +import mineplex.core.donation.DonationManager; + +/** + * Created by shaun on 15-08-05. + */ +public class Votifier extends JavaPlugin +{ + private String WEB_CONFIG = "webServer"; + + @Override + public void onEnable() + { + getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); + getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); + saveConfig(); + + String webServerAddress = getConfig().getString(WEB_CONFIG); + + CommandCenter.Initialize(this); + CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); + DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress); + BonusManager bonusManager = new BonusManager(this, clientManager, donationManager); + + + VotifierManager vote = new VotifierManager(this, clientManager, donationManager, bonusManager); + } +} diff --git a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java new file mode 100644 index 000000000..4791202f9 --- /dev/null +++ b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java @@ -0,0 +1,231 @@ +package mineplex.votifier; + +import java.sql.Date; +import java.util.UUID; + +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import com.vexsoftware.votifier.model.Vote; +import com.vexsoftware.votifier.model.VotifierEvent; +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.bonuses.BonusAmount; +import mineplex.core.bonuses.BonusClientData; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UUIDFetcher; +import mineplex.core.database.DBPool; +import mineplex.core.donation.DonationManager; +import mineplex.core.votifier.VotifierCommand; +import mineplex.database.Tables; +import mineplex.serverdata.Region; +import mineplex.serverdata.Utility; +import mineplex.serverdata.commands.ServerCommand; +import mineplex.serverdata.commands.ServerCommandManager; +import mineplex.serverdata.data.PlayerStatus; +import mineplex.serverdata.redis.RedisConfig; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; +import org.jooq.DSLContext; +import org.jooq.Record1; +import org.jooq.SQLDialect; +import org.jooq.impl.DSL; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.exceptions.JedisConnectionException; + +/** + * Created by shaun on 15-08-05. + */ +public class VotifierManager extends MiniPlugin +{ + private CoreClientManager _clientManager; + private DonationManager _donationManager; + private BonusManager _bonusManager; + + private RedisConfig _usConfig; + private RedisConfig _euConfig; + private RedisDataRepository _usPlayerRepo; + private RedisDataRepository _euPlayerRepo; + private JedisPool _usWritePool; + private JedisPool _euWritePool; + + public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, BonusManager bonusManager) + { + super("Votifier", plugin); + + _clientManager = clientManager; + _donationManager = donationManager; + _bonusManager = bonusManager; + + _usConfig = ServerManager.getConfig("us-redis.dat"); + _euConfig = ServerManager.getConfig("eu-redis.dat"); + + _usPlayerRepo = new RedisDataRepository(_usConfig.getConnection(true, "DefaultConnection"), + _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus"); + _euPlayerRepo = new RedisDataRepository(_euConfig.getConnection(true, "DefaultConnection"), + _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus"); + + _usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection")); + _euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection")); + } + + @EventHandler + public void handleVote(VotifierEvent event) + { + Vote vote = event.getVote(); + String playerName = vote.getUsername(); + + System.out.println("New Vote: " + playerName); + + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + if (uuid == null) + { + System.out.println("Failed to load UUID of " + playerName + " from UUIDFetcher. Trying with database"); + uuid = _clientManager.loadUUIDFromDB(playerName); + + if (uuid == null) + { + System.out.println("Failed to load UUID from database. Giving up on " + playerName); + } + } + + System.out.println("Loaded " + playerName + " with uuid " + uuid); + System.out.println("Attempting to award bonus"); + awardBonus(playerName, uuid); + System.out.println(); + System.out.println(); + +// UUID uuid = _clientManager.loadUUIDFromDB(playerName); +// if (uuid != null) +// { +// System.out.println("Found UUID:" + uuid.toString()); +// if (playerName.equalsIgnoreCase("Phinary")) +// { +// System.out.println("award bonus"); +// awardBonus(uuid); +// } +// } +// else +// { +// System.out.println("Failed to load UUID for player: " + playerName); +// } + +// PlayerStatus usStatus = _usPlayerRepo.getElement(playerName); +// if (usStatus != null) +// { +// System.out.println("Found on US Server: " + usStatus.getServer()); +// writePool = _usWritePool; +// serverName = usStatus.getServer(); +// } +// +// PlayerStatus euStatus = _euPlayerRepo.getElement(playerName); +// if (euStatus != null) +// { +// System.out.println("Found on EU Server: " + euStatus.getServer()); +// writePool = _euWritePool; +// serverName = euStatus.getServer(); +// } + + // Currently we just notify all servers, and the server with the player on it can deal with it + notifyServer(playerName, false); +// notifyServer(playerName, true); + } + + private void notifyServer(String playerName, boolean eu) + { + JedisPool writePool = eu ? _euWritePool : _usWritePool; + + VotifierCommand command = new VotifierCommand(playerName); + publishCommand(command, writePool); + } + + private void awardBonus(final String playerName, UUID uuid) + { + DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); + + Record1 idRecord = create.select(Tables.accounts.id).from(Tables.accounts).where(Tables.accounts.uuid.eq(uuid.toString())).fetchOne(); + if (idRecord != null) + { + final int accountId = idRecord.value1(); + final BonusClientData client = new BonusClientData(_bonusManager.getRepository().loadRecord(playerName, accountId)); + + final BonusAmount amount = _bonusManager.getVoteBonusAmount(client); + + // Reward Amount + if (amount.getTickets() > 0) + client.setTickets(client.getTickets() + amount.getTickets()); + + if (amount.getGems() > 0) + { + _donationManager.RewardGems(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + System.out.println("Gave " + amount.getGems() + " gems to " + playerName); + else + System.out.println("Failed to give " + amount.getGems() + " gems to " + playerName); + } + }, "Votifier", playerName, uuid, amount.getGems()); + } + + if (amount.getCoins() > 0) + { + _donationManager.RewardCoins(new Callback() + { + @Override + public void run(Boolean data) + { + if (data) + System.out.println("Gave " + amount.getGems() + " coins to " + playerName); + else + System.out.println("Failed to give " + amount.getGems() + " coins to " + playerName); + } + }, "Votifier", playerName, accountId, amount.getCoins()); + } + + // Update time + client.getRecord().setVotetime(new Date(_bonusManager.getSqlTime())); + + // Update Streak + _bonusManager.incrementVoteStreak(client); + + client.getRecord().store(); + System.out.println("Awarded carl ticket to " + playerName); + } + } + + private void publishCommand(final ServerCommand serverCommand, final JedisPool writePool) + { + new Thread(new Runnable() + { + public void run() + { + Jedis jedis = writePool.getResource(); + + try + { + String commandType = serverCommand.getClass().getSimpleName(); + String serializedCommand = Utility.serialize(serverCommand); + jedis.publish("commands.server" + ":" + commandType, serializedCommand); + } + catch (JedisConnectionException exception) + { + exception.printStackTrace(); + writePool.returnBrokenResource(jedis); + jedis = null; + } + finally + { + if (writePool != null) + { + writePool.returnResource(jedis); + } + } + } + }).start(); + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/MenuPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/MenuPage.java index c24a31d78..26adc68ba 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/MenuPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/MenuPage.java @@ -89,10 +89,10 @@ public class MenuPage extends BasePage if (host) { GiveAdminButton giveAdminButton = new GiveAdminButton(getPlugin(), getShop()); - addButton(4 + 9, new ShopItem(Material.DIAMOND_SWORD, "Give Admin", new String[]{}, 1, false), giveAdminButton); + addButton(4 + 9, new ShopItem(Material.DIAMOND_SWORD, "Give Co-Host", new String[]{}, 1, false), giveAdminButton); RemoveAdminButton removeAdminButton = new RemoveAdminButton(getPlugin(), getShop()); - addButton(4 + 18, new ShopItem(Material.GOLD_SWORD, "Remove Admin", new String[]{}, 1, false), removeAdminButton); + addButton(4 + 18, new ShopItem(Material.GOLD_SWORD, "Remove Co-Host", new String[]{}, 1, false), removeAdminButton); KillButton killButton = new KillButton(getPlugin()); addButton(8 + 18, new ShopItem(Material.TNT, "Kill Private Server", diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java index 4aed91a8a..5f949845c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java @@ -90,9 +90,9 @@ public class GameChatManager implements Listener else if (Manager.GetGameHostManager().isAdmin(event.getPlayer(), false)) { if (Manager.GetGameHostManager().isEventServer()) - rankStr = C.cDGreen + C.Bold + "Event Admin "; + rankStr = C.cDGreen + C.Bold + "Event Co-Host "; else - rankStr = C.cDGreen + C.Bold + "MPS Admin "; + rankStr = C.cDGreen + C.Bold + "MPS Co-Host "; } else { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java index 07bb93f7a..53f8173c3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java @@ -36,7 +36,7 @@ public class GameGemManager implements Listener { ArcadeManager Manager; - boolean DoubleGem = true; + boolean DoubleGem = false; public GameGemManager(ArcadeManager manager) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java index b6f91560c..a5f9fab74 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java @@ -230,6 +230,10 @@ public class GameHostManager implements Listener _hostRank = Manager.GetClients().Get(_host).GetRank(); System.out.println("Game Host Joined."); + //Limit player count! + if (Manager.GetServerConfig().MaxPlayers > getMaxPlayerCap()) + Manager.GetServerConfig().MaxPlayers = getMaxPlayerCap(); + if (isEventServer()) worldeditPermissionSet(event.getPlayer(), true); } @@ -642,7 +646,7 @@ public class GameHostManager implements Listener { _adminList.add(player.getName()); _onlineAdmins.add(player); - UtilPlayer.message(player, F.main("Server", "You were given admin privileges.")); + UtilPlayer.message(player, F.main("Server", "You were given Co-Host privileges.")); if (isEventServer()) worldeditPermissionSet(player, true); @@ -660,7 +664,7 @@ public class GameHostManager implements Listener { player.closeInventory(); } - UtilPlayer.message(player, F.main("Server", "Your admin privileges were removed.")); + UtilPlayer.message(player, F.main("Server", "Your Co-Host privileges were removed.")); player.setGameMode(GameMode.SURVIVAL); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java index 08fc48275..e018a834d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java @@ -50,12 +50,12 @@ public class GameLootManager implements Listener Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); - _rewardManager = new RewardManager(Manager.GetClients(), Manager.GetDonation(), Manager.getInventoryManager(), petManager, + _rewardManager = new RewardManager(Manager.GetClients(), Manager.GetDonation(), Manager.getInventoryManager(), petManager, Manager.GetStatsManager(), 100, 250, 500, 1000, 1500, 2500, 6000, 12000, - false); + false, false); //Chest _rewardManager.addReward(new InventoryReward(Manager.getInventoryManager(), "Old Chest", "Old Chest", 1, 1,