Prevent horses from spawning in Clans

Added Building supplies shop and pvp shop to clans.
This commit is contained in:
Jonathan Williams 2014-12-29 06:44:00 -05:00
parent a7f77c09fe
commit 97f57b655b
14 changed files with 269 additions and 30 deletions

View File

@ -74,16 +74,12 @@ public class InventoryUtil
else if (item == null)
continue;
boolean equals = false;
boolean equals = (item.getTypeId() == inventory[i].getTypeId() && item.getDurability() == inventory[i].getDurability() && item.getEnchantments().equals(inventory[i].getEnchantments()));
if (withAmount)
if (equals && withAmount)
{
equals = item.equals(inventory[i]);
equals = inventory[i].getAmount() >= item.getAmount();
}
else
{
equals = item.getTypeId() == inventory[i].getTypeId() && item.getDurability() == inventory[i].getDurability() && item.getEnchantments().equals(inventory[i].getEnchantments());
}
if (equals)
{
@ -94,7 +90,7 @@ public class InventoryUtil
return -1;
}
public static int GetCountOfObjectsRemoved(CraftInventory getInventory, int i, ItemStack itemStack)
public static int getCountOfObjectsRemoved(CraftInventory getInventory, int i, ItemStack itemStack)
{
int count = 0;

View File

@ -140,7 +140,7 @@ public class ItemPackage implements ISalesPackage
int count = 0;
count = InventoryUtil.GetCountOfObjectsRemoved((CraftInventory)player.GetPlayer().getInventory(), 9, (ItemStack)shopItem);
count = InventoryUtil.getCountOfObjectsRemoved((CraftInventory)player.GetPlayer().getInventory(), 9, (ItemStack)shopItem);
/* TODO default
for (int i=0; i < 9; i++)

View File

@ -24,6 +24,8 @@ import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.shop.building.BuildingShop;
import mineplex.game.clans.shop.pvp.PvpShop;
import mineplex.minecraft.game.core.mechanics.Weapon;
import net.minecraft.server.v1_7_R4.MinecraftServer;
@ -59,7 +61,7 @@ public class Clans extends JavaPlugin
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
_donationManager = new DonationManager(this, webServerAddress);
_donationManager = new DonationManager(this, _clientManager, webServerAddress);
_serverConfiguration = new ServerConfiguration(this);
@ -84,9 +86,11 @@ public class Clans extends JavaPlugin
new FriendManager(this, _clientManager, preferenceManager);
new InventoryManager(this, _clientManager);
new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, webServerAddress);
ClansManager clans = new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, webServerAddress);
new Recipes(this);
new Farming(this);
new BuildingShop(clans, _clientManager, _donationManager);
new PvpShop(clans, _clientManager, _donationManager);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -37,6 +38,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -75,6 +77,13 @@ public class ClansGame extends MiniPlugin
}
}
@EventHandler
public void preventHorseSpawn(CreatureSpawnEvent event)
{
if (event.getEntityType() == EntityType.HORSE)
event.setCancelled(true);
}
@EventHandler
public void deductEnergy(UpdateEvent event)
{

View File

@ -7,19 +7,58 @@ import mineplex.core.shop.item.ShopItem;
public class PvpItem extends ShopItem
{
private static String LEFT_CLICK_BUY = C.cWhite + "Left-Click to Buy 1";
private static String LEFT_CLICK_BUY = C.cYellow + "Left-Click" + C.cWhite + " to Buy " + C.cGreen + 1;
private static String RIGHT_CLICK_SELL = C.cYellow + "Right-Click" + C.cWhite + " to Sell " + C.cGreen + 1;
private int _price;
private int _bulkCount;
public PvpItem(Material type, byte data, int displayAmount, String name, int price, int bulkCount)
{
super(type, data, name, new String[]
{
C.cYellow + C.Bold + name,
C.cWhite + " ",
LEFT_CLICK_BUY,
C.cWhite + "Costs " + C.cGreen + "$" + price,
C.cWhite + " ",
C.cWhite + "Shift Left-Click to Buy " + bulkCount,
C.cYellow + "Shift Left-Click" + C.cWhite + " to Buy " + C.cGreen + bulkCount,
C.cWhite + "Costs " + C.cGreen + "$" + (price * bulkCount),
C.cWhite + " ",
RIGHT_CLICK_SELL,
C.cWhite + "Earns " + C.cGreen + "$" + (int)(price / 2),
C.cWhite + " ",
C.cYellow + "Shift Right-Click" + C.cWhite + " to Sell " + C.cGreen + "All",
}, 0, false, false);
_price = price;
_bulkCount = bulkCount;
}
public PvpItem(Material type, byte data, int displayAmount, String name, int price)
{
super(type, data, name, new String[]
{
C.cWhite + " ",
LEFT_CLICK_BUY,
C.cWhite + "Costs " + C.cGreen + "$" + price,
C.cWhite + " ",
RIGHT_CLICK_SELL,
C.cWhite + "Earns " + C.cGreen + "$" + (int)(price / 2),
C.cWhite + " ",
C.cYellow + "Shift Right-Click" + C.cWhite + " to Sell " + C.cGreen + "All",
}, 0, false, false);
_price = price;
_bulkCount = -1;
}
public int getPrice()
{
return _price;
}
public int getBulkCount()
{
return _bulkCount;
}
}

View File

@ -1,13 +1,21 @@
package mineplex.game.clans.shop;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.InventoryUtil;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
public class PvpShopButton<PageType extends ShopPageBase<ClansManager, BuildingShop>> implements IButton
public class PvpShopButton<PageType extends ShopPageBase<ClansManager, ?>> implements IButton
{
protected PageType Page;
protected PvpItem Item;
@ -19,14 +27,89 @@ public class PvpShopButton<PageType extends ShopPageBase<ClansManager, BuildingS
}
@Override
public void onClick(Player player, ClickType clickType)
public void onClick(final Player player, ClickType clickType)
{
if (clickType == ClickType.LEFT)
int balance = Page.getDonationManager().Get(player.getName()).getGold();
int cost = Item.getPrice();
int tempAmount = Item.getAmount();
if (clickType == ClickType.SHIFT_LEFT)
{
int balance = Page.getDonationManager().Get(player.getName()).getGold();
cost *= Item.getBulkCount() == -1 ? 1 : Item.getBulkCount();
tempAmount = Item.getBulkCount() == -1 ? Item.getAmount() : Item.getBulkCount();
}
final int deliveryAmount = tempAmount;
if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT)
{
if (cost > balance)
{
Page.PlayDenySound(player);
UtilPlayer.message(player, F.main(Page.getPlugin().getName(), "You do not have enough funds to purchase " + deliveryAmount + " " + Item.GetName() + "."));
return;
}
else
{
Page.getDonationManager().RewardGold(new Callback<Boolean>()
{
public void run(Boolean result)
{
if (result)
{
Page.PlayAcceptSound(player);
ShopItem item = Item.clone();
item.setAmount(deliveryAmount);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Item.getType(), Item.getData().getData(), Item.getAmount(), Item.GetName()));
}
else
{
Page.PlayDenySound(player);
UtilPlayer.message(player, F.main(Page.getPlugin().getName(), "An error occurred processing your purchase."));
}
}
}, "Clans", player.getName(), player.getUniqueId(), -cost);
}
}
else if (clickType == ClickType.RIGHT || clickType == ClickType.SHIFT_RIGHT)
{
int removed = 1;
ItemStack dumbItem = new ItemStack(Item.getType(), Item.getAmount(), Item.getDurability());
if (InventoryUtil.first((CraftInventory)player.getInventory(), 36, dumbItem, true) == -1)
{
Page.PlayDenySound(player);
UtilPlayer.message(player, F.main(Page.getPlugin().getName(), "You do not have " + deliveryAmount + " " + Item.GetName() + " in your inventory."));
return;
}
if (clickType == ClickType.RIGHT)
{
if (player.getInventory().contains(Item.getType(), Item.getAmount()))
InventoryUtil.removeItem((CraftInventory)player.getInventory(), 36, dumbItem);
}
else
removed = InventoryUtil.getCountOfObjectsRemoved((CraftInventory)player.getInventory(), 36, dumbItem);
final int creditAmount = removed * Item.getPrice() / 2;
System.out.println("Crediting " + player.getName() + " with " + creditAmount + " gold.");
Page.getDonationManager().RewardGold(new Callback<Boolean>()
{
public void run(Boolean result)
{
if (result)
{
Page.PlayAcceptSound(player);
System.out.println("Credited " + player.getName() + " with " + creditAmount + " gold.");
}
else
{
Page.PlayDenySound(player);
UtilPlayer.message(player, F.main(Page.getPlugin().getName(), "An error occurred processing your return."));
}
}
}, "Clans", player.getName(), player.getUniqueId(), creditAmount);
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.shop;
package mineplex.game.clans.shop.building;
import org.bukkit.Material;
@ -6,25 +6,29 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.shop.PvpItem;
import mineplex.game.clans.shop.PvpShopButton;
public class BuildingPage extends ShopPageBase<ClansManager, BuildingShop>
{
public BuildingPage(ClansManager plugin, BuildingShop shop, CoreClientManager clientManager, DonationManager donationManager, org.bukkit.entity.Player player)
{
super(plugin, shop, clientManager, donationManager, "Building Supplies", player);
BuildPage();
}
@Override
protected void BuildPage()
{
addPvpItem(1, new PvpItem(Material.STONE, (byte)0, 1, "Stone", 25, 64));
addPvpItem(1, new PvpItem(Material.WOOD, (byte)0, 1, "Wood", 15, 64));
addPvpItem(1, new PvpItem(Material.BRICK, (byte)0, 1, "Bricks", 30, 64));
addPvpItem(1, new PvpItem(Material.SANDSTONE, (byte)0, 1, "Sandstone", 30, 64));
addPvpItem(2, new PvpItem(Material.WOOD, (byte)0, 1, "Wood", 15, 64));
addPvpItem(3, new PvpItem(Material.BRICK, (byte)0, 1, "Bricks", 30, 64));
addPvpItem(4, new PvpItem(Material.SANDSTONE, (byte)0, 1, "Sandstone", 30, 64));
}
public void addPvpItem(int slot, PvpItem item)
{
AddButton(1, item, new PvpShopButton<BuildingPage>(this, item));
AddButton(slot, item, new PvpShopButton<BuildingPage>(this, item));
}
}

View File

@ -1,8 +1,11 @@
package mineplex.game.clans.shop;
package mineplex.game.clans.shop.building;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
@ -19,4 +22,14 @@ public class BuildingShop extends ShopBase<ClansManager>
{
return new BuildingPage(Plugin, this, ClientManager, DonationManager, player);
}
@EventHandler
public void playerCmd(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/gold"))
{
UtilPlayer.message(event.getPlayer(), "PVP SHOP > Gold balance : " + DonationManager.Get(event.getPlayer().getName()).getGold());
event.setCancelled(true);
}
}
}

View File

@ -0,0 +1,69 @@
package mineplex.game.clans.shop.pvp;
import org.bukkit.Material;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.shop.PvpItem;
import mineplex.game.clans.shop.PvpShopButton;
public class PvpPage extends ShopPageBase<ClansManager, PvpShop>
{
public PvpPage(ClansManager plugin, PvpShop shop, CoreClientManager clientManager, DonationManager donationManager, org.bukkit.entity.Player player)
{
super(plugin, shop, clientManager, donationManager, "Pvp Gear", player);
BuildPage();
}
@Override
protected void BuildPage()
{
addPvpItem(9, new PvpItem(Material.GOLD_HELMET, (byte)0, 1, "Mage Helmet", 200, 4));
addPvpItem(18, new PvpItem(Material.GOLD_CHESTPLATE, (byte)0, 1, "Mage Chestplate", 200, 4));
addPvpItem(27, new PvpItem(Material.GOLD_LEGGINGS, (byte)0, 1, "Mage Leggings", 200, 4));
addPvpItem(36, new PvpItem(Material.GOLD_BOOTS, (byte)0, 1, "Mage Boots", 200, 4));
addPvpItem(10, new PvpItem(Material.LEATHER_HELMET, (byte)0, 1, "Assassin Helmet", 200, 4));
addPvpItem(19, new PvpItem(Material.LEATHER_CHESTPLATE, (byte)0, 1, "Assassin Chestplate", 200, 4));
addPvpItem(28, new PvpItem(Material.LEATHER_LEGGINGS, (byte)0, 1, "Assassin Leggings", 200, 4));
addPvpItem(37, new PvpItem(Material.LEATHER_BOOTS, (byte)0, 1, "Assassin Boots", 200, 4));
addPvpItem(11, new PvpItem(Material.CHAINMAIL_HELMET, (byte)0, 1, "Ranger Helmet", 200, 4));
addPvpItem(20, new PvpItem(Material.CHAINMAIL_CHESTPLATE, (byte)0, 1, "Ranger Chestplate", 200, 4));
addPvpItem(29, new PvpItem(Material.CHAINMAIL_LEGGINGS, (byte)0, 1, "Ranger Leggings", 200, 4));
addPvpItem(38, new PvpItem(Material.CHAINMAIL_BOOTS, (byte)0, 1, "Ranger Boots", 200, 4));
addPvpItem(12, new PvpItem(Material.IRON_HELMET, (byte)0, 1, "Knight Helmet", 200, 4));
addPvpItem(21, new PvpItem(Material.IRON_CHESTPLATE, (byte)0, 1, "Knight Chestplate", 200, 4));
addPvpItem(30, new PvpItem(Material.IRON_LEGGINGS, (byte)0, 1, "Knight Leggings", 200, 4));
addPvpItem(39, new PvpItem(Material.IRON_BOOTS, (byte)0, 1, "Knight Boots", 200, 4));
addPvpItem(13, new PvpItem(Material.DIAMOND_HELMET, (byte)0, 1, "Brute Helmet", 200, 4));
addPvpItem(22, new PvpItem(Material.DIAMOND_CHESTPLATE, (byte)0, 1, "Brute Chestplate", 200, 4));
addPvpItem(31, new PvpItem(Material.DIAMOND_LEGGINGS, (byte)0, 1, "Brute Leggings", 200, 4));
addPvpItem(40, new PvpItem(Material.DIAMOND_BOOTS, (byte)0, 1, "Brute Boots", 200, 4));
addPvpItem(15, new PvpItem(Material.IRON_SWORD, (byte)0, 1, "Iron Sword", 100, 4));
addPvpItem(16, new PvpItem(Material.DIAMOND_SWORD, (byte)0, 1, "Power Sword", 800, 4));
addPvpItem(17, new PvpItem(Material.GOLD_SWORD, (byte)0, 1, "Booster Sword", 800, 4));
addPvpItem(24, new PvpItem(Material.IRON_AXE, (byte)0, 1, "Iron Axe", 100, 4));
addPvpItem(25, new PvpItem(Material.DIAMOND_AXE, (byte)0, 1, "Power Axe", 800, 4));
addPvpItem(26, new PvpItem(Material.GOLD_AXE, (byte)0, 1, "Booster Axe", 800, 4));
addPvpItem(33, new PvpItem(Material.BOW, (byte)0, 1, "Standard Bow", 100, 4));
addPvpItem(34, new PvpItem(Material.ARROW, (byte)0, 16, "Arrows", 50, 4));
addPvpItem(51, new PvpItem(Material.TNT, (byte)0, 1, "TNT", 500, 16));
addPvpItem(52, new PvpItem(Material.BREWING_STAND_ITEM, (byte)0, 1, "TNT Generator", 5000));
addPvpItem(53, new PvpItem(Material.ENCHANTMENT_TABLE, (byte)0, 1, "Class Shop", 10000));
}
public void addPvpItem(int slot, PvpItem item)
{
AddButton(slot, item, new PvpShopButton<PvpPage>(this, item));
}
}

View File

@ -0,0 +1,22 @@
package mineplex.game.clans.shop.pvp;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ClansManager;
public class PvpShop extends ShopBase<ClansManager>
{
public PvpShop(ClansManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager)
{
super(plugin, clientManager, donationManager, "Pvp Gear");
}
@Override
protected ShopPageBase<ClansManager, ? extends ShopBase<ClansManager>> BuildPagesFor(Player player)
{
return new PvpPage(Plugin, this, ClientManager, DonationManager, player);
}
}

View File

@ -81,7 +81,7 @@ public class Hub extends JavaPlugin implements IRelation
Recharge.Initialize(this);
Punish punish = new Punish(this, webServerAddress, clientManager);
BlockRestore blockRestore = new BlockRestore(this);
DonationManager donationManager = new DonationManager(this, webServerAddress);
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
new ServerConfiguration(this);

View File

@ -48,7 +48,7 @@ public class StaffServer extends JavaPlugin
CommandCenter.Instance.setClientManager(clientManager);
Recharge.Initialize(this);
DonationManager donationManager = new DonationManager(this, webServerAddress);
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
new Punish(this, webServerAddress, clientManager);
new NpcManager(this, new Creature(this));

View File

@ -82,7 +82,7 @@ public class Arcade extends JavaPlugin
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
_donationManager = new DonationManager(this, webServerAddress);
_donationManager = new DonationManager(this, _clientManager, webServerAddress);
_serverConfiguration = new ServerConfiguration(this);

Binary file not shown.