Tweak dye boxes

This commit is contained in:
AlexTheCoder 2017-05-08 23:21:19 -04:00
parent b1b12babf0
commit 9fcf718e65
4 changed files with 198 additions and 38 deletions

View File

@ -1,11 +1,8 @@
package mineplex.game.clans.clans.boxes;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@ -16,6 +13,7 @@ import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@ -29,6 +27,7 @@ import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.boxes.extra.DyeBoxSpinner;
public class BoxManager extends MiniPlugin
{
@ -137,6 +136,19 @@ public class BoxManager extends MiniPlugin
event.setCancelled(true);
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (event.getItem() == null || !event.getItem().hasItemMeta() || !event.getItem().getItemMeta().hasDisplayName())
{
return;
}
if (event.getItem().getItemMeta().getDisplayName().equals(C.cGold + "Dye"))
{
event.setCancelled(true);
}
}
public static enum BoxType
{
@SuppressWarnings("deprecation")
@ -165,26 +177,7 @@ public class BoxManager extends MiniPlugin
UtilPlayer.message(player, F.main("Builder's Box", "You have redeemed your box contents!"));
}),
@SuppressWarnings("deprecation")
DYE_BOX("Clans Dye Box", C.cGreen + "Dye Box", Material.INK_SACK, DyeColor.RED.getDyeData(), player ->
{
List<DyeColor> commonColors = Arrays.asList(DyeColor.values()).stream().filter(c -> c != DyeColor.BLACK && c != DyeColor.WHITE).collect(Collectors.toList());
List<DyeColor> rareColors = Arrays.asList(DyeColor.WHITE, DyeColor.BLACK);
for (int i = 0; i < 6; i++)
{
DyeColor color = null;
if (Math.random() <= 0.40)
{
color = rareColors.get(UtilMath.r(rareColors.size()));
}
else
{
color = commonColors.get(UtilMath.r(commonColors.size()));
}
player.getInventory().addItem(new ItemBuilder(Material.INK_SACK).setData(color.getDyeData()).setTitle(C.cGold + "Dye").build());
}
UtilPlayer.message(player, F.main("Dye Box", "You have redeemed your box contents!"));
}),
DYE_BOX("Clans Dye Box", C.cGreen + "Dye Box", Material.INK_SACK, DyeColor.RED.getDyeData(), DyeBoxSpinner::createSpinner),
;
private String _itemName, _displayName;

View File

@ -3,6 +3,7 @@ package mineplex.game.clans.clans.boxes;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.recharge.Recharge;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
@ -36,7 +37,10 @@ public class BoxOverviewPage extends ShopPageBase<BoxManager, BoxShop>
{
player.closeInventory();
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1f, 1f);
type.generateRewards(player);
if (Recharge.Instance.use(player, "Clans Box Click", 1000, false, false))
{
type.generateRewards(player);
}
}
};
addButton(slot, type.getDisplayItem(owns), button);

View File

@ -0,0 +1,169 @@
package mineplex.game.clans.clans.boxes.extra;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class DyeBoxSpinner implements Listener
{
private Player _player;
private Inventory _inv;
private int _step;
private List<ItemStack> _items;
private boolean _givenRewards = false;
private DyeBoxSpinner(Player player)
{
_player = player;
_inv = Bukkit.createInventory(player, 27, "Dye Box");
_step = 0;
_items = new ArrayList<>();
buildGUI();
generateRewards();
player.openInventory(_inv);
Bukkit.getPluginManager().registerEvents(this, UtilServer.getPlugin());
}
/**
* Upper and lower bounds are inclusive
*/
private int getRandom(int max, int min)
{
return UtilMath.r(max - min + 1) + min;
}
@SuppressWarnings("deprecation")
private void buildGUI()
{
ItemStack border = new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short)DyeColor.GRAY.getWoolData()).setTitle(C.cRed + " ").build();
ItemStack fill = new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short)DyeColor.BLACK.getWoolData()).setTitle(C.cRed + " ").build();
for (int i = 0; i < 27; i++)
{
if (i < 9 || i > 17)
{
_inv.setItem(i, border);
}
else
{
_inv.setItem(i, fill);
}
}
}
@SuppressWarnings("deprecation")
private void generateRewards()
{
List<DyeColor> commonColors = Arrays.asList(DyeColor.values()).stream().filter(c -> c != DyeColor.BLACK && c != DyeColor.WHITE).collect(Collectors.toList());
List<DyeColor> rareColors = Arrays.asList(DyeColor.WHITE, DyeColor.BLACK);
for (int i = 1; i <= getRandom(9, 5); i++)
{
DyeColor color = null;
if (Math.random() <= 0.05)
{
color = rareColors.get(UtilMath.r(rareColors.size()));
}
else
{
color = commonColors.get(UtilMath.r(commonColors.size()));
}
_items.add(new ItemBuilder(Material.INK_SACK).setData(color.getDyeData()).setTitle(C.cGold + "Dye").build());
}
}
private void giveRewards()
{
if (_givenRewards)
{
return;
}
_givenRewards = true;
_player.closeInventory();
_items.forEach(_player.getInventory()::addItem);
UtilPlayer.message(_player, F.main("Dye Box", "You have redeemed your box contents!"));
}
@SuppressWarnings("deprecation")
private void progress()
{
if (_step == 0)
{
_step++;
return;
}
if (_step < 10)
{
int slot = 18 - _step;
if (Math.max(18, slot) - Math.min(18, slot) <= _items.size())
{
_inv.setItem(slot, new ItemBuilder(Material.STAINED_GLASS_PANE).setData((short)DyeColor.LIME.getWoolData()).setTitle(C.cRed + " ").build());
}
_step++;
return;
}
if (_step == 10)
{
int slot = 17;
for (int i = 0; i < _items.size(); i++)
{
_inv.setItem(slot, _items.get(i));
slot--;
}
_step++;
return;
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() == UpdateType.FASTEST)
{
if (_player.getOpenInventory() == null || _player.getOpenInventory().getTopInventory() == null || !_player.getOpenInventory().getTopInventory().getName().equals("Dye Box"))
{
HandlerList.unregisterAll(this);
giveRewards();
}
}
if (event.getType() == UpdateType.SEC)
{
progress();
}
}
@EventHandler
public void onClick(InventoryClickEvent event)
{
if (event.getWhoClicked().getEntityId() == _player.getEntityId())
{
event.setCancelled(true);
}
}
public static void createSpinner(Player player)
{
new DyeBoxSpinner(player);
}
}

View File

@ -1,20 +1,6 @@
package mineplex.game.clans.clans.map;
import java.awt.Color;
import java.util.List;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.tutorial.TutorialManager;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.TutorialType;
import mineplex.game.clans.tutorial.map.TutorialMapManager;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.minecraft.game.core.boss.EventState;
import mineplex.minecraft.game.core.boss.WorldEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -26,6 +12,14 @@ import org.bukkit.map.MapPalette;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import mineplex.core.common.util.UtilTime;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.api.EventState;
import mineplex.game.clans.clans.worldevent.api.WorldEvent;
import mineplex.game.clans.tutorial.TutorialManager;
public class ItemMapRenderer extends MapRenderer
{
private ItemMapManager _manager;