Open Treasure chests through cosmetic gui, purchase treasure keys, some bug fixes
This commit is contained in:
parent
b8d157f99f
commit
51ad6d8368
@ -5,7 +5,7 @@ import org.bukkit.Material;
|
||||
public enum CurrencyType
|
||||
{
|
||||
Tokens(" Tokens", Material.EMERALD),
|
||||
Coins(" Coins", Material.GOLD_INGOT),
|
||||
Coins(" Coins", Material.DOUBLE_PLANT),
|
||||
Gems("Gems", Material.DIAMOND);
|
||||
|
||||
private String _prefix;
|
||||
|
@ -3,7 +3,6 @@ package mineplex.core.cosmetic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
@ -24,6 +23,7 @@ import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.mount.MountManager;
|
||||
import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.treasure.TreasureManager;
|
||||
|
||||
public class CosmeticManager extends MiniPlugin
|
||||
{
|
||||
@ -31,13 +31,19 @@ public class CosmeticManager extends MiniPlugin
|
||||
private GadgetManager _gadgetManager;
|
||||
private MountManager _mountManager;
|
||||
private PetManager _petManager;
|
||||
private TreasureManager _treasureManager;
|
||||
|
||||
private CosmeticShop _shop;
|
||||
|
||||
private boolean _showInterface = true;
|
||||
private int _interfaceSlot = 4;
|
||||
|
||||
|
||||
public CosmeticManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager, boolean useBooster)
|
||||
{
|
||||
this(plugin, clientManager, donationManager, inventoryManager, gadgetManager, mountManager, petManager, useBooster, null);
|
||||
}
|
||||
|
||||
public CosmeticManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, GadgetManager gadgetManager, MountManager mountManager, PetManager petManager, boolean useBooster, TreasureManager treasureManager)
|
||||
{
|
||||
super("Cosmetic Manager", plugin);
|
||||
|
||||
@ -45,6 +51,7 @@ public class CosmeticManager extends MiniPlugin
|
||||
_gadgetManager = gadgetManager;
|
||||
_mountManager = mountManager;
|
||||
_petManager = petManager;
|
||||
_treasureManager = treasureManager;
|
||||
|
||||
_shop = new CosmeticShop(this, clientManager, donationManager, _moduleName, useBooster);
|
||||
}
|
||||
@ -177,4 +184,9 @@ public class CosmeticManager extends MiniPlugin
|
||||
{
|
||||
return _showInterface;
|
||||
}
|
||||
|
||||
public TreasureManager getTreasureManager()
|
||||
{
|
||||
return _treasureManager;
|
||||
}
|
||||
}
|
||||
|
@ -3,21 +3,41 @@ package mineplex.core.cosmetic.ui.button;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.cosmetic.ui.page.Menu;
|
||||
import mineplex.core.shop.item.SingleButton;
|
||||
import mineplex.core.shop.item.IButton;
|
||||
|
||||
public class TreasureButton extends SingleButton
|
||||
public class TreasureButton implements IButton
|
||||
{
|
||||
private Menu _menu;
|
||||
private boolean _hasEnoughChests;
|
||||
private boolean _hasEnoughKeys;
|
||||
private boolean _canPurchaseKey;
|
||||
|
||||
public TreasureButton(Menu menu)
|
||||
public TreasureButton(Menu menu, boolean hasEnoughChests, boolean hasEnoughKeys, boolean canPurchaseKey)
|
||||
{
|
||||
_menu = menu;
|
||||
_hasEnoughChests = hasEnoughChests;
|
||||
_hasEnoughKeys = hasEnoughKeys;
|
||||
_canPurchaseKey = canPurchaseKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Clicked(Player player)
|
||||
public void ClickedLeft(Player player)
|
||||
{
|
||||
|
||||
if (_hasEnoughChests && _hasEnoughKeys)
|
||||
{
|
||||
_menu.openTreasure(player);
|
||||
player.closeInventory();
|
||||
}
|
||||
else if (_hasEnoughChests && _canPurchaseKey)
|
||||
{
|
||||
_menu.attemptPurchaseKey(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ClickedRight(Player player)
|
||||
{
|
||||
if (_canPurchaseKey)
|
||||
_menu.attemptPurchaseKey(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.cosmetic.ui.page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -8,6 +10,8 @@ import org.bukkit.entity.Player;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.cosmetic.event.ActivateGemBoosterEvent;
|
||||
import mineplex.core.cosmetic.ui.CosmeticShop;
|
||||
@ -29,13 +33,15 @@ import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.item.SingleButton;
|
||||
import mineplex.core.shop.page.ConfirmationPage;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.core.treasure.TreasureKey;
|
||||
import mineplex.core.treasure.TreasureManager;
|
||||
|
||||
public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
|
||||
{
|
||||
public Menu(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, "Inventory", player);
|
||||
|
||||
|
||||
BuildPage();
|
||||
}
|
||||
|
||||
@ -45,21 +51,35 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
|
||||
AddItem(2, new ShopItem(175, DonationManager.Get(Player.getName()).getCoins() + " Coins", 1, false));
|
||||
|
||||
int treasureChestCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Chest");
|
||||
int treasureKeyCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Key");
|
||||
boolean canPurchaseKey = DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= 1000;
|
||||
|
||||
if (treasureChestCount <= 0 && Player.getName().equals("Phinary"))
|
||||
{
|
||||
Plugin.getInventoryManager().addItemToInventory(Player, "Utility", "Treasure Chest", 1);
|
||||
treasureChestCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Chest");
|
||||
}
|
||||
// if (treasureChestCount <= 0 && Player.getName().equals("Phinary"))
|
||||
// {
|
||||
// Plugin.getInventoryManager().addItemToInventory(Player, "Utility", "Treasure Chest", 1);
|
||||
// treasureChestCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Chest");
|
||||
// }
|
||||
|
||||
if (treasureChestCount > 0)
|
||||
{
|
||||
AddButton(4, new ShopItem(Material.CHEST, C.cGold + treasureChestCount + " Treasure Chests", new String[] { ChatColor.RESET + "Click to Open Treasure Chest" }, 1, false), new TreasureButton(this));
|
||||
}
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
|
||||
lore.add(" ");
|
||||
lore.add(C.cYellow + "Treasure Keys Owned: " + ChatColor.RESET + treasureKeyCount);
|
||||
lore.add(" ");
|
||||
|
||||
if (treasureChestCount > 0 && treasureKeyCount > 0)
|
||||
lore.add(ChatColor.RESET + "Left Click to Open Treasure Chest");
|
||||
else if (treasureChestCount > 0)
|
||||
lore.add(ChatColor.RESET + "You must purchase a Treasure Key to open Treasure");
|
||||
else
|
||||
{
|
||||
AddItem(4, new ShopItem(Material.CHEST, ChatColor.RESET + C.cGold + treasureChestCount + " Treasure Chests" + ChatColor.RESET, new String[] { ChatColor.RESET + "Coming soon..." }, 1, false));
|
||||
}
|
||||
lore.add(ChatColor.RESET + "You do not own any Treasure Chests to unlock");
|
||||
|
||||
lore.add(" ");
|
||||
if (canPurchaseKey)
|
||||
lore.add(ChatColor.RESET + "Right Click to purchase Treasure Key");
|
||||
else
|
||||
lore.add(ChatColor.RESET + "You need 1000 coins to purchase a Treasure Key");
|
||||
|
||||
AddButton(4, new ShopItem(Material.CHEST, C.cGold + treasureChestCount + " Treasure Chests", lore.toArray(new String[0]), 1, false), new TreasureButton(this, treasureChestCount > 0, treasureKeyCount > 0, canPurchaseKey));
|
||||
|
||||
final GemBooster gemBoosterItem = new GemBooster(Shop.getBoosterEnabled(), Plugin.getInventoryManager().Get(Player).getItemCount("Gem Booster"));
|
||||
|
||||
@ -254,4 +274,30 @@ public class Menu extends ShopPageBase<CosmeticManager, CosmeticShop>
|
||||
{
|
||||
Shop.OpenPageForPlayer(player, new MusicPage(Plugin, Shop, ClientManager, DonationManager, "Music", player));
|
||||
}
|
||||
|
||||
public void openTreasure(Player player)
|
||||
{
|
||||
TreasureManager treasureManager = Plugin.getTreasureManager();
|
||||
if (treasureManager == null)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Treasure", "You cannot open treasures on this server"));
|
||||
}
|
||||
else
|
||||
{
|
||||
treasureManager.attemptOpenTreasure(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void attemptPurchaseKey(Player player)
|
||||
{
|
||||
Shop.OpenPageForPlayer(player, new ConfirmationPage<CosmeticManager, CosmeticShop>(Plugin, Shop, ClientManager, DonationManager, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
System.out.println("Added treasure key");
|
||||
Plugin.getInventoryManager().addItemToInventory(Player, "Treasure", "Treasure Key", 1);
|
||||
Refresh();
|
||||
}
|
||||
}, this, new TreasureKey(), CurrencyType.Coins, Player));
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public abstract class Reward
|
||||
{
|
||||
protected static final Random RANDOM = new Random();
|
||||
|
||||
// Reward Manager used to log rewards given to players. Shitty way to do this, but it works for now
|
||||
// Reward Manager used to log rewards given to players.
|
||||
private RewardManager _rewardManager;
|
||||
|
||||
private RewardRarity _rarity;
|
||||
|
@ -0,0 +1,28 @@
|
||||
package mineplex.core.treasure;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.shop.item.SalesPackageBase;
|
||||
|
||||
/**
|
||||
* Created by shaun on 14-09-18.
|
||||
*/
|
||||
public class TreasureKey extends SalesPackageBase
|
||||
{
|
||||
public TreasureKey()
|
||||
{
|
||||
super("Treasure Key", Material.LEVER, (byte) 0, new String[] { ChatColor.RESET + "Used to open Treasure Chests" }, 1000);
|
||||
|
||||
KnownPackage = false;
|
||||
OneTimePurchaseOnly = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Sold(Player player, CurrencyType currencyType)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -48,12 +49,14 @@ public class TreasureManager extends MiniPlugin
|
||||
{
|
||||
private NautHashMap<Player, Treasure> _playerTreasureMap;
|
||||
private RewardManager _rewardManager;
|
||||
private InventoryManager _inventoryManager;
|
||||
|
||||
public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager)
|
||||
{
|
||||
super("Treasure", plugin);
|
||||
|
||||
_playerTreasureMap = new NautHashMap<Player, Treasure>();
|
||||
_inventoryManager = inventoryManager;
|
||||
_rewardManager = new RewardManager(donationManager, inventoryManager,
|
||||
250, 500,
|
||||
750, 1500,
|
||||
@ -73,7 +76,7 @@ public class TreasureManager extends MiniPlugin
|
||||
|
||||
public void attemptOpenTreasure(Player player)
|
||||
{
|
||||
if (checkNearbyBlocks(player) || checkNearSpawn(player) || checkInAir(player) || checkNearbyTreasure(player))
|
||||
if (checkNearbyBlocks(player) || checkNearSpawn(player) || checkInAir(player) || checkNearbyTreasure(player) || checkNoTreasureAndKey(player))
|
||||
return;
|
||||
|
||||
TreasureStartEvent event = new TreasureStartEvent(player);
|
||||
@ -84,6 +87,10 @@ public class TreasureManager extends MiniPlugin
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove a treasure and a key
|
||||
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", -1);
|
||||
_inventoryManager.addItemToInventory(player, "Treasure", "Treasure Chest", -1);
|
||||
|
||||
Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + C.cGreen + "Treasure Chest"));
|
||||
|
||||
Reward[] rewards = _rewardManager.getRewards(player, true);
|
||||
@ -103,6 +110,23 @@ public class TreasureManager extends MiniPlugin
|
||||
|
||||
}
|
||||
|
||||
private boolean checkNoTreasureAndKey(Player player)
|
||||
{
|
||||
int treasureCount = _inventoryManager.Get(player).getItemCount("Treasure Chest");
|
||||
int treasureKeyCount = _inventoryManager.Get(player).getItemCount("Treasure Key");
|
||||
|
||||
if (treasureCount < 1)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Treasure", "You don't have any treasure chests."));
|
||||
}
|
||||
else if (treasureKeyCount < 1)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Treasure", "You don't have any treasure keys."));
|
||||
}
|
||||
|
||||
return (treasureCount < 1 || treasureKeyCount < 1);
|
||||
}
|
||||
|
||||
private boolean checkNearbyTreasure(Player player)
|
||||
{
|
||||
boolean nearTreasure = false;
|
||||
@ -281,6 +305,19 @@ public class TreasureManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void inventoryOpen(InventoryOpenEvent event)
|
||||
{
|
||||
// Prevent players in treasures from opening inventories
|
||||
if (event.getPlayer() instanceof Player)
|
||||
{
|
||||
if (_playerTreasureMap.containsKey(((Player) event.getPlayer())))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void interact(PlayerInteractEvent event)
|
||||
{
|
||||
|
@ -53,10 +53,7 @@ import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTitle;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.treasure.TreasureManager;
|
||||
import mineplex.minecraft.game.core.condition.ConditionManager;
|
||||
import mineplex.core.cosmetic.CosmeticManager;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.disguise.disguises.DisguiseSlime;
|
||||
@ -72,6 +69,7 @@ import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.projectile.ProjectileManager;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.treasure.TreasureManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.commands.ForcefieldRadius;
|
||||
@ -83,7 +81,6 @@ import mineplex.hub.modules.MapManager;
|
||||
import mineplex.hub.modules.NewsManager;
|
||||
import mineplex.hub.modules.ParkourManager;
|
||||
import mineplex.hub.modules.TextManager;
|
||||
import mineplex.hub.modules.UHCManager;
|
||||
import mineplex.hub.modules.VisibilityManager;
|
||||
import mineplex.hub.modules.WorldManager;
|
||||
import mineplex.hub.party.Party;
|
||||
@ -92,6 +89,7 @@ import mineplex.hub.poll.PollManager;
|
||||
import mineplex.hub.tutorial.TutorialManager;
|
||||
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
|
||||
import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent;
|
||||
import mineplex.minecraft.game.core.condition.ConditionManager;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
|
||||
public class HubManager extends MiniClientPlugin<HubClient>
|
||||
@ -117,6 +115,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
private InventoryManager _inventoryManager;
|
||||
private NewsManager _news;
|
||||
private AchievementManager _achievementManager;
|
||||
private TreasureManager _treasureManager;
|
||||
|
||||
private Location _spawn;
|
||||
private int _scoreboardTick = 0;
|
||||
@ -161,8 +160,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
_mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager);
|
||||
_inventoryManager = new InventoryManager(plugin);
|
||||
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin));
|
||||
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false);
|
||||
new TreasureManager(_plugin, donationManager, _inventoryManager);
|
||||
_treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager);
|
||||
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false, _treasureManager);
|
||||
|
||||
_partyManager = partyManager;
|
||||
_preferences = preferences;
|
||||
|
Loading…
Reference in New Issue
Block a user