Change boxes more
This commit is contained in:
parent
a268b0dfff
commit
8ee5faf4d9
@ -1,7 +1,5 @@
|
|||||||
package mineplex.game.clans.clans.boxes;
|
package mineplex.game.clans.clans.boxes;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
@ -17,26 +15,27 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.command.CommandBase;
|
import mineplex.core.command.CommandBase;
|
||||||
import mineplex.core.common.Pair;
|
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.C;
|
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.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.game.clans.clans.ClansManager;
|
import mineplex.game.clans.clans.boxes.extra.BuilderBoxVerifier;
|
||||||
import mineplex.game.clans.clans.boxes.extra.DyeBoxSpinner;
|
import mineplex.game.clans.clans.boxes.extra.DyeBoxSpinner;
|
||||||
|
|
||||||
public class BoxManager extends MiniPlugin
|
public class BoxManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
|
private BuilderBoxVerifier _builderVerifier;
|
||||||
|
|
||||||
public BoxManager(JavaPlugin plugin)
|
public BoxManager(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super("Box Manager", plugin);
|
super("Box Manager", plugin);
|
||||||
|
|
||||||
final BoxShop shop = new BoxShop(this);
|
final BoxShop shop = new BoxShop(this);
|
||||||
|
|
||||||
|
_builderVerifier = new BuilderBoxVerifier(this, shop);
|
||||||
|
|
||||||
addCommand(new CommandBase<BoxManager>(this, Rank.ALL, "boxes", "box")
|
addCommand(new CommandBase<BoxManager>(this, Rank.ALL, "boxes", "box")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -68,6 +67,12 @@ public class BoxManager extends MiniPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getInventory().getResult().getType() == Material.INK_SACK)
|
||||||
|
{
|
||||||
|
event.getInventory().setResult(null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (ItemStack item : event.getInventory().getMatrix())
|
for (ItemStack item : event.getInventory().getMatrix())
|
||||||
{
|
{
|
||||||
@ -75,6 +80,10 @@ public class BoxManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (item.getType() != Material.INK_SACK)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye"))
|
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye"))
|
||||||
{
|
{
|
||||||
event.getInventory().setResult(null);
|
event.getInventory().setResult(null);
|
||||||
@ -103,6 +112,12 @@ public class BoxManager extends MiniPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getInventory().getResult().getType() == Material.INK_SACK)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (ItemStack item : event.getInventory().getMatrix())
|
for (ItemStack item : event.getInventory().getMatrix())
|
||||||
{
|
{
|
||||||
@ -110,10 +125,13 @@ public class BoxManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (item.getType() != Material.INK_SACK)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye"))
|
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye"))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,31 +169,7 @@ public class BoxManager extends MiniPlugin
|
|||||||
|
|
||||||
public static enum BoxType
|
public static enum BoxType
|
||||||
{
|
{
|
||||||
@SuppressWarnings("deprecation")
|
BUILDER_BOX("Clans Builder Box", C.cGold + "Builder's Box", Material.GLOWSTONE, Managers.get(BoxManager.class)._builderVerifier::showVerifier),
|
||||||
BUILDER_BOX("Clans Builder Box", C.cGold + "Builder's Box", Material.GLOWSTONE, player ->
|
|
||||||
{
|
|
||||||
Map<Pair<Material, Byte>, ItemStack> replace = new HashMap<>();
|
|
||||||
replace.put(Pair.create(Material.STONE, (byte)0), new ItemStack(Material.STAINED_CLAY));
|
|
||||||
replace.put(Pair.create(Material.GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS));
|
|
||||||
replace.put(Pair.create(Material.THIN_GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS_PANE));
|
|
||||||
|
|
||||||
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
|
|
||||||
{
|
|
||||||
ItemStack item = player.getInventory().getItem(slot);
|
|
||||||
if (item == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ItemStack after = new ItemBuilder(replace.get(Pair.create(item.getType(), item.getData().getData()))).setData(DyeColor.values()[UtilMath.r(DyeColor.values().length)].getWoolData()).build();
|
|
||||||
if (after != null)
|
|
||||||
{
|
|
||||||
after.setAmount(item.getAmount());
|
|
||||||
player.getInventory().setItem(slot, after);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UtilPlayer.message(player, F.main("Builder's Box", "You have redeemed your box contents!"));
|
|
||||||
}),
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
DYE_BOX("Clans Dye Box", C.cGreen + "Dye Box", Material.INK_SACK, DyeColor.RED.getDyeData(), DyeBoxSpinner::createSpinner),
|
DYE_BOX("Clans Dye Box", C.cGreen + "Dye Box", Material.INK_SACK, DyeColor.RED.getDyeData(), DyeBoxSpinner::createSpinner),
|
||||||
;
|
;
|
||||||
@ -220,9 +214,8 @@ public class BoxManager extends MiniPlugin
|
|||||||
return newBuilder.addLore(C.cGreenB + "Owned: " + C.cWhite + owned).build();
|
return newBuilder.addLore(C.cGreenB + "Owned: " + C.cWhite + owned).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateRewards(Player player)
|
public void onUse(Player player)
|
||||||
{
|
{
|
||||||
ClansManager.getInstance().getInventoryManager().addItemToInventory(player, getItemName(), -1);
|
|
||||||
_itemGenerator.accept(player);
|
_itemGenerator.accept(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class BoxOverviewPage extends ShopPageBase<BoxManager, BoxShop>
|
|||||||
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1f, 1f);
|
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1f, 1f);
|
||||||
if (Recharge.Instance.use(player, "Clans Box Click", 1000, false, false))
|
if (Recharge.Instance.use(player, "Clans Box Click", 1000, false, false))
|
||||||
{
|
{
|
||||||
type.generateRewards(player);
|
type.onUse(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
package mineplex.game.clans.clans.boxes.extra;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import mineplex.core.Managers;
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.Pair;
|
||||||
|
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.donation.DonationManager;
|
||||||
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
|
import mineplex.core.shop.confirmation.ConfirmationCallback;
|
||||||
|
import mineplex.core.shop.confirmation.ConfirmationPage;
|
||||||
|
import mineplex.core.shop.confirmation.ConfirmationProcessor;
|
||||||
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
import mineplex.game.clans.clans.boxes.BoxManager;
|
||||||
|
import mineplex.game.clans.clans.boxes.BoxManager.BoxType;
|
||||||
|
import mineplex.game.clans.clans.boxes.BoxShop;
|
||||||
|
|
||||||
|
public class BuilderBoxVerifier
|
||||||
|
{
|
||||||
|
private BoxManager _manager;
|
||||||
|
private BoxShop _shop;
|
||||||
|
|
||||||
|
public BuilderBoxVerifier(BoxManager manager, BoxShop shop)
|
||||||
|
{
|
||||||
|
_manager = manager;
|
||||||
|
_shop = shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showVerifier(Player player)
|
||||||
|
{
|
||||||
|
_shop.openPageForPlayer(player, new ConfirmationPage<BoxManager, BoxShop>(player, _manager, _shop, Managers.get(CoreClientManager.class), Managers.get(DonationManager.class), new ConfirmationProcessor()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void init(Inventory inventory) {}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public void process(ConfirmationCallback callback)
|
||||||
|
{
|
||||||
|
ClansManager.getInstance().getInventoryManager().addItemToInventory(player, BoxType.BUILDER_BOX.getItemName(), -1);
|
||||||
|
|
||||||
|
Map<Pair<Material, Byte>, ItemStack> replace = new HashMap<>();
|
||||||
|
replace.put(Pair.create(Material.STONE, (byte)0), new ItemStack(Material.STAINED_CLAY));
|
||||||
|
replace.put(Pair.create(Material.GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS));
|
||||||
|
replace.put(Pair.create(Material.THIN_GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS_PANE));
|
||||||
|
replace.put(Pair.create(Material.WOOL, (byte)0), new ItemStack(Material.WOOL));
|
||||||
|
replace.put(Pair.create(Material.CARPET, (byte)0), new ItemStack(Material.CARPET));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)0), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)1), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)2), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)3), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)4), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)5), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)6), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)7), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.RED_ROSE, (byte)8), new ItemStack(Material.RED_ROSE));
|
||||||
|
replace.put(Pair.create(Material.COBBLE_WALL, (byte)0), new ItemStack(Material.COBBLE_WALL));
|
||||||
|
|
||||||
|
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
|
||||||
|
{
|
||||||
|
ItemStack item = player.getInventory().getItem(slot);
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Pair<Material, Byte> pair = Pair.create(item.getType(), item.getData().getData());
|
||||||
|
if (!replace.containsKey(pair))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ItemBuilder after = new ItemBuilder(replace.get(pair));
|
||||||
|
if (after.getType() == Material.RED_ROSE)
|
||||||
|
{
|
||||||
|
after.setData((short)UtilMath.r(9));
|
||||||
|
}
|
||||||
|
else if (after.getType() == Material.COBBLE_WALL)
|
||||||
|
{
|
||||||
|
after.setData((short)1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
after.setData(UtilMath.randomElement(DyeColor.values()).getWoolData());
|
||||||
|
}
|
||||||
|
after.setAmount(item.getAmount());
|
||||||
|
player.getInventory().setItem(slot, after.build());
|
||||||
|
}
|
||||||
|
callback.resolve("You have redeemed your box!");
|
||||||
|
|
||||||
|
UtilPlayer.message(player, F.main("Builder's Box", "You have redeemed your box!"));
|
||||||
|
}
|
||||||
|
}, new ItemBuilder(Material.BARRIER).setTitle(C.cDRedB + "WARNING").setLore(C.cRedB + "ALL " + C.cRed + "compatible items", C.cRed + "in your inventory", C.cRed + "will be converted!").build()));
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,8 @@ import mineplex.core.common.util.UtilServer;
|
|||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
import mineplex.game.clans.clans.boxes.BoxManager.BoxType;
|
||||||
|
|
||||||
public class DyeBoxSpinner implements Listener
|
public class DyeBoxSpinner implements Listener
|
||||||
{
|
{
|
||||||
@ -82,11 +84,11 @@ public class DyeBoxSpinner implements Listener
|
|||||||
DyeColor color = null;
|
DyeColor color = null;
|
||||||
if (Math.random() <= 0.05)
|
if (Math.random() <= 0.05)
|
||||||
{
|
{
|
||||||
color = rareColors.get(UtilMath.r(rareColors.size()));
|
color = UtilMath.randomElement(rareColors);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
color = commonColors.get(UtilMath.r(commonColors.size()));
|
color = UtilMath.randomElement(commonColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
_items.add(new ItemBuilder(Material.INK_SACK).setData(color.getDyeData()).setTitle(C.cGold + "Dye").build());
|
_items.add(new ItemBuilder(Material.INK_SACK).setData(color.getDyeData()).setTitle(C.cGold + "Dye").build());
|
||||||
@ -164,6 +166,7 @@ public class DyeBoxSpinner implements Listener
|
|||||||
|
|
||||||
public static void createSpinner(Player player)
|
public static void createSpinner(Player player)
|
||||||
{
|
{
|
||||||
|
ClansManager.getInstance().getInventoryManager().addItemToInventory(player, BoxType.DYE_BOX.getItemName(), -1);
|
||||||
new DyeBoxSpinner(player);
|
new DyeBoxSpinner(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user