Persistence fixes

This commit is contained in:
LCastr0 2016-06-25 00:36:00 -03:00
commit d75abe3aea
62 changed files with 1753 additions and 652 deletions

View File

@ -8,18 +8,27 @@ import com.google.gson.Gson;
public class ApiEndpoint
{
private static final String API_HOST = "10.33.53.12";
// private static final String API_HOST = "localhost";
// private static final int API_PORT = 3000;
private static final int API_PORT = 7979;
private Gson _gson;
private ApiWebCall _webCall;
public ApiEndpoint(String path, Gson gson)
{
String url = "http://" + API_HOST + ":" + API_PORT + path;
_webCall = new ApiWebCall(url, gson);
_gson = gson;
}
protected ApiWebCall getWebCall()
{
return _webCall;
}
public Gson getGson()
{
return _gson;
}
}

View File

@ -5,8 +5,10 @@ import java.util.Date;
/**
* @author Shaun Bennett
*/
public class ApiResponse
public class ApiResponse implements HttpStatusCode
{
// These do not have _ prefix because of gson. Please do not add underscores!
private int statusCode;
private boolean success;
private String error;
@ -33,4 +35,16 @@ public class ApiResponse
", error='" + error + '\'' +
'}';
}
@Override
public int getStatusCode()
{
return statusCode;
}
@Override
public void setStatusCode(int statusCode)
{
this.statusCode = statusCode;
}
}

View File

@ -92,6 +92,11 @@ public class ApiWebCall
private <T> T parseResponse(CloseableHttpResponse response, Type type) throws IOException
{
HttpEntity entity = response.getEntity();
return _gson.fromJson(new InputStreamReader(entity.getContent()), type);
T parsed = _gson.fromJson(new InputStreamReader(entity.getContent()), type);
if (parsed instanceof HttpStatusCode && response.getStatusLine() != null)
{
((HttpStatusCode) parsed).setStatusCode(response.getStatusLine().getStatusCode());
}
return parsed;
}
}

View File

@ -0,0 +1,12 @@
package mineplex.core.common.api;
/**
* Interface used to also grab status code from ApiWebCall
* @author Shaun Bennett
*/
public interface HttpStatusCode
{
public int getStatusCode();
public void setStatusCode(int statusCode);
}

View File

@ -180,7 +180,7 @@ public class UtilTime
{
if (type == TimeUnit.DAYS) text = (num = UtilMath.trim(trim, time / 86400000d)) + " Day";
else if (type == TimeUnit.HOURS) text = (num = UtilMath.trim(trim, time / 3600000d)) + " Hour";
else if (type == TimeUnit.MINUTES) text = (num = UtilMath.trim(trim, time / 60000d)) + " Minute";
else if (type == TimeUnit.MINUTES) text = (int) (num = (int) UtilMath.trim(trim, time / 60000d)) + " Minute";
else if (type == TimeUnit.SECONDS) text = (int) (num = (int) UtilMath.trim(trim, time / 1000d)) + " Second";
else text = (int) (num = (int) UtilMath.trim(trim, time)) + " Millisecond";
}

View File

@ -6,7 +6,6 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.bonuses.animations.AnimationCarl;
import mineplex.core.bonuses.commands.AllowCommand;
import mineplex.core.bonuses.commands.AnimationCommand;
import mineplex.core.bonuses.commands.GuiCommand;
import mineplex.core.bonuses.commands.TicketCommand;
@ -39,6 +38,7 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.treasure.TreasureType;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.youtube.YoutubeManager;
import mineplex.database.Tables;
import mineplex.database.tables.records.BonusRecord;
import mineplex.serverdata.commands.ServerCommandManager;
@ -122,7 +122,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private RewardManager _rewardManager;
private StatsManager _statsManager;
private FacebookManager _facebookManager;
// private BoosterManager _boosterManager;
private YoutubeManager _youtubeManager;
private BoosterManager _boosterManager;
public boolean _enabled;
private Npc _carlNpc;
private AnimationCarl _animation;
@ -161,7 +162,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
updateOffSet();
}
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, FacebookManager facebookManager, GadgetManager gadgetManager)
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, FacebookManager facebookManager, YoutubeManager youtubeManager, GadgetManager gadgetManager, BoosterManager boosterManager)
{
super("Bonus", plugin);
_repository = new BonusRepository(plugin, this, donationManager);
@ -170,12 +171,14 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_npcManager = npcManager;
_hologramManager = hologramManager;
_inventoryManager = inventoryManager;
_boosterManager = boosterManager;
_rewardManager = new RewardManager(_clientManager, _donationManager, _inventoryManager, petManager, statsManager, gadgetManager);
_pollManager = pollManager;
_statsManager = statsManager;
_facebookManager = facebookManager;
_youtubeManager = youtubeManager;
_voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
@ -414,6 +417,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
public static final long DAILY_STREAK_RESET_TIME = 1000 * 60 * 60 * 12;
public static final long VOTE_STREAK_RESET_TIME = 1000 * 60 * 60 * 24;
public void attemptDailyBonus(final Player player, final BonusAmount amount, final Callback<Boolean> result)
{
if (timeTillDailyBonus(player) > 0)
@ -823,7 +827,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (entity.equals(_carlNpc.getEntity()))
{
updateDailyStreak(event.getPlayer());
new BonusGui(_plugin, event.getPlayer(), this, _rewardManager, _facebookManager).openInventory();
new BonusGui(_plugin, event.getPlayer(), this, _rewardManager, _facebookManager, _youtubeManager, _boosterManager).openInventory();
}
}
@ -839,7 +843,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (event.getEntity().equals(_carlNpc.getEntity()))
{
updateDailyStreak(player);
new BonusGui(_plugin, player, this, _rewardManager, _facebookManager).openInventory();
new BonusGui(_plugin, player, this, _rewardManager, _facebookManager, _youtubeManager, _boosterManager).openInventory();
}
}
}
@ -901,11 +905,12 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
int availableRewards = 0;
if (canVote(player)) availableRewards++;
if (_youtubeManager.canYoutube(player)) availableRewards++;
if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++;
if (canDaily(player)) availableRewards++;
if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++;
if (!_facebookManager.hasRedeemed(player)) availableRewards++;
// if (_boosterManager.getTipManager().Get(player).getTips() > 0) availableRewards++;
if (_boosterManager.getTipManager().Get(player).getTips() > 0) availableRewards++;
Hologram hologram;
@ -1052,6 +1057,11 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
return _facebookManager;
}
public YoutubeManager getYoutubeManager()
{
return _youtubeManager;
}
@EventHandler
public void Join(final PlayerJoinEvent event)
{
@ -1185,4 +1195,9 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
return "SELECT * FROM bonus WHERE accountId = '" + accountId + "';";
}
public BoosterManager getBoosterManager()
{
return _boosterManager;
}
}

View File

@ -18,7 +18,7 @@ public class GuiCommand extends CommandBase<BonusManager>
@Override
public void Execute(Player caller, String[] args)
{
new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager()).openInventory();
new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager(), Plugin.getYoutubeManager(), Plugin.getBoosterManager()).openInventory();
}
}

View File

@ -1,12 +1,12 @@
package mineplex.core.bonuses.gui;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.bonuses.gui.buttons.*;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.facebook.FacebookManager;
import mineplex.core.gui.SimpleGui;
import mineplex.core.reward.RewardManager;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.youtube.YoutubeManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -15,23 +15,27 @@ public class BonusGui extends SimpleGui
private BonusManager manager;
public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager, FacebookManager facebookManager)
public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager, FacebookManager facebookManager, YoutubeManager youtubeManager, BoosterManager boosterManager)
{
super(plugin, player, player.getName() + "'s Bonuses", 5 * 9);
this.manager = manager;
setItem(9, new VoteButton(plugin, player, this, manager));
setItem(10, new VoteButton(plugin, player, this, manager));
setItem(11, new RankBonusButton(getPlugin(), player, this, manager));
setItem(12, new RankBonusButton(getPlugin(), player, this, manager));
setItem(13, new DailyBonusButton(getPlugin(), player, this, manager));
setItem(14, new DailyBonusButton(getPlugin(), player, this, manager));
setItem(15, new PollButton(getPlugin(), player, manager.getPollManager(), manager.getClientManager(), this, manager));
setItem(16, new PollButton(getPlugin(), player, manager.getPollManager(), manager.getClientManager(), this, manager));
setItem(17, new FacebookButton(player, facebookManager));
setItem(19, new FacebookButton(player, facebookManager));
// setItem(19, new ClaimTipsButton(getPlugin(), player, this, manager, boosterManager));
setItem(21, new YoutubeButton(player, youtubeManager));
setItem(23, new TwitterButton(player));
setItem(25, new ClaimTipsButton(getPlugin(), player, this, manager, boosterManager));
setItem(31, new CarlSpinButton(getPlugin(), player, manager, rewardManager));
}

View File

@ -0,0 +1,51 @@
package mineplex.core.bonuses.gui;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.gui.GuiItem;
import mineplex.core.itemstack.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class TwitterButton implements GuiItem
{
private static final ItemStack ICON = new ItemBuilder(Material.EGG)
.setTitle(C.cGreen + C.Bold + "Visit us on Twitter")
.addLore(
C.cWhite + "Check out and follow Mineplex on",
C.cWhite + "Twitter for Giveaways, Announcements,",
C.cWhite + "Teasers, and Tips!",
" ",
C.cGreen + "Click to visit us on Twitter!"
)
.build();
private final Player _player;
public TwitterButton(Player player)
{
this._player = player;
}
@Override
public void setup() {}
@Override
public void close() {}
@Override
public void click(ClickType clickType)
{
_player.closeInventory();
new JsonMessage(C.cAquaB + "Click here to visit our Twitter page!").click(ClickEvent.OPEN_URL, "https://www.twitter.com/Mineplex").sendToPlayer(_player);
}
@Override
public ItemStack getObject()
{
return ICON;
}
}

View File

@ -84,10 +84,10 @@ public class ClaimTipsButton implements GuiItem, Listener
if (getPlayer().getOpenInventory() != null)
{
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.LIME.getData(), 1, ChatColor.GREEN + "Booster Tips Collected"), "Tips Collected", 6*9, 20*3, getGui()).openInventory();
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.LIME.getData(), 1, ChatColor.GREEN + "Amplifier Thanks Collected"), "Thanks Collected", 6*9, 20*3, getGui()).openInventory();
}
UtilPlayer.message(getPlayer(), F.main("Carl", "You collected " + F.currency(CurrencyType.TREASURE_SHARD, claimed) + " from Booster Tips!"));
UtilPlayer.message(getPlayer(), F.main("Carl", "You collected " + F.currency(CurrencyType.TREASURE_SHARD, claimed) + " from Amplifiers!"));
// Pending explosions are strange.. Not sure why we are using strings. Either way, lets display a rank reward effect
_bonusManager.addPendingExplosion(getPlayer(), "RANK");
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f);
@ -97,10 +97,10 @@ public class ClaimTipsButton implements GuiItem, Listener
// No tips to claim
if (getPlayer().getOpenInventory() != null)
{
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "No Tips to Claim!"), "You have no tips to claim!", 6*9, 20*3, getGui()).openInventory();
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "No Thanks to Claim!"), "You have no thanks to claim!", 6*9, 20*3, getGui()).openInventory();
}
UtilPlayer.message(getPlayer(), F.main("Carl", "You have no tips to claim!"));
UtilPlayer.message(getPlayer(), F.main("Carl", "You have no rewards to claim!"));
getPlayer().playSound(getPlayer().getLocation(), Sound.ENDERDRAGON_GROWL, 1, 10);
}
else
@ -108,10 +108,10 @@ public class ClaimTipsButton implements GuiItem, Listener
// Failed to claim
if (getPlayer().getOpenInventory() != null)
{
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "Error collecting tips. Try again later."), "Error", 6*9, 20*3, getGui()).openInventory();
new TimedMessageWindow(getPlugin(), getPlayer(), ItemStackFactory.Instance.CreateStack(Material.STAINED_GLASS_PANE, DyeColor.RED.getData(), 1, ChatColor.RED + "Error collecting rewards. Try again later."), "Error", 6*9, 20*3, getGui()).openInventory();
}
UtilPlayer.message(getPlayer(), F.main("Carl", "Error collecting tips. Try again later."));
UtilPlayer.message(getPlayer(), F.main("Carl", "Error collecting rewards. Try again later."));
getPlayer().playSound(getPlayer().getLocation(), Sound.ENDERDRAGON_GROWL, 1, 10);
}
@ -133,9 +133,9 @@ public class ClaimTipsButton implements GuiItem, Listener
if (isAvailable())
{
material = Material.EMERALD;
itemName = C.cGreen + C.Bold + "Booster Tips";
itemName = C.cGreen + C.Bold + "Game Amplifiers";
lore.add(" ");
lore.add(C.cYellow + "Your Tips");
lore.add(C.cYellow + "Your Rewards");
lore.add(" " + C.cWhite + getTips() + " Treasure Shards");
lore.add(" ");
lore.add(ChatColor.RESET + "Click to Claim!");
@ -143,10 +143,12 @@ public class ClaimTipsButton implements GuiItem, Listener
else
{
material = Material.REDSTONE_BLOCK;
itemName = C.cRed + C.Bold + "Booster Tips";
itemName = C.cRed + C.Bold + "Game Amplifiers";
lore.add(" ");
lore.add(C.Reset + "Activate Game Boosters to receive tips");
lore.add(C.cGray + "Use Amplifiers to earn rewards");
lore.add(" ");
lore.add(C.cWhite + "Get Amplifiers at " + C.cGreen + "mineplex.com/shop");
}
_item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false);

View File

@ -0,0 +1,82 @@
package mineplex.core.bonuses.gui.buttons;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.gui.GuiItem;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.youtube.YoutubeManager;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
public class YoutubeButton implements GuiItem
{
private static final ItemStack DISABLED_ICON = new ItemBuilder(Material.APPLE)
.setTitle(C.cGreen + C.Bold + "Visit us on YouTube")
.addLore(
C.cWhite + "Come back tomorrow for your",
C.cWhite + "Daily 250 Shard Reward!",
" ",
C.cWhite + "Check out the latest Video",
C.cWhite + "on the MineplexGames Channel!",
" ",
C.cWhite + "Be sure and Subscribe so you",
C.cWhite + "don't miss a video!",
" ",
C.cGreen + "Click to visit us on YouTube!"
)
.build();
private static final ItemStack ENABLED_ICON = new ItemBuilder(Material.APPLE)
.setTitle(C.cGreen + C.Bold + "Visit us on YouTube")
.addLore(
C.cYellow + "Claim your Daily 250 Shard Reward",
C.cWhite + "by checking out the latest Video",
C.cWhite + "on the MineplexGames Channel!",
C.cWhite + " ",
C.cWhite + "Be sure and Subscribe so you",
C.cWhite + "don't miss a video!",
" ",
C.cGreen + "Click to visit us on YouTube!"
)
.build();
private final Player _player;
private final YoutubeManager _youtubeManager;
public YoutubeButton(Player player, YoutubeManager youtubeManager)
{
this._player = player;
this._youtubeManager = youtubeManager;
}
@Override
public void setup() {}
@Override
public void close() {}
@Override
public void click(ClickType clickType)
{
_player.closeInventory();
final String message;
if (_youtubeManager.canYoutube(_player))
{
message = "Click here to claim YouTube Prize!";
_youtubeManager.attemptYoutube(_player);
} else
{
message = "Click here to visit our YouTube page!";
}
new JsonMessage(C.cAquaB + message).click(ClickEvent.OPEN_URL, "https://www.youtube.com/mineplexgamesofficial").sendToPlayer(_player);
}
@Override
public ItemStack getObject()
{
return _youtubeManager.canYoutube(_player) ? ENABLED_ICON : DISABLED_ICON;
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.boosters;
import com.mojang.authlib.properties.PropertyMap;
import mineplex.core.common.util.UtilTime;
import java.util.Date;
@ -10,7 +11,7 @@ import java.util.UUID;
*/
public class Booster
{
private int _boosterId;
private int _id;
private String _playerName;
private UUID _uuid;
private int _accountId;
@ -19,14 +20,15 @@ public class Booster
private Date _startTime;
private Date _endTime;
private Date _activationTime;
// private PropertyMap _propertyMap;
public Booster()
{
}
public int getBoosterId()
public int getId()
{
return _boosterId;
return _id;
}
public String getPlayerName()
@ -66,13 +68,25 @@ public class Booster
public boolean isActive()
{
return getEndTime().before(new Date());
Date now = new Date();
return getStartTime().before(now) && getEndTime().after(now);
}
public long getTimeRemaining()
{
if (isActive())
{
return Math.max(0, getEndTime().getTime() - System.currentTimeMillis());
}
else if (getEndTime().after(new Date()))
{
return _duration * 1000L;
}
else
{
return 0;
}
}
public String getTimeRemainingString()
{
@ -84,6 +98,11 @@ public class Booster
return _multiplier;
}
// public PropertyMap getPropertyMap()
// {
// return _propertyMap;
// }
@Override
public boolean equals(Object o)
{
@ -92,23 +111,28 @@ public class Booster
Booster booster = (Booster) o;
if (_boosterId != booster._boosterId) return false;
if (_id != booster._id) return false;
return _accountId == booster._accountId;
}
@Override
public int hashCode()
{
int result = _boosterId;
int result = _id;
result = 31 * result + _accountId;
return result;
}
public int getIncreasePercent()
{
return (int) (getMultiplier() - 1) * 100;
}
@Override
public String toString()
{
return "Booster{" +
"_boosterId=" + _boosterId +
"_id=" + _id +
", _playerName='" + _playerName + '\'' +
", _uuid=" + _uuid +
", _accountId=" + _accountId +

View File

@ -1,12 +0,0 @@
package mineplex.core.boosters;
import mineplex.core.game.GameDisplay;
/**
* @author Shaun Bennett
*/
public enum BoosterCategory
{
}

View File

@ -1,31 +1,63 @@
package mineplex.core.boosters;
import com.mojang.authlib.properties.PropertyMap;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.command.BoosterCommand;
import mineplex.core.boosters.event.BoosterActivateEvent;
import mineplex.core.boosters.event.BoosterDeactivateEvent;
import mineplex.core.boosters.event.BoosterExpireEvent;
import mineplex.core.boosters.event.BoosterUpdateEvent;
import mineplex.core.boosters.gui.BoosterShop;
import mineplex.core.boosters.redis.BoosterUpdateRepository;
import mineplex.core.boosters.tips.BoosterTipManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.*;
/**
* BoosterManager handles the majority of logic for creating and getting Boosters. Every BoosterManager stores a cache
* for all boosters across all servers. We pull all boosters from the API when the server boots up. To keep them in sync,
* instead of consistently polling the API I have decided to go with a redis pub/sub solution to ensuring all boosters
* across all servers are up to date. Whenever the Booster API receives a call to add or modify boosters, it will publish
* an updated version of all boosters over redis.
*
* Boosters are enabled on live servers using "Booster Groups". A {@link mineplex.serverdata.data.ServerGroup} can specify
* which BoosterGroup applies to it. If there is no BoosterGroup, then it means the server does not use boosters. To add
* a BoosterGroup, you must add to the "boostergroups" set on redis (the same way the servergroups set works), otherwise
* the API will return an error saying that BoosterGroup does not exist. Currently BoosterGroups are no more than a String
* key for Boosters. In the future we may want to look into implementing BoosterGroup specific data such as default
* booster length and multiplier.
*
* @author Shaun Bennett
*/
public class BoosterManager extends MiniPlugin
{
// The InventoryManager item name for boosters. This is required to activate a booster on servers
public static final String BOOSTER_ITEM = "Game Booster";
// Item in arcade lobbies that opens the booster gui
public static final ItemStack INTERFACE_ITEM = ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, ChatColor.RESET + C.cGreen + "Game Amplifiers");
// Slot for the booster gui item
public static final int INTERFACE_SLOT = 7;
private BoosterRepository _repository;
private CoreClientManager _clientManager;
private DonationManager _donationManager;
@ -33,15 +65,19 @@ public class BoosterManager extends MiniPlugin
private BoosterTipManager _tipManager;
private BoosterShop _shop;
private String _boosterGroup;
private boolean _giveInterfaceItem;
private long _cacheLastUpdated;
private Map<String, List<Booster>> _boosterCache = new HashMap<>();
public BoosterManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager)
public BoosterManager(JavaPlugin plugin, String boosterGroup, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager)
{
super("Booster Manager", plugin);
_repository = new BoosterRepository();
_boosterGroup = boosterGroup;
_clientManager = clientManager;
_donationManager = donationManager;
_inventoryManager = inventoryManager;
@ -51,13 +87,18 @@ public class BoosterManager extends MiniPlugin
try
{
_boosterCache = _repository.getBoosters();
Map<String, List<Booster>> boosters = _repository.getBoosters();
if (boosters != null) _boosterCache = boosters;
}
catch (Exception e)
{
System.out.println("Failed to load boosters on server start.");
e.printStackTrace();
}
_giveInterfaceItem = canActivateBoosters();
new BoosterUpdateRepository(plugin);
}
@Override
@ -66,6 +107,10 @@ public class BoosterManager extends MiniPlugin
addCommand(new BoosterCommand(this));
}
/**
* Make an API call to grab all Boosters
*/
@Deprecated
public void getBoostersAsync(Callback<Map<String, List<Booster>>> callback)
{
runAsync(() -> {
@ -75,29 +120,7 @@ public class BoosterManager extends MiniPlugin
Map<String, List<Booster>> boosters = _repository.getBoosters();
long timeTaken = System.currentTimeMillis() - time;
runSync(() -> {
_boosterCache.entrySet().stream()
.filter(entry -> entry.getValue().size() > 0)
.filter(entry -> boosters.get(entry.getKey()) == null)
.forEach(entry -> callNextTick(new BoosterDeactivateEvent(entry.getValue().get(0))));
for (Map.Entry<String, List<Booster>> entry : boosters.entrySet())
{
List<Booster> current = _boosterCache.get(entry.getKey());
if (current == null || current.get(0) == null)
{
callNextTick(new BoosterActivateEvent(entry.getValue().get(0)));
}
else if (!current.get(0).equals(entry.getValue().get(0)))
{
callNextTick(new BoosterDeactivateEvent(current.get(0)));
callNextTick(new BoosterActivateEvent(entry.getValue().get(0)));
}
}
_cacheLastUpdated = System.currentTimeMillis();
_boosterCache = boosters;
handleBoosterUpdate(boosters);
if (callback != null) callback.run(boosters);
});
}
@ -109,9 +132,153 @@ public class BoosterManager extends MiniPlugin
});
}
public Booster getActiveBoosterFromCache(String serverGroup)
/**
* Make an API call to grab all boosters for a specific booster group
* @param boosterGroup
* @param callback
*/
@Deprecated
public void getBoostersAsync(String boosterGroup, Callback<List<Booster>> callback)
{
List<Booster> boosters = _boosterCache.get(serverGroup);
runAsync(() -> {
try
{
List<Booster> boosters = _repository.getBoosters(boosterGroup);
if (callback != null) runSync(() -> callback.run(boosters));
}
catch (Exception e)
{
System.err.println("Failed to grab boosters for boostergroup: " + boosterGroup);
e.printStackTrace();
}
});
}
/**
* Process the new boosterMap whenever a BoosterUpdateEvent is sent. This will compare itself to the current
* cached BoosterMap and call events when it finds a booster was activated or deactivated
* @param boosterMap The new booster map
*/
private void handleBoosterUpdate(Map<String, List<Booster>> boosterMap)
{
_boosterCache.entrySet().stream()
.filter(entry -> entry.getValue().size() > 0)
.filter(entry -> boosterMap.get(entry.getKey()) == null)
.forEach(entry -> callNextTick(new BoosterExpireEvent(entry.getKey(), entry.getValue().get(0))));
for (Map.Entry<String, List<Booster>> entry : boosterMap.entrySet())
{
List<Booster> current = _boosterCache.get(entry.getKey());
if (entry.getValue() != null && !entry.getValue().isEmpty())
{
if (current == null || current.isEmpty())
{
// New booster was added
callNextTick(new BoosterActivateEvent(entry.getKey(), entry.getValue().get(0)));
} else if (!current.get(0).equals(entry.getValue().get(0)))
{
// First booster was deactivated, new booster replaced it
callNextTick(new BoosterExpireEvent(entry.getKey(), current.get(0)));
callNextTick(new BoosterActivateEvent(entry.getKey(), entry.getValue().get(0)));
}
}
}
_cacheLastUpdated = System.currentTimeMillis();
_boosterCache = boosterMap;
}
private void tickBoosterCache()
{
List<Event> events = new ArrayList<>(3);
for (Map.Entry<String, List<Booster>> entry : _boosterCache.entrySet())
{
Iterator<Booster> iterator = entry.getValue().iterator();
boolean removedOne = false;
while (iterator.hasNext())
{
Booster booster = iterator.next();
if (!booster.isActive())
{
iterator.remove();
removedOne = true;
events.add(new BoosterExpireEvent(entry.getKey(), booster));
}
else
{
if (removedOne) events.add(new BoosterActivateEvent(entry.getKey(), booster));
break;
}
}
}
events.forEach(Bukkit.getPluginManager()::callEvent);
}
@EventHandler
public void tickBoosters(UpdateEvent event)
{
if (event.getType() == UpdateType.MIN_10)
{
// sync with API every 10 minutes, incase pubsub fails
getBoostersAsync(null);
}
else if (event.getType() == UpdateType.SEC)
{
tickBoosterCache();
}
}
/**
* Return all boosters for the active booster group
* @return list of boosters, or null if there is no active booster group
*/
public List<Booster> getBoosters()
{
if (_boosterGroup == null || _boosterGroup.length() == 0)
{
return null;
}
else
{
List<Booster> boosters = _boosterCache.get(_boosterGroup);
return boosters == null ? Collections.emptyList() : boosters;
}
}
public String getBoosterGroup()
{
return _boosterGroup;
}
public long getBoostTime()
{
return getBoostTime(_boosterGroup);
}
public long getBoostTime(String boosterGroup)
{
long time = 0;
List<Booster> boosters = _boosterCache.get(boosterGroup);
if (boosters != null && boosters.size() > 0)
{
for (Booster booster : boosters)
{
time += booster.getTimeRemaining();
}
}
return time;
}
public Booster getActiveBooster()
{
return getActiveBooster(_boosterGroup);
}
public Booster getActiveBooster(String boosterGroup)
{
List<Booster> boosters = _boosterCache.get(boosterGroup);
if (boosters != null)
{
for (Booster booster : boosters)
@ -124,20 +291,9 @@ public class BoosterManager extends MiniPlugin
return null;
}
public void getBoostersAsync(String serverGroup, Callback<List<Booster>> callback)
public void activateBooster(Player player, Callback<BoosterApiResponse> callback)
{
runAsync(() -> {
try
{
List<Booster> boosters = _repository.getBoosters(serverGroup);
if (callback != null) runSync(() -> callback.run(boosters));
}
catch (Exception e)
{
System.err.println("Failed to grab boosters for servergroup: " + serverGroup);
e.printStackTrace();
}
});
activateBooster(_boosterGroup, player, callback);
}
public void activateBooster(String serverGroup, Player player, Callback<BoosterApiResponse> callback)
@ -145,6 +301,7 @@ public class BoosterManager extends MiniPlugin
String playerName = player.getName();
UUID uuid = player.getUniqueId();
int accountId = _clientManager.getAccountId(player);
// PropertyMap propertyMap = ((CraftPlayer) player).getHandle().getProfile().getProperties();
runAsync(() -> {
BoosterApiResponse response = _repository.addBooster(serverGroup, playerName, uuid, accountId, 3600);
@ -152,18 +309,28 @@ public class BoosterManager extends MiniPlugin
});
}
public void chargeBooster(Player player, Callback<Boolean> callback)
{
_inventoryManager.addItemToInventory(callback, player, BOOSTER_ITEM, -1);
}
public void refundBooster(Player player, Callback<Boolean> callback)
{
_inventoryManager.addItemToInventory(callback, player, BOOSTER_ITEM, 1);
}
public void openShop(Player player)
{
_shop.attemptShopOpen(player);
}
/**
* Booster updates are sent from {@link mineplex.core.boosters.redis.BoosterUpdateListener}
*/
@EventHandler
public void updateCache(UpdateEvent event)
public void onBoosterUpdate(BoosterUpdateEvent event)
{
if (event.getType() == UpdateType.SEC_30)
{
getBoostersAsync(null);
}
handleBoosterUpdate(event.getBoosterMap());
}
public BoosterTipManager getTipManager()
@ -178,7 +345,7 @@ public class BoosterManager extends MiniPlugin
*/
public int getAvailableBoosterCount(Player player)
{
return _inventoryManager.Get(player).getItemCount("Game Booster");
return _inventoryManager.Get(player).getItemCount(BOOSTER_ITEM);
}
/**
@ -187,18 +354,37 @@ public class BoosterManager extends MiniPlugin
*/
public boolean canActivateBoosters()
{
return true;
return _boosterGroup != null && _boosterGroup.length() > 0;
}
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException
public void giveInterfaceItem(Player player)
{
BoosterRepository repository = new BoosterRepository();
Map<String, List<Booster>> boosters = repository.getBoosters();
boosters.entrySet().forEach((entry) -> {
System.out.println("Booster Entry: " + entry.getKey());
System.out.println("Booster Size: " + entry.getValue().size());
entry.getValue().forEach(System.out::println);
});
if (_giveInterfaceItem && !UtilGear.isMat(player.getInventory().getItem(INTERFACE_SLOT), Material.EMERALD))
{
player.getInventory().setItem(INTERFACE_SLOT, INTERFACE_ITEM);
UtilInv.Update(player);
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
giveInterfaceItem(event.getPlayer());
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (INTERFACE_ITEM.equals(event.getPlayer().getItemInHand()))
{
openShop(event.getPlayer());
}
}
public Map<String, List<Booster>> getBoosterCache()
{
return _boosterCache;
}
private void callNextTick(Event event)

View File

@ -1,8 +0,0 @@
package mineplex.core.boosters;
/**
* @author Shaun Bennett
*/
public class BoosterMap
{
}

View File

@ -0,0 +1,59 @@
package mineplex.core.boosters;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.shop.confirmation.ConfirmationCallback;
import mineplex.core.shop.confirmation.ConfirmationProcessor;
import org.bukkit.entity.Player;
/**
* @author Shaun Bennett
*/
public class BoosterProcessor implements ConfirmationProcessor
{
private BoosterManager _boosterManager;
private Player _player;
public BoosterProcessor(BoosterManager boosterManager, Player player)
{
_boosterManager = boosterManager;
_player = player;
}
@Override
public void process(ConfirmationCallback callback)
{
_boosterManager.chargeBooster(_player, data -> {
if (data)
{
_boosterManager.activateBooster(_player, response -> {
if (response.isSuccess())
{
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
if (timeToStart <= 0) _player.sendMessage(F.main("Amplifier", "Game Amplifier Activated!"));
else _player.sendMessage(F.main("Amplifier", "Game Amplifier Added. It will start in " + F.elem(UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT))));
callback.resolve("Success!");
}
else
{
_player.sendMessage(C.cRed + "There was an error trying to enable your Game Amplifier");
if (response.getStatusCode() == 503 && response.getError() != null && response.getError().length() > 0)
{
// Service Unavailable HTTP Code
_player.sendMessage(C.cRed + "Error: " + response.getError());
}
_boosterManager.refundBooster(_player, null);
callback.reject("Failed. Try again later.");
}
});
}
else
{
callback.reject("Failed charging account.");
_player.sendMessage(F.main("Amplifier", "There was an error charging your account. Try again later!"));
}
});
}
}

View File

@ -4,6 +4,7 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.mojang.authlib.properties.PropertyMap;
import mineplex.core.common.api.ApiEndpoint;
import mineplex.core.common.api.ApiFieldNamingStrategy;
import mineplex.core.common.api.ApiResponse;
@ -14,6 +15,8 @@ import java.util.Map;
import java.util.UUID;
/**
* Boosters interaction is handled through a web API. All data is represented as JSON and then parsed using gson.
*
* @author Shaun Bennett
*/
public class BoosterRepository extends ApiEndpoint
@ -21,6 +24,7 @@ public class BoosterRepository extends ApiEndpoint
public BoosterRepository()
{
super("/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
// .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create());
}
@ -41,6 +45,7 @@ public class BoosterRepository extends ApiEndpoint
body.addProperty("uuid", uuid.toString());
body.addProperty("accountId", accountId);
body.addProperty("duration", duration);
// body.add("propertyMap", getGson().toJsonTree(propertyMap));
return getWebCall().post("/" + serverGroup, BoosterApiResponse.class, body);
}

View File

@ -32,11 +32,11 @@ public class AddCommand extends CommandBase<BoosterManager>
{
if (response.isSuccess())
{
UtilPlayer.message(caller, F.main("Booster", "Successfully added booster to " + F.elem(serverGroup)));
UtilPlayer.message(caller, F.main("Amplifier", "Successfully added amplifier to " + F.elem(serverGroup)));
}
else
{
UtilPlayer.message(caller, F.main("Booster", "Failed to add booster. Error: " + F.elem(response.getError())));
UtilPlayer.message(caller, F.main("Amplifier", "Failed to add amplifier. Error: " + F.elem(response.getError())));
}
}
});
@ -49,6 +49,6 @@ public class AddCommand extends CommandBase<BoosterManager>
private void help(Player caller)
{
UtilPlayer.message(caller, F.help("booster add <servergroup>", "Add a booster to that server group", Rank.DEVELOPER));
UtilPlayer.message(caller, F.help("amplifier add <servergroup>", "Add an amplifier to that server group", Rank.DEVELOPER));
}
}

View File

@ -15,14 +15,17 @@ public class BoosterCommand extends MultiCommandBase<BoosterManager>
{
public BoosterCommand(BoosterManager plugin)
{
super(plugin, Rank.DEVELOPER, "booster");
super(plugin, Rank.DEVELOPER, "amplifier", "booster");
AddCommand(new AddCommand(plugin));
AddCommand(new GuiCommand(plugin));
AddCommand(new ReloadCommand(plugin));
}
@Override
protected void Help(Player caller, String[] args)
{
UtilPlayer.message(caller, F.help("booster add <servergroup>", "Add a booster to that server group", Rank.DEVELOPER));
UtilPlayer.message(caller, F.help("amplifier add <group>", "Add an amplifier to that group", Rank.DEVELOPER));
UtilPlayer.message(caller, F.help("amplifier gui", "Open Amplifier GUI", Rank.DEVELOPER));
}
}

View File

@ -0,0 +1,23 @@
package mineplex.core.boosters.command;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import org.bukkit.entity.Player;
/**
* @author Shaun Bennett
*/
public class GuiCommand extends CommandBase<BoosterManager>
{
public GuiCommand(BoosterManager plugin)
{
super(plugin, Rank.DEVELOPER, "gui");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.openShop(caller);
}
}

View File

@ -0,0 +1,35 @@
package mineplex.core.boosters.command;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Map;
/**
* @author Shaun Bennett
*/
public class ReloadCommand extends CommandBase<BoosterManager>
{
public ReloadCommand(BoosterManager plugin)
{
super(plugin, Rank.DEVELOPER, "reload");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.getBoostersAsync(data -> {
if (data != null)
{
UtilPlayer.message(caller, F.main("Amplifier", "Amplifiers reloaded!"));
}
});
}
}

View File

@ -5,17 +5,27 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called when a Booster is activated. This will be called regardless of which "BoosterGroup" the current server is set
* to, so if you only want Boosters on the current BoosterGroup, you will need to verify it.
*
* @author Shaun Bennett
*/
public class BoosterActivateEvent extends Event
{
private String _boosterGroup;
private Booster _booster;
public BoosterActivateEvent(Booster booster)
public BoosterActivateEvent(String boosterGroup, Booster booster)
{
_boosterGroup = boosterGroup;
_booster = booster;
}
public String getBoosterGroup()
{
return _boosterGroup;
}
public Booster getBooster()
{
return _booster;

View File

@ -5,17 +5,26 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called when a Booster is finished.
*
* @author Shaun Bennett
*/
public class BoosterDeactivateEvent extends Event
public class BoosterExpireEvent extends Event
{
private String _boosterGroup;
private Booster _booster;
public BoosterDeactivateEvent(Booster booster)
public BoosterExpireEvent(String boosterGroup, Booster booster)
{
_boosterGroup = boosterGroup;
_booster = booster;
}
public String getBoosterGroup()
{
return _boosterGroup;
}
public Booster getBooster()
{
return _booster;

View File

@ -0,0 +1,41 @@
package mineplex.core.boosters.event;
import mineplex.core.boosters.Booster;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import java.util.List;
import java.util.Map;
/**
* Called when {@link mineplex.core.boosters.redis.BoosterUpdateListener} receives updated Boosters over redis pubsub.
*
* @author Shaun Bennett
*/
public class BoosterUpdateEvent extends Event
{
private Map<String, List<Booster>> _boosterMap;
public BoosterUpdateEvent(Map<String, List<Booster>> boosterMap)
{
_boosterMap = boosterMap;
}
public Map<String, List<Booster>> getBoosterMap()
{
return _boosterMap;
}
private static final HandlerList _handlers = new HandlerList();
private static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -4,6 +4,7 @@ import mineplex.core.boosters.BoosterApiResponse;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.shop.item.IButton;
import org.bukkit.entity.Player;
@ -12,6 +13,7 @@ import org.bukkit.event.inventory.ClickType;
/**
* @author Shaun Bennett
*/
@Deprecated
public class ActivateBoosterButton implements IButton
{
private BoosterShop _boosterShop;
@ -27,21 +29,26 @@ public class ActivateBoosterButton implements IButton
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
_boosterManager.activateBooster("Testing", player, new Callback<BoosterApiResponse>()
{
@Override
public void run(BoosterApiResponse response)
_boosterManager.chargeBooster(player, data -> {
if (data)
{
_boosterManager.activateBooster(player, response -> {
if (response.isSuccess())
{
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
if (timeToStart <= 0) player.sendMessage(C.cGreen + "Booster activated and enabled now!");
else player.sendMessage(C.cGreen + "Booster activated. Enabled in " + UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT));
if (timeToStart <= 0) player.sendMessage(F.main("Amplifier", "Amplifier Activated!"));
else player.sendMessage(F.main("Amplifier", "Game Amplifier Added. It will start in " + F.elem(UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT))));
}
else
{
player.sendMessage(C.cRed + "There was an error trying to enable your booster :(");
player.sendMessage(C.cRed + "There was an error trying to enable your Amplifier :(");
}
});
}
else
{
player.sendMessage(F.main("Amplifier", "There was an error charging your account. Try again later!"));
}
});
}

View File

@ -1,25 +1,33 @@
package mineplex.core.boosters.gui;
import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.BoosterCategory;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.boosters.BoosterProcessor;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.confirmation.ConfirmationPage;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import org.apache.commons.lang3.tuple.Triple;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Shaun Bennett
*/
public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
{
public BoosterPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, BoosterCategory category)
public BoosterPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Booster", player);
super(plugin, shop, clientManager, donationManager, "Game Amplifiers", player, 45);
buildPage();
}
@ -29,15 +37,194 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
{
ArrayList<String> lore = new ArrayList<>();
int amplifierCount = getPlugin().getAvailableBoosterCount(getPlayer());
lore.add(" ");
lore.add(C.cWhite + "You Own: " + getPlugin().getAvailableBoosterCount(getPlayer()));
if (getPlugin().canActivateBoosters())
lore.add(C.cWhite + "You own " + C.cGreen + amplifierCount + C.cWhite + " Game Amplifiers");
if (getPlugin().canActivateBoosters() && amplifierCount > 0)
{
List<Booster> boosters = getPlugin().getBoosters();
long waitTime = getPlugin().getBoostTime();
if (waitTime == 0)
{
lore.add(C.cWhite + "Amplifier would activate " + C.cGreen + "now");
lore.add(" ");
lore.add(C.cGray + "Once this Amplifier is activated");
lore.add(C.cGray + "or queued you are not able to");
lore.add(C.cGray + "cancel or refund it. You will still");
lore.add(C.cGray + "earn rewards if you are offline.");
lore.add(" ");
lore.add(C.cWhite + "Click to Activate Amplifier");
}
else
{
lore.add(" ");
lore.add(C.cWhite + "Click to Activate");
lore.add(C.cWhite + "Amplifier would activate in " + C.cGreen + UtilTime.convertColonString(waitTime, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS));
if (boosters.size() - 1 == 1)
{
lore.add(C.cWhite + "There is " + C.cGreen + 1 + C.cWhite + " Amplifier queued");
}
else if (boosters.size() - 1 > 0)
{
lore.add(C.cWhite + "There are " + C.cGreen + (boosters.size() - 1) + C.cWhite + " Amplifiers queued");
}
lore.add(" ");
lore.add(C.cGray + "Once this Amplifier is activated");
lore.add(C.cGray + "or queued you are not able to");
lore.add(C.cGray + "cancel or refund it. You will still");
lore.add(C.cGray + "earn rewards if you are offline.");
lore.add(" ");
lore.add(C.cWhite + "Click to Queue Amplifier");
}
}
else
{
lore.add(" ");
lore.add(C.cGray + "Game Amplifiers allow you to");
lore.add(C.cGray + "increase the gems and shards");
lore.add(C.cGray + "earned in that game for 1 hour.");
lore.add(C.cGray + "You will also earn bonus rewards");
lore.add(C.cGray + "from players thanking you while");
lore.add(C.cGray + "your amplifier is active.");
lore.add(" ");
lore.add(C.cWhite + "Get Amplifiers at " + C.cGreen + "mineplex.com/shop");
}
ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false);
setItem(4, booster);
ShopItem booster = new ShopItem(Material.SUGAR, "Game Amplifier", lore.toArray(new String[0]), 0, false, false);
if (getPlugin().canActivateBoosters() && amplifierCount > 0)
{
addButton(13, booster, this::openConfirmation);
}
else
{
setItem(13, booster);
}
addBoosterQueue();
// addOtherBoosters();
}
private void openConfirmation(Player player, ClickType type)
{
ArrayList<String> lore = new ArrayList<>();
lore.add(" ");
lore.add(C.cGray + "Once this Amplifier is activated");
lore.add(C.cGray + "or queued you are not able to");
lore.add(C.cGray + "cancel or refund it. You will still");
lore.add(C.cGray + "earn rewards if you are offline.");
ShopItem booster = new ShopItem(Material.SUGAR, "Game Amplifier", lore.toArray(new String[0]), 0, false, false);
BoosterProcessor processor = new BoosterProcessor(getPlugin(), getPlayer());
ConfirmationPage<BoosterManager, BoosterShop> page = new ConfirmationPage<>(getPlugin(), getShop(),
getClientManager(), getDonationManager(), getPlayer(), this, processor, booster);
getShop().openPageForPlayer(getPlayer(), page);
}
private void addBoosterQueue()
{
if (getPlugin().getBoosters() == null)
return;
List<Booster> boosters = getPlugin().getBoosters();
int startIndex = Math.max(0, (9 - boosters.size()) / 2);
for (int i = 0; i < boosters.size() && i < 18; i++)
{
int slot = startIndex + 27 + i;
Booster booster = boosters.get(i);
boolean active = booster.isActive();
int queueIndex = Math.max(1, i);
boolean owns = getPlayer().getUniqueId().equals(booster.getUuid());
long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime();
String activationTime = UtilTime.convertString(timeActivatedDif, 0, UtilTime.TimeUnit.FIT);
List<String> lore = new ArrayList<>();
if (active)
{
lore.add(C.cWhite + "Active");
lore.add(" ");
String expireTime = UtilTime.convertColonString(booster.getTimeRemaining(), UtilTime.TimeUnit.MINUTES, UtilTime.TimeUnit.SECONDS);
lore.add(C.cWhite + "Added by " + C.cGreen + booster.getPlayerName());
lore.add(C.cWhite + "Expires in " + C.cGreen + expireTime);
}
else
{
long timeToActive = booster.getStartTime().getTime() - System.currentTimeMillis();
String activeString = UtilTime.convertColonString(timeToActive, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS);
lore.add(" ");
lore.add(C.cWhite + "Added by " + C.cGreen + booster.getPlayerName());
lore.add(C.cWhite + "Starts in " + C.cGreen + activeString);
// lore.add(C.cWhite + "Position " + C.cGreen + queueIndex + C.cWhite + " in queue");
}
lore.add(" ");
lore.add(C.cGray + "Added " + activationTime + " ago");
ShopItem shopItem = new ShopItem(booster.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK,
"Game Amplifier", lore.toArray(new String[0]), queueIndex, !active, false);
setItem(slot, shopItem);
// Add glow if the booster belongs to you
if (owns)
{
addGlow(slot);
}
}
}
private void addOtherBoosters()
{
Map<String, List<Booster>> boosterMap = getPlugin().getBoosterCache();
List<Triple<Integer, String, Booster>> tripleList = new ArrayList<>();
for (Map.Entry<String, List<Booster>> entry : boosterMap.entrySet())
{
String boosterGroup = entry.getKey();
// dont display boosters for the current booster group
if (boosterGroup.equals(getPlugin().getBoosterGroup()))
continue;
List<Booster> boosters = entry.getValue();
for (int i = 0; i < boosters.size(); i++)
{
Booster booster = boosters.get(i);
if (booster.getUuid().equals(getPlayer().getUniqueId()))
{
tripleList.add(Triple.of(i, boosterGroup, booster));
}
}
}
int startIndex = Math.max(0, (9 - tripleList.size()) / 2);
for (int i = 0; i < 9 && i < tripleList.size(); i++)
{
Triple<Integer, String, Booster> triple = tripleList.get(i);
int deliveryAmount = Math.max(1, triple.getLeft());
String boosterGroup = triple.getMiddle();
Booster booster = triple.getRight();
long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime();
String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT);
List<String> lore = new ArrayList<String>();
lore.add(" ");
lore.add(C.cWhite + "Server: " + C.cGreen + boosterGroup);
if (booster.isActive())
{
lore.add(C.cWhite + "Expires in " + C.cGreen + UtilTime.convertColonString(booster.getTimeRemaining(), UtilTime.TimeUnit.MINUTES, UtilTime.TimeUnit.SECONDS));
}
else
{
long timeToActive = booster.getStartTime().getTime() - System.currentTimeMillis();
lore.add(C.cWhite + "Starts in " + C.cGreen + UtilTime.convertColonString(timeToActive, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS));
}
lore.add(" ");
lore.add(C.cGray + "Added " + activationTime + " ago");
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK,
"Game Amplifier", lore.toArray(new String[0]), 1, false, false);
setItem(startIndex + i + 27, shopItem);
}
}
}

View File

@ -5,7 +5,10 @@ import mineplex.core.boosters.BoosterManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
/**
* @author Shaun Bennett
@ -14,12 +17,21 @@ public class BoosterShop extends ShopBase<BoosterManager>
{
public BoosterShop(BoosterManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Boosters");
super(plugin, clientManager, donationManager, "Game Amplifiers");
}
@Override
protected ShopPageBase<BoosterManager, ? extends ShopBase<BoosterManager>> buildPagesFor(Player player)
{
return new MenuPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
return new BoosterPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
getPlayerPageMap().values().stream().filter(value -> value instanceof BoosterPage).forEach(ShopPageBase::refresh);
}
}

View File

@ -1,37 +0,0 @@
package mineplex.core.boosters.gui;
import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
/**
* @author Shaun Bennett
*/
public class MenuPage extends ShopPageBase<BoosterManager,BoosterShop>
{
public MenuPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Boosters", player);
buildPage();
}
@Override
protected void buildPage()
{
}
}

View File

@ -0,0 +1,44 @@
package mineplex.core.boosters.redis;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.event.BoosterUpdateEvent;
import mineplex.core.common.api.ApiFieldNamingStrategy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import redis.clients.jedis.JedisPubSub;
import java.util.List;
import java.util.Map;
/**
* @author Shaun Bennett
*/
public class BoosterUpdateListener extends JedisPubSub
{
private Gson _gson = new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy())
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create();
private JavaPlugin _plugin;
public BoosterUpdateListener(JavaPlugin plugin)
{
_plugin = plugin;
}
@Override
public void onMessage(String channel, String message)
{
try
{
Map<String, List<Booster>> boosterMap = _gson.fromJson(message, new TypeToken<Map<String, List<Booster>>>() {}.getType());
_plugin.getServer().getScheduler().runTask(_plugin, () -> Bukkit.getPluginManager().callEvent(new BoosterUpdateEvent(boosterMap)));
}
catch (Exception e)
{
System.out.println("Failed to load booster update");
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,39 @@
package mineplex.core.boosters.redis;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.RedisRepository;
import org.bukkit.plugin.java.JavaPlugin;
import redis.clients.jedis.Jedis;
/**
* @author Shaun Bennett
*/
public class BoosterUpdateRepository extends RedisRepository
{
private JavaPlugin _plugin;
public BoosterUpdateRepository(JavaPlugin plugin)
{
super(Region.ALL);
_plugin = plugin;
init();
}
private void init()
{
Thread thread = new Thread("Booster Subscriber")
{
@Override
public void run()
{
try (Jedis jedis = getResource(false))
{
jedis.subscribe(new BoosterUpdateListener(_plugin), "minecraft.boosters");
}
}
};
thread.start();
}
}

View File

@ -17,15 +17,15 @@ import java.sql.SQLException;
*/
public class BoosterTipManager extends MiniDbClientPlugin<PlayerTipData>
{
public static final int TIP_FOR_SPONSOR = 30;
public static final int TIP_FOR_TIPPER = 10;
public static final int TIP_FOR_SPONSOR = 5;
public static final int TIP_FOR_TIPPER = 5;
private BoosterTipRepository _repository;
private DonationManager _donationManager;
public BoosterTipManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("Booster Tips", plugin, clientManager);
super("Amplifier Thanks", plugin, clientManager);
_donationManager = donationManager;
_repository = new BoosterTipRepository(plugin);
@ -33,7 +33,7 @@ public class BoosterTipManager extends MiniDbClientPlugin<PlayerTipData>
public void addTip(Player player, Booster booster, Callback<TipAddResult> callback)
{
if (!Recharge.Instance.use(player, "Booster Tip", 1000 * 60 * 10, true, false))
if (!Recharge.Instance.use(player, "Amplifier Thanks", 1000 * 60 * 10, true, false))
{
callback.run(TipAddResult.ON_COOLDOWN);
return;
@ -57,7 +57,7 @@ public class BoosterTipManager extends MiniDbClientPlugin<PlayerTipData>
runAsync(() -> {
TipAddResult result;
if (_repository.addTip(accountId, booster.getAccountId(), booster.getBoosterId(), TIP_FOR_SPONSOR))
if (_repository.addTip(accountId, booster.getAccountId(), booster.getId(), TIP_FOR_SPONSOR))
{
_donationManager.rewardCoinsUntilSuccess(null, "Tips", player.getName(), accountId, TIP_FOR_TIPPER);
result = TipAddResult.SUCCESS;

View File

@ -5,9 +5,9 @@ package mineplex.core.boosters.tips;
*/
public enum TipAddResult
{
ALREADY_TIPPED_BOOSTER("You have already tipped!"),
ALREADY_TIPPED_BOOSTER("You have already thanked this Amplifier!"),
INVALID_ACCOUNT_ID("Uh oh, something went wrong. Try relogging"),
CANNOT_TIP_SELF("You can't tip yourself, silly!"),
CANNOT_TIP_SELF("You can't thank yourself, silly!"),
ON_COOLDOWN(null),
SUCCESS(null);

View File

@ -52,17 +52,4 @@ public class CosmeticShop extends ShopBase<CosmeticManager> implements PluginMes
{
new GadgetPage(getPlugin(), this, getClientManager(), getDonationManager(), "Gadgets", event.getPlayer()).purchaseGadget(event.getPlayer(), event.getGadget());
}
@EventHandler
public void updatePages(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
for (ShopPageBase<CosmeticManager, ? extends ShopBase<CosmeticManager>> shop : getPlayerPageMap().values())
{
if (shop instanceof BoosterPage)
((BoosterPage) shop).updatePage();
}
}
}

View File

@ -1,45 +0,0 @@
package mineplex.core.cosmetic.ui.page;
import mineplex.core.account.CoreClientManager;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import java.util.ArrayList;
/**
* @author Shaun Bennett
*/
public class BoosterPage extends ShopPageBase<CosmeticManager, CosmeticShop>
{
public BoosterPage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Game Boosters", player, 9);
buildPage();
}
@Override
protected void buildPage()
{
ArrayList<String> lore = new ArrayList<>();
lore.add(" ");
lore.add("You Own: " + _plugin.getBoosterManager().getAvailableBoosterCount(getPlayer()));
ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false);
setItem(4, booster);
}
public void updatePage()
{
refresh();
}
}

View File

@ -242,9 +242,4 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
{
getShop().openPageForPlayer(player, new MusicPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "Music", player));
}
public void openBoosters(Player player)
{
getShop().openPageForPlayer(player, new BoosterPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), player));
}
}

View File

@ -1,30 +0,0 @@
package mineplex.core.gadget.gadgets.item;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.types.ItemGadget;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class ItemGemBooster extends ItemGadget
{
public static final String NAME = "Gem Booster";
private static final String[] LORE = UtilText.splitLineToArray(C.cGray + "Get triple gems in any game on this server!", LineFormat.LORE);
public ItemGemBooster(GadgetManager manager)
{
super(manager, NAME, LORE, 1, Material.EMERALD, (byte) -1, 0,
new Ammo(NAME, NAME, Material.EMERALD, (byte) 0, LORE, -1, 0));
}
@Override
public void ActivateCustom(Player player)
{
player.getServer().getPluginManager().callEvent(new ActivateGemBoosterEvent(player));
}
}

View File

@ -1,87 +0,0 @@
package mineplex.core.gamebooster;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.cosmetic.ui.page.BoosterPage;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Set;
import java.util.UUID;
/**
* Handles activation of GameBoosters
*
* @author Shaun Bennett
*/
public class GameBoosterManager extends MiniPlugin
{
// The item name used for InventoryManager
private static final String BOOSTER_INVENTORY_ITEM = "Global.GameBooster";
private final CoreClientManager _clientManager;
private final DonationManager _donationManager;
private final InventoryManager _inventoryManager;
private final DataRepository<BoosterData> _boosterRepository;
private BoostGame _activeBoostGame;
public GameBoosterManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager)
{
super("Game Boosters", plugin);
_clientManager = clientManager;
_donationManager = donationManager;
_inventoryManager = inventoryManager;
_boosterRepository = new RedisDataRepository(Region.currentRegion(), BoosterData.class, "gemBooster");
}
/**
* Get the number of boosters available for a player for a specific BoostGame. Currently the BoostGame has no
* affect on the output (there aren't separate types of boosters), but we may need to introduce different booster
* items for different games in the future.
*
* @param player The player that owns the boosters
* @param game The game to check for boosters
* @return The amount of unactivated boosters that player owns
*/
public int getAvailableBoosters(Player player, BoostGame game)
{
return _inventoryManager.Get(player).getItemCount(BOOSTER_INVENTORY_ITEM);
}
/**
* Attempt to activate a booster from a player for a specific game. This will do all the required checks to make sure
* the player has boosters available and removes that booster from the player's account. This will return true if
* the booster was successfully added, or false if it wasn't
*
* @param player The player that owns the booster item
* @param game The game to be boosted
* @return True if the booster has been enabled and removed from the player account, false otherwise
*/
public boolean activateBooster(Player player, BoostGame game)
{
// TODO
return false;
}
/**
* Return the BoosterData for a specific BoostGame
* @param game The BoostGame we want data for
* @return The BoosterData instance for that game
*/
public BoosterData getBoosterData(BoostGame game)
{
BoosterData data = new BoosterData(game);
data.getBoostQueue().add(new BoosterData.BoostedGame("Phinary", UUID.randomUUID()));
return data;
}
}

View File

@ -1,10 +1,6 @@
package mineplex.core.hologram;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.UUID;
import java.util.*;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
@ -45,6 +41,7 @@ public class Hologram {
private boolean _makeDestroyPackets = true;
private boolean _makeSpawnPackets = true;
private Packet[] _packets1_8;
private Packet[] _packets1_9;
private HashSet<String> _playersInList = new HashSet<String>();
private ArrayList<Player> _playersTracking = new ArrayList<Player>();
private boolean _removeEntityDeath;
@ -58,13 +55,18 @@ public class Hologram {
private long _startTime;
public Hologram(HologramManager hologramManager, Location location, String... text) {
this(hologramManager, location, -1l, text);
this(hologramManager, location, false, -1l, text);
}
public Hologram(HologramManager hologramManager, Location location, long maxLifetime, String... text) {
public Hologram(HologramManager hologramManager, Location location, boolean hideBoundingBox, String... text) {
this(hologramManager, location, hideBoundingBox, -1l, text);
}
public Hologram(HologramManager hologramManager, Location location, boolean hideBoundingBox, long maxLifetime, String... text) {
_hologramManager = hologramManager;
_location = location.clone();
_maxLifetime = maxLifetime;
_hideBoundingBox = hideBoundingBox;
setText(text);
}
@ -163,13 +165,11 @@ public class Hologram {
return _playersTracking;
}
protected Packet[] getSpawnPackets() {
protected void checkSpawnPackets() {
if (_makeSpawnPackets) {
makeSpawnPackets();
_makeSpawnPackets = false;
}
return _packets1_8;
}
/**
@ -228,7 +228,8 @@ public class Hologram {
}
private void makeSpawnPackets() {
_packets1_8 = new Packet[_hologramText.length * 1];
_packets1_8 = new Packet[_hologramText.length];
_packets1_9 = new Packet[_hologramText.length];
if (_entityIds.size() < _hologramText.length) {
_makeDestroyPackets = true;
@ -244,22 +245,39 @@ public class Hologram {
}
}
for (int textRow = 0; textRow < _hologramText.length; textRow++) {
Packet[] packets1_8 = makeSpawnPackets1_8(textRow, _entityIds.get(textRow), _hologramText[textRow]);
PacketPlayOutSpawnEntityLiving packet1_8 = makeSpawnPacket1_8(textRow, _entityIds.get(textRow), _hologramText[textRow]);
PacketPlayOutSpawnEntityLiving packet1_9 = makeSpawnPacket1_9(textRow, _entityIds.get(textRow), _hologramText[textRow]);
for (int i = 0; i < packets1_8.length; i++) {
_packets1_8[textRow + i] = packets1_8[i];
}
_packets1_8[textRow] = packet1_8;
_packets1_9[textRow] = packet1_9;
}
}
private Packet[] makeSpawnPackets1_8(int textRow, int entityId, String lineOfText) {
/**
* Used for sending 1.9 clients holograms with no bounding boxes
*/
private PacketPlayOutSpawnEntityLiving makeSpawnPacket1_9(int textRow, int entityId, String lineOfText)
{
PacketPlayOutSpawnEntityLiving packet = makeSpawnPacket1_8(textRow, entityId, lineOfText);
if (_hideBoundingBox)
{
DataWatcher watcher = packet.l;
packet.d = (int) ((getLocation().getY() + ((double) textRow * 0.285)) * 32);
watcher.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16);
}
return packet;
}
private PacketPlayOutSpawnEntityLiving makeSpawnPacket1_8(int textRow, int entityId, String lineOfText) {
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
DataWatcher watcher = new DataWatcher(null);
packet.a = entityId;
packet.b = 30;
packet.c = (int) (getLocation().getX() * 32);
packet.d = (int) ((getLocation().getY() + (_hideBoundingBox ? 0 : -2.1) + ((double) textRow * 0.285)) * 32);
packet.d = (int) ((getLocation().getY() - 2.1 + ((double) textRow * 0.285)) * 32);
packet.e = (int) (getLocation().getZ() * 32);
packet.l = watcher;
packet.uuid = UUID.randomUUID();
@ -269,18 +287,7 @@ public class Hologram {
watcher.a(2, lineOfText, EntityArmorStand.META_CUSTOMNAME, lineOfText);
watcher.a(3, (byte) 1, EntityArmorStand.META_CUSTOMNAME_VISIBLE, true);
if (_hideBoundingBox) {
watcher.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16); // TODO
// Uncomment
// after
// we
// can
// enforce
// 1.8.3
}
// Also correct hologram positioning
return new Packet[] { packet };
return packet;
}
/**
@ -352,6 +359,7 @@ public class Hologram {
}
}
itel = canSee.iterator();
checkSpawnPackets();
while (itel.hasNext()) {
Player player = itel.next();
@ -359,7 +367,7 @@ public class Hologram {
_playersTracking.add(player);
itel.remove();
UtilPlayer.sendPacket(player, getSpawnPackets());
UtilPlayer.sendPacket(player, UtilPlayer.is1_9(player) ? _packets1_9 : _packets1_8);
}
}
if (!canSee.isEmpty()) {
@ -452,6 +460,7 @@ public class Hologram {
int[] destroy1_8 = new int[0];
ArrayList<Packet> packets1_8 = new ArrayList<Packet>();
ArrayList<Packet> packets1_9 = new ArrayList<>();
if (_hologramText.length != newText.length) {
_makeDestroyPackets = true;
@ -465,7 +474,8 @@ public class Hologram {
int entityId = UtilEnt.getNewEntityId();
_entityIds.add(entityId);
packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(i, entityId, newText[i])));
packets1_8.add(makeSpawnPacket1_8(i, entityId, newText[i]));
packets1_9.add(makeSpawnPacket1_9(i, entityId, newText[i]));
}
// If less lines than previously
else if (i >= newText.length) {
@ -479,29 +489,45 @@ public class Hologram {
Integer entityId = _entityIds.get(i);
PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata();
PacketPlayOutEntityMetadata metadata1_9 = new PacketPlayOutEntityMetadata();
metadata1_8.a = entityId;
metadata1_9.a = entityId;
DataWatcher watcher1_8 = new DataWatcher(null);
DataWatcher watcher1_9 = new DataWatcher(null);
{
watcher1_8.a(0, (byte) 32, EntityArmorStand.META_ENTITYDATA, (byte) 32);
watcher1_8.a(2, newText[i], EntityArmorStand.META_CUSTOMNAME, newText[i]);
watcher1_8.a(3, (byte) 1, EntityArmorStand.META_CUSTOMNAME_VISIBLE, true);
// watcher1_8.a(10, (byte) 16);// TODO Uncomment after we
// can enforce 1.8.3
// Also correct hologram positioning
}
{
watcher1_9.a(0, (byte) 32, EntityArmorStand.META_ENTITYDATA, (byte) 32);
watcher1_9.a(2, newText[i], EntityArmorStand.META_CUSTOMNAME, newText[i]);
watcher1_9.a(3, (byte) 1, EntityArmorStand.META_CUSTOMNAME_VISIBLE, true);
if (_hideBoundingBox)
{
watcher1_9.a(10, (byte) 16, EntityArmorStand.META_ARMOR_OPTION, (byte) 16);
}
}
metadata1_8.b = watcher1_8.c();
metadata1_9.b = watcher1_9.c();
packets1_8.add(metadata1_8);
packets1_9.add(metadata1_9);
}
}
if (destroy1_8.length > 0) {
packets1_8.add(new PacketPlayOutEntityDestroy(destroy1_8));
packets1_9.add(new PacketPlayOutEntityDestroy(destroy1_8));
}
for (Player player : _playersTracking) {
for (Packet packet : packets1_8) {
List<Packet> packets = UtilPlayer.is1_9(player) ? packets1_9 : packets1_8;
for (Packet packet : packets)
{
UtilPlayer.sendPacket(player, packet);
}
}
@ -532,15 +558,30 @@ public class Hologram {
_hologramManager.addHologram(this);
_playersTracking.addAll(getNearbyPlayers());
for (Player player : _playersTracking) {
UtilPlayer.sendPacket(player, getSpawnPackets());
}
sendPackets();
_lastMovement = new Vector();
}
return this;
}
private void sendPackets()
{
checkSpawnPackets();
for (Player player : _playersTracking)
{
UtilPlayer.sendPacket(player, UtilPlayer.is1_9(player) ? _packets1_9 : _packets1_8);
}
}
public Packet[] getSpawnPackets(Player player)
{
checkSpawnPackets();
return UtilPlayer.is1_9(player) ? _packets1_9 : _packets1_8;
}
/**
* Stop the hologram
*/

View File

@ -116,7 +116,7 @@ public class HologramManager implements Listener, IPacketHandler
{
hologram.getPlayersTracking().add(player);
UtilPlayer.sendPacket(player, hologram.getSpawnPackets());
UtilPlayer.sendPacket(player, hologram.getSpawnPackets(player));
}
}
}

View File

@ -1,38 +0,0 @@
package mineplex.core.inventory;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.shop.item.SalesPackageBase;
public class GemBooster extends SalesPackageBase
{
public GemBooster(boolean enabled, int gemBoosters)
{
super("20 Gem Booster Pack", Material.EMERALD, (byte)0, new String[]
{
C.cYellow + "1000 Coins",
" ",
(enabled ? C.cGreen + "Left-Click To Use:" : ""),
C.cWhite + "Use these before games start to",
C.cWhite + "boost the amount of Gems earned",
C.cWhite + "for all players in the game!",
" ",
C.cGreen + "Right-Click To Purchase:",
C.cWhite + "20 Gem Boosters for " + C.cYellow + "1000 Coins",
" ",
C.cWhite + "Your Gem Boosters: " + C.cGreen + gemBoosters
}, 1000, 20);
KnownPackage = false;
OneTimePurchaseOnly = false;
}
@Override
public void sold(Player player, CurrencyType currencyType)
{
}
}

View File

@ -160,7 +160,7 @@ public class PersonalServerManager extends MiniPlugin
}
final ServerGroup serverGroup = new ServerGroup(serverName, serverName, host.getName(), ram, cpu, 1, 0, UtilMath.random.nextInt(250) + 19999, true, "arcade.zip", "Arcade.jar", "plugins/Arcade/", minPlayers, maxPlayers,
true, false, false, games, "", "Player", true, event, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", "");
true, false, false, games, "", "", "Player", true, event, false, true, false, true, true, false, false, false, false, true, true, true, false, false, "", _us ? Region.US : Region.EU, "", "", "", "");
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{

View File

@ -0,0 +1,11 @@
package mineplex.core.shop.confirmation;
/**
* @author Shaun Bennett
*/
public interface ConfirmationCallback
{
public void resolve(String message);
public void reject(String message);
}

View File

@ -0,0 +1,210 @@
package mineplex.core.shop.confirmation;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
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.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
* @author Shaun Bennett
*/
public class ConfirmationPage<PluginType extends MiniPlugin, ShopType extends ShopBase<PluginType>> extends ShopPageBase<PluginType, ShopType> implements Runnable, ConfirmationCallback
{
private int _taskId;
private ShopPageBase<PluginType, ShopType> _returnPage;
private ItemStack _displayItem;
private ItemStack _progressItem = new ShopItem(Material.LAPIS_BLOCK, (byte)11, ChatColor.BLUE + "Processing", null, 1, false, true);
private int _okSquareSlotStart = 27;
private int _progressCount;
private ConfirmationProcessor _processor;
private boolean _processing;
public ConfirmationPage(PluginType plugin, ShopType shop, CoreClientManager clientManager, DonationManager donationManager, Player player, ShopPageBase<PluginType, ShopType> returnPage, ConfirmationProcessor processor, ItemStack displayItem)
{
super(plugin, shop, clientManager, donationManager, "Confirmation", player);
_returnPage = returnPage;
_displayItem = displayItem;
_processor = processor;
buildPage();
}
@Override
protected void buildPage()
{
setItem(22, _displayItem);
buildSquareAt(_okSquareSlotStart, new ShopItem(Material.EMERALD_BLOCK, (byte) 0, ChatColor.GREEN + "OK", null, 1, false, true), this::okClicked);
buildSquareAt(_okSquareSlotStart + 6, new ShopItem(Material.REDSTONE_BLOCK, (byte) 0, ChatColor.RED + "CANCEL", null, 1, false, true), this::cancelClicked);
}
protected void okClicked(Player player, ClickType clickType)
{
processTransaction();
}
protected void cancelClicked(Player player, ClickType clickType)
{
getPlugin().getScheduler().cancelTask(_taskId);
if (_returnPage != null)
getShop().openPageForPlayer(player, _returnPage);
else
{
player.closeInventory();
}
}
private void buildSquareAt(int slot, ShopItem item, IButton button)
{
addButton(slot, item, button);
addButton(slot + 1, item, button);
addButton(slot + 2, item, button);
slot += 9;
addButton(slot, item, button);
addButton(slot + 1, item, button);
addButton(slot + 2, item, button);
slot += 9;
addButton(slot, item, button);
addButton(slot + 1, item, button);
addButton(slot + 2, item, button);
}
private void processTransaction()
{
for (int i=_okSquareSlotStart; i < 54; i++)
{
getButtonMap().remove(i);
clear(i);
}
_processing = true;
_processor.process(this);
_taskId = getPlugin().getScheduler().scheduleSyncRepeatingTask(getPlugin().getPlugin(), this, 2L, 2L);
}
private void buildErrorPage(String... message)
{
ShopItem item = new ShopItem(Material.REDSTONE_BLOCK, (byte)0, ChatColor.RED + "" + ChatColor.UNDERLINE + "ERROR", message, 1, false, true);
for (int i = 0; i < this.getSize(); i++)
{
addButton(i, item, this::cancelClicked);
}
getPlayer().playSound(getPlayer().getLocation(), Sound.BLAZE_DEATH, 1, .1f);
}
private void buildSuccessPage(String message)
{
ShopItem item = new ShopItem(Material.EMERALD_BLOCK, (byte)0, ChatColor.GREEN + message, null, 1, false, true);
for (int i = 0; i < this.getSize(); i++)
{
addButton(i, item, this::cancelClicked);
}
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, .9f);
}
@Override
public void playerClosed()
{
super.playerClosed();
Bukkit.getScheduler().cancelTask(_taskId);
if (_returnPage != null && getShop() != null)
getShop().setCurrentPageForPlayer(getPlayer(), _returnPage);
}
@Override
public void run()
{
if (_processing)
{
if (_progressCount == 9)
{
for (int i=45; i < 54; i++)
{
clear(i);
}
_progressCount = 0;
}
setItem(45 + _progressCount, _progressItem);
}
else
{
if (_progressCount >= 20)
{
try
{
Bukkit.getScheduler().cancelTask(_taskId);
if (_returnPage != null && getShop() != null)
{
getShop().openPageForPlayer(getPlayer(), _returnPage);
}
else if (getPlayer() != null)
{
getPlayer().closeInventory();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
dispose();
}
}
}
_progressCount++;
}
@Override
public void dispose()
{
super.dispose();
Bukkit.getScheduler().cancelTask(_taskId);
}
@Override
public void resolve(String message)
{
_processing = false;
buildSuccessPage(message);
_progressCount = 0;
}
@Override
public void reject(String message)
{
_processing = false;
buildErrorPage(message);
_progressCount = 0;
}
}

View File

@ -0,0 +1,9 @@
package mineplex.core.shop.confirmation;
/**
* @author Shaun Bennett
*/
public interface ConfirmationProcessor
{
public void process(ConfirmationCallback callback);
}

View File

@ -0,0 +1,23 @@
package mineplex.core.youtube;
import java.time.LocalDate;
public class YoutubeClient
{
private LocalDate _clickDate;
public YoutubeClient(LocalDate date)
{
this._clickDate = date;
}
public LocalDate getClickDate()
{
return _clickDate;
}
public void setClickDate(LocalDate date)
{
_clickDate = date;
}
}

View File

@ -0,0 +1,75 @@
package mineplex.core.youtube;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class YoutubeManager extends MiniDbClientPlugin<YoutubeClient>
{
private final YoutubeRepository _repository;
private final DonationManager _donationManager;
public YoutubeManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("YoutubeManager", plugin, clientManager);
_donationManager = donationManager;
_repository = new YoutubeRepository(this);
}
public boolean canYoutube(Player player)
{
YoutubeClient client = Get(player);
LocalDate date = client.getClickDate();
if (date == null)
{
return true;
}
ZonedDateTime utcZoned = ZonedDateTime.now(ZoneOffset.UTC);
LocalDate utc = utcZoned.toLocalDate();
return !date.equals(utc);
}
public void attemptYoutube(Player player)
{
if (!canYoutube(player))
{
return;
}
YoutubeClient client = Get(player);
client.setClickDate(ZonedDateTime.now(ZoneOffset.UTC).toLocalDate());
_repository.attemptYoutube(player, client, () -> _donationManager.RewardCoinsLater("YouTube", player, 250));
}
@Override
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
boolean hasRow = resultSet.next();
if (hasRow)
Set(playerName, new YoutubeClient(resultSet.getDate(1).toLocalDate()));
else
Set(playerName, new YoutubeClient(null));
}
@Override
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT clicktime FROM youtube WHERE accountId=" + accountId + ";";
}
@Override
protected YoutubeClient AddPlayer(String player)
{
return new YoutubeClient(null);
}
}

View File

@ -0,0 +1,43 @@
package mineplex.core.youtube;
import mineplex.serverdata.database.DBPool;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class YoutubeRepository
{
private final YoutubeManager _manager;
public YoutubeRepository(YoutubeManager manager)
{
_manager = manager;
}
public void attemptYoutube(Player player, YoutubeClient client, Runnable runnable)
{
int accountId = _manager.getClientManager().Get(player).getAccountId();
Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), () ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement statement = connection.prepareStatement("REPLACE INTO youtube (accountId, clicktime) VALUES (?, ?)");
statement.setInt(1, accountId);
statement.setDate(2, Date.valueOf(client.getClickDate()));
statement.executeUpdate();
runnable.run();
}
catch (SQLException e)
{
e.printStackTrace();
}
});
}
}

View File

@ -23,7 +23,6 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.gadgets.item.ItemGemBooster;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.server.util.TransactionResponse;
import mineplex.core.updater.UpdateType;
@ -290,7 +289,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
_purchaseManager.addAccountPurchaseToQueue(client.getAccountId(), "Gem Boosters", amount, response);
}
}, client.getAccountId(), ItemGemBooster.NAME, amount);
}, client.getAccountId(), "Game Booster", amount);
return true;
}

View File

@ -530,6 +530,7 @@ public abstract class SiegeWeapon implements Listener
new Hologram(
_siegeManager.getClansManager().getHologramManager(),
_location.clone().add(UtilMath.random(-1, 1),1.4, UtilMath.random(-1, 1)),
false,
3500l,
C.cRed + "-" + health)
.start();

View File

@ -1,6 +1,7 @@
package mineplex.hub;
import mineplex.core.brawl.fountain.FountainManager;
import com.avaje.ebean.config.ServerConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -97,6 +98,7 @@ public class Hub extends JavaPlugin implements IRelation
new VelocityFix(this);
//Static Modules
new ProfileCacheManager(this);
CommandCenter.Initialize(this);
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(clientManager);
@ -109,7 +111,7 @@ public class Hub extends JavaPlugin implements IRelation
BlockRestore blockRestore = new BlockRestore(this);
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
new ServerConfiguration(this, clientManager);
ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);
//Other Modules
PacketHandler packetHandler = new PacketHandler(this);
@ -150,9 +152,10 @@ public class Hub extends JavaPlugin implements IRelation
CustomDataManager customDataManager = new CustomDataManager(this, clientManager);
PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager);
BoosterManager boosterManager = new BoosterManager(this, clientManager, donationManager, inventoryManager);
String boosterGroup = serverConfiguration.getServerGroup().getBoosterGroup();
BoosterManager boosterManager = new BoosterManager(this, boosterGroup, clientManager, donationManager, inventoryManager);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, boosterManager);
HologramManager hologramManager = new HologramManager(this, packetHandler);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, hologramManager, npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, boosterManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager);
ServerManager serverManager = new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, new StackerManager(hubManager), queueManager, boosterManager);
@ -195,8 +198,6 @@ public class Hub extends JavaPlugin implements IRelation
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true);
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true);
new ProfileCacheManager(this);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -1,48 +1,4 @@
package mineplex.hub;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import mineplex.core.boosters.BoosterManager;
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_8_R3.CraftWorld;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
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.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;
@ -51,17 +7,10 @@ import mineplex.core.aprilfools.AprilFoolsManager;
import mineplex.core.benefit.BenefitManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.*;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.customdata.CustomDataManager;
import mineplex.core.disguise.DisguiseManager;
@ -104,21 +53,9 @@ import mineplex.core.treasure.TreasureManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.valentines.ValentinesGiftManager;
import mineplex.hub.commands.DisguiseCommand;
import mineplex.hub.commands.ForcefieldRadius;
import mineplex.hub.commands.GadgetToggle;
import mineplex.hub.commands.GameModeCommand;
import mineplex.hub.commands.NewsCommand;
import mineplex.hub.modules.ForcefieldManager;
import mineplex.hub.modules.HubVisibilityManager;
import mineplex.hub.modules.JumpManager;
import mineplex.hub.modules.KothManager;
import mineplex.hub.modules.NewsManager;
import mineplex.hub.modules.ParkourManager;
import mineplex.hub.modules.SoccerManager;
import mineplex.hub.modules.TextManager;
import mineplex.hub.modules.ValentinesManager;
import mineplex.hub.modules.WorldManager;
import mineplex.core.youtube.YoutubeManager;
import mineplex.hub.commands.*;
import mineplex.hub.modules.*;
import mineplex.hub.profile.gui.GUIProfile;
import mineplex.hub.tutorial.TutorialManager;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
@ -132,6 +69,36 @@ import net.md_5.bungee.api.chat.HoverEvent.Action;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_8_R3.EntityInsentient;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
public class HubManager extends MiniClientPlugin<HubClient>
{
@ -226,7 +193,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager);
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
_bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, _gadgetManager);
YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager);
_bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _gadgetManager, boosterManager);
_treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager());
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager, boosterManager);

View File

@ -48,7 +48,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Memorize Gwen the Guardian's builds",
C.Reset + "Then recreate them in a short amount of time.",
C.Reset + "The least correct builder is eliminated.",
}, "SB", "SpeedBuilders", new SelectSBButton(this));
}, "SB", "Speed_Builders", new SelectSBButton(this));
add(4, Material.BOOK_AND_QUILL, C.cYellowB + "Draw My Thing " + C.cGray + "Pictionary", new String[]
{
@ -57,7 +57,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Players take turns at drawing a random",
C.Reset + "word. Whoever guesses it within the time",
C.Reset + "limit gets some points!",
}, "DMT", "DrawMyThing", new SelectDMTButton(this));
}, "DMT", "Draw_My_Thing", new SelectDMTButton(this));
add(6, Material.TNT, C.cYellowB + "Dragon Escape " + C.cGray + "Fast Paced Parkour", new String[]
{
@ -75,7 +75,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Then the bridges drop, and all hell",
C.Reset + "breaks loose as you battle to the",
C.Reset + "death with the other teams.",
}, "BR", "Bridge", new SelectBRButton(this));
}, "BR", "Bridges", new SelectBRButton(this));
add(11, Material.DIAMOND_SWORD, (byte) 0, C.cYellowB + "Survival Games " + C.cGray + "Solo/Team Survival", new String[]
{
@ -83,7 +83,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Search for chests to find loot and ",
C.Reset + "fight others to be the last man standing. ",
C.Reset + "Stay away from the borders!",
}, new String[] {"HG", "SG2"}, "SurvivalGames", new SelectSGButton(this));
}, new String[] {"HG", "SG2"}, "Survival_Games", new SelectSGButton(this));
add(13, Material.FEATHER, (byte) 0, C.cYellowB + "Skywars " + C.cGray + "Solo/Team Survival", new String[]
{
@ -93,7 +93,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Find weapons to take your enemies down!",
C.Reset + "Up in the skies, death looming if you fall..",
C.Reset + "Win! Fight! Send enemies flying in Skywars!",
}, new String[] {"SKY", "SKY2"}, "SkyWars", new SelectSKYButton(this));
}, new String[] {"SKY", "SKY2"}, "Skywars", new SelectSKYButton(this));
add(15, Material.GOLDEN_APPLE, C.cYellowB + "UHC " + C.cGray + "Ultra Hardcore Mode", new String[]
{
@ -133,7 +133,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Customize one of five exciting champions",
C.Reset + "and battle with the opposing team to the",
C.Reset + "last man standing.",
}, "TDM", "TeamDeathMatch", new SelectTDMButton(this));
}, "TDM", "Team_Deathmatch", new SelectTDMButton(this));
add(24, Material.DIAMOND_CHESTPLATE, C.cYellowB + "Castle Siege " + C.cGray + "Team Game", new String[]
{
@ -141,7 +141,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Defenders must protect King Sparklez",
C.Reset + "from the endless waves of Undead",
C.Reset + "until the sun rises!",
}, "CS", "CastleSiege", new SelectCSButton(this));
}, "CS", "Castle_Siege", new SelectCSButton(this));
add(26, Material.GRASS, C.cYellowB + "Block Hunt " + C.cGray + "Cat and Mouse", new String[]
{
@ -149,7 +149,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Hide as blocks/animals, upgrade your ",
C.Reset + "weapon and fight to survive against",
C.Reset + "the Hunters!",
}, "BH", "BlockHunt", new SelectBHButton(this));
}, "BH", "Block_Hunt", new SelectBHButton(this));
add(28, Material.TNT, C.cYellowB + "MineStrike " + C.cGray + "Team Survival", new String[]
{
@ -159,7 +159,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "and blow them up!",
}, "MS", "MineStrike", new SelectMSButton(this));
add(30, _superSmashCycle.get(_ssmIndex).clone(), null, null, new String[] {"SSM", "SSM2"}, "SmashMobs", new SelectSSMButton(this));
add(30, _superSmashCycle.get(_ssmIndex).clone(), null, null, new String[] {"SSM", "SSM2"}, "Smash_Mobs", new SelectSSMButton(this));
String[] games = new String[] {"MIN", "DR", "DE", "PB", "TF", "RUN", "SN", "DT", "SQ", "SA", "SS",
"OITQ", "BB", "MB", "EVO", "GLD", "BL"};
@ -171,7 +171,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Players are given a Build Theme and ",
C.Reset + "must use blocks, monsters and more",
C.Reset + "to create a masterpiece!",
}, "BLD", "MasterBuilders", new SelectBLDButton(this));
}, "BLD", "Master_Builders", new SelectBLDButton(this));
add(39, Material.SKULL_ITEM, (byte) 3, C.cYellowB + "Player Servers " + C.cGray + "Player Hosted Games", new String[]
{
@ -188,7 +188,7 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Equip custom skills and builds",
C.Reset + "and join your clan to destroy",
C.Reset + "and raid others!",
}, "Clans", "Clans", new SelectCLANSButton(this));
}, "Clans", null, new SelectCLANSButton(this));
add(41, Material.BREWING_STAND_ITEM, C.cYellowB + "Monster Maze " + C.cGray + "Snow Sprint", new String[]
{
@ -197,29 +197,30 @@ public class ServerGameMenu extends ShopPageBase<ServerManager, QuickShop>
C.Reset + "Run along a maze avoiding",
C.Reset + "evil monsters. Get to the",
C.Reset + "Safe-Pad or be killed!",
}, "BETA", "Beta", new SelectBETAButton(this));
}, "BETA", null, new SelectBETAButton(this));
}
private void add(int slot, Material material, String title, String[] lore, String serverTag, String serverGroup, IButton button)
private void add(int slot, Material material, String title, String[] lore, String serverTag, String boosterGroup, IButton button)
{
add(slot, material, (byte) 0, title, lore, serverTag == null ? null : new String[]{serverTag}, serverGroup, button);
add(slot, material, (byte) 0, title, lore, serverTag == null ? null : new String[]{serverTag}, boosterGroup, button);
}
private void add(int slot, Material material, byte data, String title, String[] lore, String[] serverTags, String serverGroup, IButton button)
private void add(int slot, Material material, byte data, String title, String[] lore, String[] serverTags, String boosterGroup, IButton button)
{
add(slot, new ItemBuilder(material, 1, data), title, lore, serverTags, serverGroup, button);
add(slot, new ItemBuilder(material, 1, data), title, lore, serverTags, boosterGroup, button);
}
private void add(int slot, ItemBuilder builder, String title, String[] lore, String[] serverTags, String serverGroup, IButton button)
private void add(int slot, ItemBuilder builder, String title, String[] lore, String[] serverTags, String boosterGroup, IButton button)
{
// Boosters
if (serverGroup != null)
if (boosterGroup != null)
{
Booster booster = getPlugin().getBoosterManager().getActiveBoosterFromCache(serverGroup);
Booster booster = getPlugin().getBoosterManager().getActiveBooster(boosterGroup);
if (booster != null)
{
// append to start of lore
builder.getLore().add(0, C.cGreen + "Boosted by " + C.cWhite + booster.getPlayerName() + C.cGreen + " - " + C.cWhite + booster.getTimeRemainingString());
builder.getLore().add(0, C.cWhite + "Amplified by " + C.cGreen + booster.getPlayerName() + C.cWhite + " - " + C.cGreen + booster.getTimeRemainingString());
builder.getLore().add(1, C.cWhite + "All players earn " + C.cGreen + "2x Gems" + C.cWhite + " and " + C.cAqua + "2x Shards");
builder.setGlow(true);
}
}

View File

@ -51,6 +51,7 @@ public class ServerGroup
private String _games;
private String _modes;
private String _boosterGroup;
private String _serverType;
private boolean _addNoCheat;
private boolean _addWorldEdit;
@ -89,6 +90,7 @@ public class ServerGroup
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
_games = data.get("games");
_modes = data.get("modes");
_boosterGroup = data.get("boosterGroup");
_serverType = data.get("serverType");
_addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
_addWorldEdit = Boolean.valueOf(data.get("addWorldEdit"));
@ -119,7 +121,7 @@ public class ServerGroup
}
public ServerGroup(String name, String prefix, String host, int ram, int cpu, int totalServers, int joinable, int portSection, boolean arcade, String worldZip, String plugin, String configPath
, int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String modes, String serverType, boolean noCheat, boolean worldEdit, boolean teamRejoin
, int minPlayers, int maxPlayers, boolean pvp, boolean tournament, boolean tournamentPoints, String games, String modes, String boosterGroup, String serverType, boolean noCheat, boolean worldEdit, boolean teamRejoin
, boolean teamAutoJoin, boolean teamForceBalance, boolean gameAutoStart, boolean gameTimeout, boolean rewardGems, boolean rewardItems, boolean rewardStats
, boolean rewardAchievements, boolean hotbarInventory, boolean hotbarHubClock, boolean playerKickIdle, boolean staffOnly, boolean whitelist, String resourcePack, Region region
, String teamServerKey, String portalBottomCornerLocation, String portalTopCornerLocation, String npcName)
@ -143,6 +145,7 @@ public class ServerGroup
_tournamentPoints = tournamentPoints;
_games = games;
_modes = modes;
_boosterGroup = boosterGroup;
_serverType = serverType;
_addNoCheat = noCheat;
_addWorldEdit = worldEdit;
@ -214,6 +217,8 @@ public class ServerGroup
public String getGames() { return _games; }
public String getModes() { return _modes; }
public String getBoosterGroup() { return _boosterGroup; }
public String getServerType() { return _serverType; }
public boolean getAddNoCheat() { return _addNoCheat; }
public boolean getAddWorldEdit() { return _addWorldEdit; }
@ -383,6 +388,8 @@ public class ServerGroup
_dataMap.put("host", _host);
_dataMap.put("region", _region.name());
_dataMap.put("teamServerKey", _teamServerKey);
_dataMap.put("modes", _modes);
_dataMap.put("boosterGroup", _boosterGroup);
_dataMap.put("portalBottomCornerLocation", _portalBottomCornerLocation);
_dataMap.put("portalTopCornerLocation", _portalTopCornerLocation);
_dataMap.put("npcName", _npcName);

View File

@ -129,6 +129,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
int winterChestsReceived = 0;
int illuminatedChestsReceived = 0;
int valentinesGiftsReceived = 0;
int boostersReceived = 0;
int freedomChestsReceived = 0;
for (CoinTransactionToken transaction : donor.getCoinTransactions())
@ -219,6 +220,17 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
}
}
if (transaction.SalesPackageName.startsWith("Game Booster"))
{
if (transaction.Coins == 0 && transaction.Gems == 0)
{
if (transaction.SalesPackageName.split(" ").length == 3)
boostersReceived += Integer.parseInt(transaction.SalesPackageName.split(" ")[2]);
else if (transaction.SalesPackageName.split(" ").length == 2)
boostersReceived += 1;
}
}
}
// Strutt20 asked me to remove some stuff from the menu
@ -227,6 +239,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
caller.sendMessage(C.cBlue + "Ancient Chests Received: " + C.cYellow + ancientChestsReceived);
caller.sendMessage(C.cBlue + "Mythical Chests Received: " + C.cYellow + mythicalChestsReceived);
caller.sendMessage(C.cBlue + "Illuminated Chests Received: " + C.cYellow + illuminatedChestsReceived);
caller.sendMessage(C.cBlue + "Game Amplifiers Received: " + C.cYellow + boostersReceived);
caller.sendMessage(C.cBlue + "Freedom Chests Received: " + C.cYellow + freedomChestsReceived);
caller.sendMessage(C.cBlue + "Monthly Bonus Log (Last 6 entries):");

View File

@ -98,6 +98,7 @@ public class Arcade extends JavaPlugin
CommandCenter.Initialize(this);
_clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(_clientManager);
new ProfileCacheManager(this);
ItemStackFactory.Initialize(this, false);
@ -158,16 +159,16 @@ public class Arcade extends JavaPlugin
PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress);
MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager);
GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager);
BoosterManager boosterManager = new BoosterManager(this, _clientManager, _donationManager, inventoryManager);
BoosterManager boosterManager = new BoosterManager(this, _serverConfiguration.getServerGroup().getBoosterGroup(), _clientManager, _donationManager, inventoryManager);
CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, null, boosterManager);
cosmeticManager.setInterfaceSlot(7);
cosmeticManager.setInterfaceSlot(6);
cosmeticManager.disableTeamArmor();
CustomDataManager customDataManager = new CustomDataManager(this, _clientManager);
//Arcade Manager
PollManager pollManager = new PollManager(this, _clientManager, _donationManager);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, incognito, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, customDataManager, punish, eloManager);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, incognito, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, customDataManager, punish, eloManager, boosterManager);
new GlobalPacketManager(this, _clientManager, serverStatusManager, inventoryManager, _donationManager, petManager, statsManager, _gameManager.getBonusManager().getRewardManager());
@ -178,8 +179,6 @@ public class Arcade extends JavaPlugin
new PacketsInteractionFix(this, packetHandler);
new FoodDupeFix(this);
new ProfileCacheManager(this);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
@ -212,6 +211,7 @@ public class Arcade extends JavaPlugin
try
{
config.ServerGroup = _serverConfiguration.getServerGroup().getName();
config.BoosterGroup = _serverConfiguration.getServerGroup().getBoosterGroup();
config.HostName = _serverConfiguration.getServerGroup().getHost();
config.ServerType = _serverConfiguration.getServerGroup().getServerType();
config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers();

View File

@ -6,6 +6,7 @@ import mineplex.core.achievement.AchievementManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.blood.Blood;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.chat.Chat;
import mineplex.core.common.Rank;
import mineplex.core.common.util.*;
@ -49,6 +50,7 @@ import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.valentines.ValentinesGiftManager;
import mineplex.core.youtube.YoutubeManager;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
@ -64,6 +66,13 @@ import mineplex.minecraft.game.core.fire.Fire;
import nautilus.game.arcade.addons.SoupAddon;
import nautilus.game.arcade.addons.TeamArmorAddon;
import nautilus.game.arcade.addons.compass.CompassAddon;
import nautilus.game.arcade.booster.GameBoosterManager;
import nautilus.game.arcade.command.DisguiseCommand;
import nautilus.game.arcade.command.GameCmdModeCommand;
import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.KitUnlockCommand;
import nautilus.game.arcade.command.RequiredRankCommand;
import nautilus.game.arcade.command.WriteCommand;
import nautilus.game.arcade.command.*;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
@ -80,6 +89,9 @@ import nautilus.game.arcade.shop.ArcadeShop;
import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.*;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Chest;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
@ -88,17 +100,11 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryType;
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.*;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
@ -165,6 +171,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private BonusManager _bonusManager;
private KitProgressionManager _kitProgressionManager;
private ProgressingKitManager _progressionKitManager;
private BoosterManager _boosterManager;
private IncognitoManager _incognitoManager;
@ -196,7 +203,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
StatsManager statsManager, IncognitoManager incognitoManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat,
Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler,
CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress, PollManager pollManager,
NpcManager npcManager, CustomDataManager customDataManager, Punish punish, EloManager eloManager)
NpcManager npcManager, CustomDataManager customDataManager, Punish punish, EloManager eloManager, BoosterManager boosterManager)
{
super("Game Manager", plugin);
@ -217,6 +224,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_brandingManager = new BrandingManager(plugin);
_boosterManager = boosterManager;
//Dont see a reason to ever just use the normal one
// if (serverConfig.GameList.contains(GameType.ChampionsDominate)
// || serverConfig.GameList.contains(GameType.ChampionsTDM)
@ -278,7 +287,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_gameTournamentManager = new GameTournamentManager(this);
new GameStatManager(this);
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
_bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, _cosmeticManager.getGadgetManager());
YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager);
_bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _cosmeticManager.getGadgetManager(), boosterManager);
new GameLootManager(this, petManager, _bonusManager.getRewardManager());
new GameSpectatorManager(this);
_gameWorldManager = new GameWorldManager(this);
@ -290,6 +300,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _cosmeticManager.getGadgetManager(), statsManager);
new GameTestingManager(this);
new PlayerDisguiseManager(plugin, _clientManager);
new GameBoosterManager(plugin, boosterManager, disguiseManager, hologramManager, npcManager, serverConfig.BoosterGroup);
// Game Addons
new CompassAddon(plugin, this);
@ -1425,6 +1436,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _youtube.contains(player);
}
public BoosterManager getBoosterManager()
{
return _boosterManager;
}
public void toggleUnlockKits(Player caller)
{
if (_youtube.remove(caller))

View File

@ -1,29 +1,34 @@
package nautilus.game.arcade.booster;
import com.mojang.authlib.GameProfile;
import mineplex.core.MiniPlugin;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.event.BoosterActivateEvent;
import mineplex.core.boosters.event.BoosterDeactivateEvent;
import mineplex.core.boosters.event.BoosterExpireEvent;
import mineplex.core.boosters.tips.BoosterTipManager;
import mineplex.core.common.util.*;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.npc.Npc;
import mineplex.core.npc.NpcManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.database.tables.records.NpcsRecord;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashSet;
/**
* @author Shaun Bennett
*/
@ -32,51 +37,67 @@ public class BoosterPodium extends MiniPlugin
private GameBoosterManager _gameBoosterManager;
private DisguiseManager _disguiseManager;
private HologramManager _hologramManager;
private NpcManager _npcManager;
private Location _podiumLocation;
private Booster _activeBooster;
private Npc _npc;
private boolean _npcAlive;
private Location _npcLocation;
private ArmorStand _activeArmorStand;
private Hologram _hologram;
public BoosterPodium(JavaPlugin plugin, GameBoosterManager gameBoosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, Location podiumLocation)
public BoosterPodium(JavaPlugin plugin, GameBoosterManager gameBoosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, NpcManager npcManager, Location podiumLocation)
{
super("Booster Podium - " + podiumLocation.toString(), plugin);
_gameBoosterManager = gameBoosterManager;
_disguiseManager = disguiseManager;
_hologramManager = hologramManager;
_npcManager = npcManager;
_podiumLocation = podiumLocation;
_npcLocation = podiumLocation.clone().add(0, 1, 0);
addPodium();
NpcsRecord npcsRecord = new NpcsRecord();
npcsRecord.setServer(_npcManager.getServerName());
npcsRecord.setName(C.cGreen + "Game Amplifiers");
npcsRecord.setWorld(_npcLocation.getWorld().getName());
npcsRecord.setX(_npcLocation.getX());
npcsRecord.setY(_npcLocation.getY());
npcsRecord.setZ(_npcLocation.getZ());
npcsRecord.setRadius(0D);
npcsRecord.setEntityType(EntityType.VILLAGER.name());
npcsRecord.setAdult(true);
_npcAlive = false;
_npc = new Npc(npcManager, npcsRecord);
setPodium(_podiumLocation, Material.EMERALD_BLOCK.getId(), (byte) 0);
updateNpcs();
}
public void addPodium()
{
for(int x = 0; x < 2; x++)
{
for (int z = 0; z < 2; z++)
{
Location location = _podiumLocation.clone().add(x - 0.5, 0, z - 0.5);
location.getBlock().setType(Material.STEP);
}
}
}
public void updateNpcs()
{
System.out.println("Updating Npcs.");
Booster activeBooster = _gameBoosterManager.getActiveBooster();
System.out.println("Active booster: " + activeBooster);
if (activeBooster != null)
{
if (_npcAlive)
{
_npcManager.removeFakeNpc(_npc);
_npcAlive = false;
}
if (_activeArmorStand != null)
{
_activeArmorStand.remove();
}
Location armorStandLocation = _podiumLocation.clone();
ArmorStand armorStand = _podiumLocation.getWorld().spawn(armorStandLocation, ArmorStand.class);
if (_hologram == null)
{
_hologram = new Hologram(_hologramManager, _npcLocation.clone().add(0, 2.5, 0), true, getHologramText(activeBooster));
_hologram.start();
}
ArmorStand armorStand = _podiumLocation.getWorld().spawn(_npcLocation, ArmorStand.class);
armorStand.setVisible(true);
armorStand.setCustomNameVisible(false);
armorStand.setCustomName("");
@ -85,18 +106,11 @@ public class BoosterPodium extends MiniPlugin
armorStand.setBasePlate(true);
armorStand.setRemoveWhenFarAway(false);
armorStand.setHelmet(UtilSkull.getPlayerHead(activeBooster.getPlayerName(), activeBooster.getPlayerName(), null));
armorStand.setChestplate(new ItemStack(Material.GOLD_CHESTPLATE));
armorStand.setLeggings(new ItemStack(Material.GOLD_LEGGINGS));
armorStand.setBoots(new ItemStack(Material.GOLD_BOOTS));
armorStand.setItemInHand(new ItemStack(Material.EMERALD));
if (_hologram == null)
{
_hologram = new Hologram(_hologramManager, armorStandLocation.clone().add(0, 2, 0), getHologramText(activeBooster));
_hologram.start();
}
armorStand.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE).setColor(Color.LIME).build());
armorStand.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS).setColor(Color.LIME).build());
armorStand.setBoots(new ItemBuilder(Material.LEATHER_BOOTS).setColor(Color.LIME).build());
// armorStand.setItemInHand();
/*
runAsync(() -> {
@ -135,6 +149,13 @@ public class BoosterPodium extends MiniPlugin
_hologram.stop();
_hologram = null;
}
if (!_npcAlive)
{
_npcManager.spawnNpc(_npc);
_npcManager.addFakeNpc(_npc);
_npcAlive = true;
}
}
}
@ -148,15 +169,15 @@ public class BoosterPodium extends MiniPlugin
private String getNameString(Booster booster)
{
return C.cGreen + "Boosted by " + C.cWhite + booster.getPlayerName() + C.cGreen + " - " + C.cWhite + booster.getTimeRemainingString();
return C.cGreen + "Amplified by " + C.cWhite + booster.getPlayerName() + C.cGreen + " - " + C.cWhite + booster.getTimeRemainingString();
}
private String[] getHologramText(Booster booster)
{
return new String[] {
C.cGreen + "Boosted by " + C.cWhite + booster.getPlayerName(),
C.cGreen + "Amplified by " + C.cWhite + booster.getPlayerName(),
C.cWhite + booster.getTimeRemainingString() + " Remaining",
C.cAqua + "Right Click to Tip. You get " + BoosterTipManager.TIP_FOR_TIPPER + " Treasure Shards"
C.cAqua + "Click to Thank. You get " + BoosterTipManager.TIP_FOR_TIPPER + " Treasure Shards"
};
}
@ -183,13 +204,13 @@ public class BoosterPodium extends MiniPlugin
}
@EventHandler
public void onBoosterDisable(BoosterDeactivateEvent event)
public void onBoosterDisable(BoosterExpireEvent event)
{
updateNpcs();
}
@EventHandler
public void onInteract(PlayerInteractAtEntityEvent event)
public void one(PlayerInteractAtEntityEvent event)
{
if (event.getRightClicked().equals(_activeArmorStand))
{
@ -207,4 +228,66 @@ public class BoosterPodium extends MiniPlugin
event.setCancelled(true);
}
}
public void setPodium(Location loc, int id, byte data)
{
HashSet<Block> blockSet = new HashSet<>();
//Coloring
Block block = loc.clone().add( 0.5, 0, 0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), id, data);
block = loc.clone().add(-0.5, 0, 0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), id, data);
block = loc.clone().add( 0.5, 0, -0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), id, data);
block = loc.clone().add(-0.5, 0, -0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), id, data);
//Top
block = loc.clone().add( 0.5, 1, 0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), 44, (byte)5);
block = loc.clone().add(-0.5, 1, 0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), 44, (byte)5);
block = loc.clone().add( 0.5, 1, -0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), 44, (byte)5);
block = loc.clone().add(-0.5, 1, -0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), 44, (byte)5);
//Floor
for (int x=-2 ; x<2 ; x++)
{
for (int z=-2 ; z<2 ; z++)
{
block = loc.clone().add(x + 0.5, -1, z + 0.5).getBlock();
blockSet.add(block);
MapUtil.QuickChangeBlockAt(block.getLocation(), id, data);
}
}
//Outline
for (int x=-3 ; x<3 ; x++)
{
for (int z=-3 ; z<3 ; z++)
{
block = loc.clone().add(x + 0.5, -1, z + 0.5).getBlock();
if (blockSet.contains(block)) continue;
MapUtil.QuickChangeBlockAt(block.getLocation(), 35, (byte)15);
}
}
}
}

View File

@ -4,7 +4,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.boosters.event.BoosterActivateEvent;
import mineplex.core.boosters.event.BoosterDeactivateEvent;
import mineplex.core.boosters.event.BoosterExpireEvent;
import mineplex.core.boosters.tips.BoosterTipManager;
import mineplex.core.boosters.tips.TipAddResult;
import mineplex.core.common.CurrencyType;
@ -13,38 +13,40 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.hologram.HologramManager;
import nautilus.game.arcade.game.GameServerConfig;
import mineplex.core.npc.NpcManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
/**
* @author Shaun Bennett
*/
public class GameBoosterManager extends MiniPlugin
{
private GameServerConfig _gameServerConfig;
private String _boosterGroup;
private BoosterManager _boosterManager;
private BoosterPodium _boosterPodium;
public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, GameServerConfig gameServerConfig)
public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, NpcManager npcManager, String boosterGroup)
{
super("Arcade Boosters", plugin);
_gameServerConfig = gameServerConfig;
_boosterGroup = boosterGroup;
_boosterManager = boosterManager;
_boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -12));
if (boosterGroup != null && boosterGroup.length() > 0)
{
_boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, npcManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -15));
}
}
public Booster getActiveBooster()
{
return _boosterManager.getActiveBoosterFromCache(_gameServerConfig.ServerGroup);
return _boosterManager.getActiveBooster(_boosterGroup);
}
public void attemptTip(Player player)
@ -53,21 +55,21 @@ public class GameBoosterManager extends MiniPlugin
if (active == null)
{
UtilPlayer.message(player, F.main("Tip", "There is no active booster to tip!"));
UtilPlayer.message(player, F.main("Thanks", "There is no active booster to Thank!"));
return;
}
_boosterManager.getTipManager().addTip(player, active, result -> {
if (result == TipAddResult.SUCCESS)
{
UtilPlayer.message(player, F.main("Tip", "Thanks for your tip! You earned "
+ F.currency(CurrencyType.TREASURE_SHARD, BoosterTipManager.TIP_FOR_TIPPER)));
}
else
UtilPlayer.message(player, F.main("Tip", "You thanked " + F.name(active.getPlayerName()) + ". They earned " + F.currency(CurrencyType.TREASURE_SHARD, BoosterTipManager.TIP_FOR_SPONSOR) + " and you got "
+ F.currency(CurrencyType.TREASURE_SHARD, BoosterTipManager.TIP_FOR_TIPPER)) + " in return!");
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
} else
{
if (result.getFriendlyMessage() != null)
{
UtilPlayer.message(player, F.main("Tip", result.getFriendlyMessage()));
UtilPlayer.message(player, F.main("Thanks", result.getFriendlyMessage()));
}
}
});
@ -76,14 +78,13 @@ public class GameBoosterManager extends MiniPlugin
@EventHandler
public void onActivate(BoosterActivateEvent event)
{
System.out.println("booster activate: " + event.getBooster());
Booster booster = event.getBooster();
Bukkit.broadcastMessage(F.main("Booster", F.name(booster.getPlayerName()) + " has activated a booster for " + booster.getMultiplier() + "x Gems!" ));
}
@EventHandler
public void onDeactivate(BoosterDeactivateEvent event)
if (event.getBoosterGroup().equals(_boosterGroup))
{
System.out.println("booster deactivate: " + event.getBooster());
Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated an Amplifier for " + booster.getMultiplier() + "x Gems and Shards!"));
} else
{
Bukkit.broadcastMessage(F.main("Amplifier", F.name(booster.getPlayerName()) + " has activated an Amplifier on " + F.elem(event.getBoosterGroup().replaceAll("_", " ")) + "!"));
}
}
}

View File

@ -22,10 +22,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.ProgressingKit;
import nautilus.game.arcade.kit.*;
import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.scoreboard.GameScoreboard;
@ -887,7 +884,7 @@ public abstract class Game implements Listener
{
kit.ApplyKit(player);
}
else
else if (!(kit instanceof ChampionsKit))
{
player.closeInventory();
}

View File

@ -9,6 +9,7 @@ public class GameServerConfig
{
public String ServerGroup = null;
public String ServerType = null;
public String BoosterGroup = null;
public int MinPlayers = -1;
public int MaxPlayers = -1;
public ArrayList<GameType> GameList = new ArrayList<GameType>();

View File

@ -180,10 +180,11 @@ public class GameGemManager implements Listener
}
//Gem Boooster
/*
if (game.GemBoosterEnabled && game.getGemBooster() != null)
total += (int)(earned * game.getGemBooster().getMultiplier());
*/
Booster booster = Manager.getBoosterManager().getActiveBooster();
if (game.GemBoosterEnabled && booster != null)
{
total *= booster.getMultiplier();
}
int shards = total;
@ -313,16 +314,14 @@ public class GameGemManager implements Listener
int totalGems = earnedGems;
//Gem Booster
/*
Booster gemBooster = game.getGemBooster();
if (game.GemBoosterEnabled && gemBooster != null)
Booster booster = Manager.getBoosterManager().getActiveBooster();
if (game.GemBoosterEnabled && booster != null)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int) (earnedGems * gemBooster.getMultiplier()) + " Gems") + " for gem booster from "
+ F.name(gemBooster.getPlayerName()));
int addedGems = (int) (earnedGems * booster.getMultiplier()) - earnedGems;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + addedGems + " Gems") + " for " + F.elem(booster.getPlayerName() + "'s Game Amplifier" + C.cGreen + " +" + booster.getIncreasePercent() + "%"));
totalGems += earnedGems * gemBooster.getMultiplier();
totalGems *= booster.getMultiplier();
}
*/
int shards = totalGems;

View File

@ -57,8 +57,6 @@ public class GameLobbyManager implements Listener
private Location spawn;
private Location _boosterLocation;
private NautHashMap<Entity, LobbyEnt> _kits = new NautHashMap<Entity, LobbyEnt>();
private NautHashMap<Block, Material> _kitBlocks = new NautHashMap<Block, Material>();
@ -1312,6 +1310,7 @@ public class GameLobbyManager implements Listener
//Cosmetic Menu
Manager.getCosmeticManager().giveInterfaceItem(player);
Manager.getBoosterManager().giveInterfaceItem(player);
}
}