Valentines gifts

This commit is contained in:
Shaun Bennett 2016-02-08 22:26:33 -06:00
parent a8ff714ee4
commit a868b8b2b8
12 changed files with 340 additions and 41 deletions

View File

@ -818,7 +818,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
}
@EventHandler
@EventHandler(ignoreCancelled = true)
public void openGui(PlayerInteractEntityEvent event)
{
if (!_enabled)
@ -832,23 +832,6 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
}
@EventHandler
public void openGui(EntityDamageByEntityEvent event)
{
if (!_enabled)
return;
if (event.getDamager() instanceof Player)
{
Player player = (Player) event.getDamager();
if (event.getEntity().equals(_carlNpc.getEntity()))
{
updateDailyStreak(player);
new BonusGui(_plugin, player, this, _rewardManager, _facebookManager).openInventory();
}
}
}
public static long getNextVoteTime(long time) {
Calendar calendar = Calendar.getInstance();

View File

@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mineplex.core.gadget.gadgets.item.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -50,22 +51,6 @@ import mineplex.core.gadget.gadgets.hat.HatPresent;
import mineplex.core.gadget.gadgets.hat.HatRudolph;
import mineplex.core.gadget.gadgets.hat.HatSanta;
import mineplex.core.gadget.gadgets.hat.HatSnowman;
import mineplex.core.gadget.gadgets.item.ItemBatGun;
import mineplex.core.gadget.gadgets.item.ItemBow;
import mineplex.core.gadget.gadgets.item.ItemCoal;
import mineplex.core.gadget.gadgets.item.ItemCoinBomb;
import mineplex.core.gadget.gadgets.item.ItemDuelingSword;
import mineplex.core.gadget.gadgets.item.ItemEtherealPearl;
import mineplex.core.gadget.gadgets.item.ItemFirework;
import mineplex.core.gadget.gadgets.item.ItemFleshHook;
import mineplex.core.gadget.gadgets.item.ItemFreezeCannon;
import mineplex.core.gadget.gadgets.item.ItemLovePotion;
import mineplex.core.gadget.gadgets.item.ItemMelonLauncher;
import mineplex.core.gadget.gadgets.item.ItemPaintballGun;
import mineplex.core.gadget.gadgets.item.ItemPaintbrush;
import mineplex.core.gadget.gadgets.item.ItemPartyPopper;
import mineplex.core.gadget.gadgets.item.ItemSnowball;
import mineplex.core.gadget.gadgets.item.ItemTNT;
import mineplex.core.gadget.gadgets.morph.MorphBat;
import mineplex.core.gadget.gadgets.morph.MorphBlaze;
import mineplex.core.gadget.gadgets.morph.MorphBlock;
@ -210,6 +195,7 @@ public class GadgetManager extends MiniPlugin
addGadget(new ItemSnowball(this));
addGadget(new ItemBow(this));
addGadget(new ItemLovePotion(this));
addGadget(new ItemFlowerGift(this));
// Costume
addGadget(new OutfitRaveSuitHelmet(this));

View File

@ -0,0 +1,115 @@
package mineplex.core.gadget.gadgets.item;
import mineplex.core.common.util.*;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.ItemGadgetOutOfAmmoEvent;
import mineplex.core.gadget.gadgets.Ammo;
import mineplex.core.gadget.types.ItemGadget;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.core.valentines.event.AttemptGiftEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
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.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class ItemFlowerGift extends ItemGadget
{
public ItemFlowerGift(GadgetManager manager)
{
super(manager,
"Valentines Gift",
UtilText.splitLineToArray(C.cGray + "Maybe you can win over Chiss' heart with this!", LineFormat.LORE),
1,
Material.RED_ROSE,
(byte) 0,
2000,
new Ammo("Valentines Gift", "Valentines Gift", Material.RED_ROSE, (byte) 0, UtilText.splitLineToArray(C.cGray + "Maybe you can win over Chiss' heart with this!", LineFormat.LORE), 1, 10));
}
@Override
public void ActivateCustom(Player player)
{
}
@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractAtEntityEvent event)
{
Player player = event.getPlayer();
if (!IsActive(player))
return;
if (!UtilGear.isMat(player.getItemInHand(), GetDisplayMaterial()))
return;
if (!hasAmmo(player))
{
UtilPlayer.message(player, F.main("Gadget", "You do not have any " + GetName() + " left."));
ItemGadgetOutOfAmmoEvent ammoEvent = new ItemGadgetOutOfAmmoEvent(event.getPlayer(), this);
Bukkit.getServer().getPluginManager().callEvent(ammoEvent);
return;
}
//Recharge
if (!Recharge.Instance.use(player, GetName(), GetName(), _recharge, _recharge > 1000, true, false, true, "Cosmetics"))
{
UtilInv.Update(player);
return;
}
if (event.getRightClicked() instanceof Player)
{
Player to = ((Player) event.getRightClicked());
AttemptGiftEvent giftEvent = new AttemptGiftEvent(player, to);
Bukkit.getPluginManager().callEvent(giftEvent);
}
else
{
UtilPlayer.message(player, F.main("Gadget", "You used " + F.elem("Give Rose") + " on " + F.name(event.getRightClicked().getName()) + ". It's not very effective..."));
}
event.setCancelled(true);
}
@Override
@EventHandler
public void Activate(PlayerInteractEvent event)
{
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (!IsActive(event.getPlayer()))
return;
if (!UtilGear.isMat(event.getPlayer().getItemInHand(), GetDisplayMaterial()))
return;
//Recharge
if (!Recharge.Instance.use(event.getPlayer(), GetName(), GetName(), _recharge, false, true, false, true, "Cosmetics"))
return;
if (!hasAmmo(event.getPlayer()))
{
UtilPlayer.message(event.getPlayer(), F.main("Gadget", "You do not have any " + GetName() + " left."));
ItemGadgetOutOfAmmoEvent ammoEvent = new ItemGadgetOutOfAmmoEvent(event.getPlayer(), this);
Bukkit.getServer().getPluginManager().callEvent(ammoEvent);
return;
}
event.setCancelled(true);
// Logic is handled in onInteract (so we can cancel interact events on npc's)
UtilPlayer.message(event.getPlayer(), F.main("Gadget", "Nothing happened... Maybe I should try giving this to someone?!"));
}
}

View File

@ -236,7 +236,7 @@ public class NpcManager extends MiniPlugin
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event)
{
if (event.getRightClicked() instanceof LivingEntity)

View File

@ -101,6 +101,10 @@ public class RewardManager
maxValue *= 2;
}
// Valentines
addReward(RewardPool.Type.VALENTINES_GIFT, new TreasureShardReward(_clientManager, donationManager, 50, 100, 10, rarity));
// Christmas
addReward(RewardPool.Type.WINTER_HOLIDAY, new InventoryReward(inventoryManager, "Coal", "Coal", 50, 100,
new ItemStack(Material.COAL), rarity, 10, 0));
@ -162,6 +166,13 @@ public class RewardManager
maxValue *= 2;
}
// Valentines
addReward(RewardPool.Type.VALENTINES_GIFT, new InventoryReward(inventoryManager, "Love Potion", "Love Potion", 1, 2,
new ItemStack(Material.POTION, 1), rarity, 10, 0));
addReward(RewardPool.Type.VALENTINES_GIFT, new InventoryReward(inventoryManager, "Cupid's Arrows", "Cupid Arrow", 1, 10,
new ItemStack(Material.BOW, 1), rarity, 10, 0));
// Christmas
addReward(RewardPool.Type.WINTER_HOLIDAY, new InventoryReward(inventoryManager, "Freeze Cannon", "Freeze Cannon", 5, 10,
new ItemStack(Material.ICE), rarity, 10, 0));
addReward(RewardPool.Type.WINTER_HOLIDAY, new InventoryReward(inventoryManager, "Party Popper", "Party Popper", 5, 10,
@ -257,6 +268,10 @@ public class RewardManager
// addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 100, RewardRarity.RARE));
}
// Valentines
addReward(RewardPool.Type.VALENTINES_GIFT, new TreasureShardReward(_clientManager, donationManager, 100, 300, 10, rarity));
// Christmas
addReward(RewardPool.Type.WINTER_HOLIDAY, new UnknownPackageReward(donationManager, "Hat", "Santa", "Santa",
SkinData.SANTA.getSkull(), rarity, 5, _rareShards));
addReward(RewardPool.Type.WINTER_HOLIDAY, new PetReward(petManager, inventoryManager, donationManager, "Elf", "Christmas Elf",
@ -326,6 +341,17 @@ public class RewardManager
// addReward(new CoinReward(donationManager, (int)minValue, (int)maxValue, 25, rarity));
}
// Valentines
addReward(RewardPool.Type.VALENTINES_GIFT, new UnknownPackageReward(donationManager, "Arrow Effect", "Arrows of Cupid", "Arrows of Cupid",
new ItemStack(Material.POTION), rarity, 10, _rareShards));
addReward(RewardPool.Type.VALENTINES_GIFT, new UnknownPackageReward(donationManager, "Death Effect", "Broken Hearted", "Broken Hearted",
new ItemStack(Material.POTION), rarity, 10, _rareShards));
addReward(RewardPool.Type.VALENTINES_GIFT, new UnknownPackageReward(donationManager, "Jump Effect", "Wings of Love", "Wings of Love",
new ItemStack(Material.POTION), rarity, 10, _rareShards));
addReward(RewardPool.Type.VALENTINES_GIFT, new UnknownPackageReward(donationManager, "Particles", "Heartfelt Halo", "Heartfelt Halo",
new ItemStack(Material.POTION), rarity, 10, _rareShards));
// Christmas
addReward(RewardPool.Type.WINTER_HOLIDAY, new UnknownPackageReward(donationManager, "Hat", "The Grinch", "The Grinch",
SkinData.THE_GRINCH.getSkull(), rarity, 5, _legendaryShards));
addReward(RewardPool.Type.WINTER_HOLIDAY, new UnknownPackageReward(donationManager, "Morph", "Olaf", "Olaf Morph",

View File

@ -35,6 +35,7 @@ public class RewardPool
public static enum Type
{
NORMAL,
WINTER_HOLIDAY;
WINTER_HOLIDAY,
VALENTINES_GIFT;
}
}

View File

@ -11,6 +11,7 @@ public enum RewardType
AncientChest( 0, 2, 8, 32),
MythicalChest( 0.1, 4, 16, 72),
WinterChest( 0, 5, 18, 32),
ValentinesGift( 9, 10, 25, 40),
SpinnerFiller( 0.1, 1, 4, 20),
SpinnerReal( 0.000001, 0.05, 0.4, 5);

View File

@ -1,6 +1,7 @@
package mineplex.core.reward.rewards;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.UtilMath;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -18,7 +19,8 @@ public class TreasureShardReward extends Reward
private CoreClientManager _clientManager;
private DonationManager _donationManager;
private Reward _otherReward;
private int _shards = 0;
private int _shardsMin = 0;
private int _shardsMax = 0;
public TreasureShardReward(CoreClientManager clientManager, DonationManager donationManager, Reward otherReward, int weight, RewardRarity rarity)
{
@ -28,14 +30,36 @@ public class TreasureShardReward extends Reward
_donationManager = donationManager;
_otherReward = otherReward;
_shards += (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
_shardsMin = (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
_shardsMax = _shardsMin;
}
public TreasureShardReward(CoreClientManager clientManager, DonationManager donationManager, int min, int max, int weight, RewardRarity rarity)
{
super(rarity, weight, 0);
_clientManager = clientManager;
_donationManager = donationManager;
_shardsMin = min;
_shardsMax = max;
}
@Override
public RewardData giveRewardCustom(Player player, RewardType rewardType)
{
RewardData fakeData = _otherReward.getFakeRewardData(player);
RewardData rewardData = new RewardData(fakeData.getHeader(), fakeData.getFriendlyName(), fakeData.getDisplayItem(), fakeData.getRarity(), _shards);
RewardData rewardData;
final int shards = UtilMath.rRange(_shardsMin, _shardsMax);
if (_otherReward != null)
{
RewardData fakeData = _otherReward.getFakeRewardData(player);
rewardData = new RewardData(fakeData.getHeader(), fakeData.getFriendlyName(), fakeData.getDisplayItem(), fakeData.getRarity(), shards);
}
else
{
rewardData = new RewardData(null, getRarity().getColor() + shards + " Treasure Shards", new ItemStack(Material.PRISMARINE_SHARD), getRarity());
}
int accountId = _clientManager.getAccountId(player);
@ -45,7 +69,7 @@ public class TreasureShardReward extends Reward
@Override
public void run()
{
_donationManager.rewardCoinsUntilSuccess(null, "Treasure", player.getName(), accountId, _shards);
_donationManager.rewardCoinsUntilSuccess(null, "Treasure", player.getName(), accountId, shards);
}
}, 100);

View File

@ -0,0 +1,91 @@
package mineplex.core.valentines;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.reward.*;
import mineplex.core.valentines.event.AttemptGiftEvent;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class ValentinesGiftManager extends MiniPlugin
{
private final String ITEM_NAME = "Valentines Gift";
private final Material ITEM_MATERIAL = Material.RED_ROSE;
private CoreClientManager _clientManager;
private RewardManager _rewardManager;
private InventoryManager _inventoryManager;
private GadgetManager _gadgetManager;
private ValentinesGiftRepository _repository;
public ValentinesGiftManager(JavaPlugin plugin, CoreClientManager clientManager, RewardManager rewardManager, InventoryManager inventoryManager, GadgetManager gadgetManager)
{
super("Valentines", plugin);
_clientManager = clientManager;
_rewardManager = rewardManager;
_inventoryManager = inventoryManager;
_gadgetManager = gadgetManager;
_repository = new ValentinesGiftRepository(plugin);
}
@EventHandler
public void onAttemptGift(AttemptGiftEvent event)
{
Player from = event.getFrom();
Player to = event.getTo();
final int fromId = _clientManager.getAccountId(from);
final int toId = _clientManager.getAccountId(to);
runAsync(() -> {
// final boolean complete = _repository.giveGift(fromId, toId);
final boolean complete = true;
runSync(() -> giveGift(from, to, complete));
});
}
private void giveGift(Player from, Player to, boolean success)
{
if (success)
{
_rewardManager.nextReward(to, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.ValentinesGift, false).giveReward(RewardType.ValentinesGift, to, new Callback<RewardData>()
{
@Override
public void run(RewardData data)
{
UtilPlayer.message(to, F.main("Gift", F.name(from.getName()) + " gave you " + data.getRarity().getColor() + data.getFriendlyName()));
UtilPlayer.message(from, F.main("Gift", "You gave " + F.name(to.getName()) + " " + data.getRarity().getColor() + data.getFriendlyName()));
}
});
_rewardManager.nextReward(from, RewardPool.Type.VALENTINES_GIFT, null, false, RewardType.ValentinesGift, false).giveReward(RewardType.ValentinesGift, from, new Callback<RewardData>()
{
@Override
public void run(RewardData data)
{
UtilPlayer.message(from, F.main("Gift", "You found " + F.elem(data.getRarity().getColor() + data.getFriendlyName()) + " for your good karma"));
}
});
_inventoryManager.addItemToInventory(from, ITEM_NAME, -1);
from.getInventory().setItem(_gadgetManager.getActiveItemSlot(), ItemStackFactory.Instance.CreateStack(ITEM_MATERIAL, (byte) 0, 1, F.item(_inventoryManager.Get(from).getItemCount(ITEM_NAME) + " " + ITEM_NAME)));
}
else
{
UtilPlayer.message(from, F.main("Gadget", "You have already given a gift to " + F.name(to.getName()) + "!"));
}
}
}

View File

@ -0,0 +1,33 @@
package mineplex.core.valentines;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import org.bukkit.plugin.java.JavaPlugin;
public class ValentinesGiftRepository extends RepositoryBase
{
private String GIVE_GIFT = "INSERT INTO accountValentinesGift (senderId, targetId) VALUES (?, ?);";
public ValentinesGiftRepository(JavaPlugin plugin)
{
super(plugin, DBPool.getAccount());
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
public boolean giveGift(int senderId, int targetId)
{
return executeUpdate(GIVE_GIFT, new ColumnInt("senderId", senderId), new ColumnInt("targetId", targetId)) == 1;
}
}

View File

@ -0,0 +1,31 @@
package mineplex.core.valentines.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class AttemptGiftEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() { return handlers; }
public HandlerList getHandlers() { return handlers; }
private Player _from;
private Player _to;
public AttemptGiftEvent(Player from, Player to)
{
_from = from;
_to = to;
}
public Player getFrom()
{
return _from;
}
public Player getTo()
{
return _to;
}
}

View File

@ -8,6 +8,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
import mineplex.core.reward.RewardManager;
import mineplex.core.valentines.ValentinesGiftManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -253,6 +255,12 @@ public class HubManager extends MiniClientPlugin<HubClient>
new PlayerDisguiseManager(plugin, _clientManager);
// NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager);
// new MailManager(_plugin, notificationManager);
new ValentinesGiftManager(plugin, clientManager, new RewardManager(clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, statsManager, giveawayManager,
100, 250,
500, 1000,
4000, 6000,
12000, 22000,
true, false), inventoryManager, _gadgetManager);
_playerCountManager = new PlayerCountManager(plugin);