+ Added shop!

This commit is contained in:
Steffion 2013-08-28 16:36:50 +02:00
parent 003ff21020
commit df63f0af72
10 changed files with 301 additions and 140 deletions

View File

@ -1,5 +1,8 @@
package nl.Steffion.BlockHunt;
import java.util.ArrayList;
import java.util.List;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.Managers.ConfigC;
@ -16,6 +19,7 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@SuppressWarnings("deprecation")
public class ArenaHandler {
@ -90,41 +94,6 @@ public class ArenaHandler {
}
arena.playersInArena.add(player);
// OLD WAY OF SETTING A PLAYER'S DATA.
// W.pLocation.put(player,
// player.getLocation());
// W.pGameMode.put(player,
// player.getGameMode());
//
// player.teleport(arena.lobbyWarp);
// player.setGameMode(GameMode.SURVIVAL);
//
// W.pInventory.put(player, player
// .getInventory().getContents());
// player.getInventory().clear();
// player.updateInventory();
// W.pArmor.put(player,
// player.getInventory()
// .getArmorContents());
// player.getInventory().setHelmet(
// new ItemStack(Material.AIR));
// player.getInventory().setChestplate(
// new ItemStack(Material.AIR));
// player.getInventory().setLeggings(
// new ItemStack(Material.AIR));
// player.getInventory().setBoots(
// new ItemStack(Material.AIR));
// W.pEXP.put(player, player.getExp());
// player.setExp(0);
// W.pEXPL.put(player, player.getLevel());
// player.setLevel(0);
// W.pHealth.put(player,
// player.getHealth());
// player.setHealth(20);
// W.pFood.put(player,
// player.getFoodLevel());
// player.setFoodLevel(20);
PlayerArenaData pad = new PlayerArenaData(
player.getLocation(),
player.getGameMode(), player
@ -155,6 +124,40 @@ public class ArenaHandler {
new ItemStack(Material.AIR));
player.getInventory().setBoots(
new ItemStack(Material.AIR));
if ((Boolean) W.config
.get(ConfigC.shop_blockChooserEnabled) == true) {
if (W.shop.getFile().get(
player.getName()
+ ".blockchooser") != null) {
ItemStack shopBlockChooser = new ItemStack(
Material.getMaterial((Integer) W.config
.get(ConfigC.shop_blockChooserID)),
1);
ItemMeta shopBlockChooser_IM = shopBlockChooser
.getItemMeta();
shopBlockChooser_IM
.setDisplayName(MessageM
.replaceAll((String) W.config
.get(ConfigC.shop_blockChooserName)));
List<String> lores = W.config
.getFile()
.getStringList(
ConfigC.shop_blockChooserDescription
.getLocation());
List<String> lores2 = new ArrayList<String>();
for (String lore : lores) {
lores2.add(MessageM
.replaceAll(lore));
}
shopBlockChooser_IM.setLore(lores2);
shopBlockChooser
.setItemMeta(shopBlockChooser_IM);
player.getInventory().addItem(
shopBlockChooser);
}
}
player.updateInventory();
if (W.dcAPI.isDisguised(player)) {
@ -265,29 +268,6 @@ public class ArenaHandler {
}
}
// OLD WAY OF RESETTING A PLAYER'S DATA.
// player.getInventory().clear();
// player.getInventory().setContents(W.pInventory.get(player));
// player.updateInventory();
// W.pInventory.remove(player);
// player.getInventory().setArmorContents(W.pArmor.get(player));
// W.pArmor.remove(player);
// player.setExp(W.pEXP.get(player));
// W.pEXP.remove(player);
// player.setLevel(W.pEXPL.get(player));
// W.pEXPL.remove(player);
// player.setHealth(W.pHealth.get(player));
// W.pHealth.remove(player);
// player.setFoodLevel(W.pFood.get(player));
// W.pFood.remove(player);
// W.pBlock.remove(player);
//
// player.teleport(W.pLocation.get(player));
//
// player.setGameMode(W.pGameMode.get(player));
// W.pGameMode.remove(player);
// W.pLocation.remove(player);
PlayerArenaData pad = new PlayerArenaData(null, null, null, null,
null, null, null, null, null);

View File

@ -232,9 +232,17 @@ public class BlockHunt extends JavaPlugin implements Listener {
for (Player arenaPlayer : arena.playersInArena) {
if (!arena.seekers.contains(arenaPlayer)) {
arenaPlayer.getInventory().clear();
arenaPlayer.updateInventory();
ItemStack block = arena.disguiseBlocks.get(W.random
.nextInt(arena.disguiseBlocks
.size()));
if (W.choosenBlock.get(arenaPlayer) != null) {
block = W.choosenBlock.get(arenaPlayer);
W.choosenBlock.remove(arenaPlayer);
}
LinkedList<String> data = new LinkedList<String>();
data.add("blockID:" + block.getTypeId());
data.add("blockData:"

View File

@ -0,0 +1,20 @@
package nl.Steffion.BlockHunt.Commands;
import nl.Steffion.BlockHunt.InventoryHandler;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
public class CMDshop extends DefaultCMD {
@Override
public boolean exectue(Player player, Command cmd, String label,
String[] args) {
if (PlayerM.hasPerm(player, PermsC.shop, true)) {
InventoryHandler.openShop(player);
}
return true;
}
}

View File

@ -1,6 +1,7 @@
package nl.Steffion.BlockHunt;
import java.util.ArrayList;
import java.util.List;
import nl.Steffion.BlockHunt.Arena.ArenaType;
import nl.Steffion.BlockHunt.Managers.ConfigC;
@ -205,4 +206,52 @@ public class InventoryHandler {
}
player.openInventory(panel);
}
public static void openShop(Player player) {
Inventory shop = Bukkit.createInventory(null, 9,
MessageM.replaceAll("\u00A7r%H&lBlockHunt %NShop"));
if (W.shop.getFile().get(player.getName() + ".tokens") == null) {
W.shop.getFile().set(player.getName() + ".tokens", 0);
W.shop.save();
}
int playerTokens = W.shop.getFile()
.getInt(player.getName() + ".tokens");
List<String> lores = new ArrayList<String>();
List<String> lores2 = new ArrayList<String>();
ItemStack shopTokens = new ItemStack(Material.EMERALD, 1);
ItemMeta shopTokens_IM = shopTokens.getItemMeta();
shopTokens_IM.setDisplayName(MessageM.replaceAll("%N&lTokens: %A"
+ playerTokens));
shopTokens.setItemMeta(shopTokens_IM);
ItemStack shopBlockChooser = new ItemStack(
Material.getMaterial((Integer) W.config
.get(ConfigC.shop_blockChooserID)), 1);
ItemMeta shopBlockChooser_IM = shopBlockChooser.getItemMeta();
shopBlockChooser_IM.setDisplayName(MessageM
.replaceAll((String) W.config
.get(ConfigC.shop_blockChooserName)));
lores = W.config.getFile().getStringList(
ConfigC.shop_blockChooserDescription.getLocation());
lores2 = new ArrayList<String>();
for (String lore : lores) {
lores2.add(MessageM.replaceAll(lore));
}
lores2.add(MessageM.replaceAll(
(String) W.config.get(ConfigC.shop_price),
"amount-" + W.config.get(ConfigC.shop_blockChooserPrice)));
shopBlockChooser_IM.setLore(lores2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
shop.setItem(0, shopTokens);
if ((Boolean) W.config.get(ConfigC.shop_blockChooserEnabled) == true
&& (Boolean) W.shop.getFile().get(
player.getName() + ".blockchooser") == null) {
shop.setItem(1, shopBlockChooser);
}
player.openInventory(shop);
}
}

View File

@ -27,7 +27,9 @@ public class OnInventoryClickEvent implements Listener {
for (Arena arena : W.arenaList) {
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
if (event.getSlot() == 8) {
event.setCancelled(true);
}
}
}
@ -44,74 +46,127 @@ public class OnInventoryClickEvent implements Listener {
return;
} else if (inv.getName().startsWith("\u00A7r")) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
String arenaname = inv
.getItem(0)
.getItemMeta()
.getDisplayName()
.replaceAll(
MessageM.replaceAll("%NSettings of arena: %A"),
"");
Arena arena = null;
for (Arena arena2 : W.arenaList) {
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
arena = arena2;
if (inv.getName().contains("Shop")) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
if (W.shop.getFile().get(player.getName() + ".tokens") == null) {
W.shop.getFile().set(player.getName() + ".tokens", 0);
W.shop.save();
}
}
if (item == null)
return;
if (item.getType().equals(Material.AIR))
return;
if (!item.getItemMeta().hasDisplayName())
return;
if (item.getType().equals(Material.GOLD_NUGGET)) {
if (item.getItemMeta().getDisplayName()
.contains("maxPlayers")) {
updownButton(player, item, arena, ArenaType.maxPlayers,
arena.maxPlayers, Bukkit.getMaxPlayers(), 2, 1,
1);
} else if (item.getItemMeta().getDisplayName()
.contains("minPlayers")) {
updownButton(player, item, arena, ArenaType.minPlayers,
arena.minPlayers, Bukkit.getMaxPlayers() - 1,
2, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("amountSeekersOnStart")) {
updownButton(player, item, arena,
ArenaType.amountSeekersOnStart,
arena.amountSeekersOnStart,
arena.maxPlayers - 1, 1, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("timeInLobbyUntilStart")) {
updownButton(player, item, arena,
ArenaType.timeInLobbyUntilStart,
arena.timeInLobbyUntilStart, 1000, 5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("waitingTimeSeeker")) {
updownButton(player, item, arena,
ArenaType.waitingTimeSeeker,
arena.waitingTimeSeeker, 1000, 5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("gameTime")) {
updownButton(player, item, arena, ArenaType.gameTime,
arena.gameTime, 1000, 5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("timeUntilHidersSword")) {
updownButton(player, item, arena,
ArenaType.timeUntilHidersSword,
arena.timeUntilHidersSword, 1000, 0, 1, 1);
int playerTokens = W.shop.getFile().getInt(
player.getName() + ".tokens");
if (item.getType().equals(Material.AIR))
return;
if (item.getItemMeta()
.getDisplayName()
.equals(MessageM.replaceAll(W.config.get(
ConfigC.shop_blockChooserName).toString()))) {
if (playerTokens >= (Integer) W.config
.get(ConfigC.shop_blockChooserPrice)) {
W.shop.getFile().set(
player.getName() + ".blockchooser", true);
W.shop.getFile()
.set(player.getName() + ".tokens",
playerTokens
- (Integer) W.config
.get(ConfigC.shop_blockChooserPrice));
W.shop.save();
MessageM.sendFMessage(
player,
ConfigC.normal_ShopBoughtItem,
true,
"itemname-"
+ W.config
.get(ConfigC.shop_blockChooserName));
} else {
MessageM.sendFMessage(player,
ConfigC.error_ShopNeedMoreTokens, true);
}
}
save(arena);
InventoryHandler.openPanel(player, arena.arenaName);
InventoryHandler.openShop(player);
} else if (inv.getName().contains(
MessageM.replaceAll((String) W.config
.get(ConfigC.shop_blockChooserName)))) {
event.setCancelled(true);
W.choosenBlock.put(player, event.getCurrentItem());
MessageM.sendFMessage(player,
ConfigC.normal_ShopChoosenBlock, true, "block-"
+ event.getCurrentItem().getType()
.toString().replaceAll("_", "")
.replaceAll("BLOCK", "")
.toLowerCase());
} else {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
String arenaname = inv
.getItem(0)
.getItemMeta()
.getDisplayName()
.replaceAll(
MessageM.replaceAll("%NSettings of arena: %A"),
"");
} else if (item.getType().equals(Material.BOOK)) {
if (item.getItemMeta().getDisplayName()
.contains("disguiseBlocks")) {
InventoryHandler.openDisguiseBlocks(arena, player);
Arena arena = null;
for (Arena arena2 : W.arenaList) {
if (arena2.arenaName.equalsIgnoreCase(arenaname)) {
arena = arena2;
}
}
if (item == null)
return;
if (item.getType().equals(Material.AIR))
return;
if (!item.getItemMeta().hasDisplayName())
return;
if (item.getType().equals(Material.GOLD_NUGGET)) {
if (item.getItemMeta().getDisplayName()
.contains("maxPlayers")) {
updownButton(player, item, arena,
ArenaType.maxPlayers, arena.maxPlayers,
Bukkit.getMaxPlayers(), 2, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("minPlayers")) {
updownButton(player, item, arena,
ArenaType.minPlayers, arena.minPlayers,
Bukkit.getMaxPlayers() - 1, 2, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("amountSeekersOnStart")) {
updownButton(player, item, arena,
ArenaType.amountSeekersOnStart,
arena.amountSeekersOnStart,
arena.maxPlayers - 1, 1, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("timeInLobbyUntilStart")) {
updownButton(player, item, arena,
ArenaType.timeInLobbyUntilStart,
arena.timeInLobbyUntilStart, 1000, 5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("waitingTimeSeeker")) {
updownButton(player, item, arena,
ArenaType.waitingTimeSeeker,
arena.waitingTimeSeeker, 1000, 5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("gameTime")) {
updownButton(player, item, arena,
ArenaType.gameTime, arena.gameTime, 1000,
5, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("timeUntilHidersSword")) {
updownButton(player, item, arena,
ArenaType.timeUntilHidersSword,
arena.timeUntilHidersSword, 1000, 0, 1, 1);
}
save(arena);
InventoryHandler.openPanel(player, arena.arenaName);
} else if (item.getType().equals(Material.BOOK)) {
if (item.getItemMeta().getDisplayName()
.contains("disguiseBlocks")) {
InventoryHandler.openDisguiseBlocks(arena, player);
}
}
}
}

View File

@ -1,6 +1,7 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.SignsHandler;
import nl.Steffion.BlockHunt.SolidBlockHandler;
@ -11,6 +12,7 @@ import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -22,6 +24,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -149,5 +152,38 @@ public class OnPlayerInteractEvent implements Listener {
}
}
}
for (Arena arena : W.arenaList) {
if (arena.playersInArena.contains(player)
&& (arena.gameState.equals(ArenaState.WAITING) || arena.gameState
.equals(ArenaState.STARTING))) {
event.setCancelled(true);
ItemStack item = player.getInventory().getItemInHand();
if (item.getType() != Material.AIR) {
if (item.getItemMeta().getDisplayName() != null) {
if (item.getItemMeta()
.getDisplayName()
.equals(MessageM.replaceAll((String) W.config
.get(ConfigC.shop_blockChooserName)))) {
Inventory blockChooser = Bukkit
.createInventory(
null,
36,
MessageM.replaceAll("\u00A7r"
+ W.config
.get(ConfigC.shop_blockChooserName)));
if (arena.disguiseBlocks != null) {
for (int i = arena.disguiseBlocks.size(); i > 0; i = i - 1) {
blockChooser.setItem(i - 1,
arena.disguiseBlocks.get(i - 1));
}
}
player.openInventory(blockChooser);
}
}
}
}
}
}
}

View File

@ -66,6 +66,14 @@ public enum CommandC {
ConfigC.help_list,
1,
W.pluginName + " <list|li>"),
SHOP ("BlockHunt%shop_",
"BlockHunt%sh_",
new CMDshop(),
ConfigC.commandEnabled_shop,
PermsC.shop,
ConfigC.help_shop,
1,
W.pluginName + " <shop|sh>"),
START ("BlockHunt%start_",
"BlockHunt%go_",
new CMDstart(),

View File

@ -21,6 +21,7 @@ public enum ConfigC {
commandEnabled_join (true, W.config),
commandEnabled_leave (true, W.config),
commandEnabled_list (true, W.config),
commandEnabled_shop (true, W.config),
commandEnabled_start (true, W.config),
commandEnabled_wand (true, W.config),
commandEnabled_create (true, W.config),
@ -40,6 +41,16 @@ public enum ConfigC {
"%NUse the create command to define your arena.",
"%A/" + W.pluginName + " <help|h>" }, W.config),
shop_price ("%NPrice: %A%amount% %Ntokens.", W.config),
shop_blockChooserEnabled (true, W.config),
shop_blockChooserID (345, W.config),
shop_blockChooserPrice (3000, W.config),
shop_blockChooserName ("%H&lBlock Chooser", W.config),
shop_blockChooserDescription (new String[] {
"%NUse this item before the arena starts.",
"%ARight-Click%N in the lobby and choose",
"%Nthe block you want to be!", "&6Unlimited uses." }, W.config),
sign_LEAVE (new String[] { "%H[" + W.pluginName + "%H]", "&4LEAVE",
"&8Right-Click", "&8To leave." }, W.config),
sign_WAITING (new String[] { "%H[" + W.pluginName + "%H]", "%A%arenaname%",
@ -66,6 +77,7 @@ public enum ConfigC {
help_join ("%NJoins a " + W.pluginName + " game.", W.messages),
help_leave ("%NLeave a " + W.pluginName + " game.", W.messages),
help_list ("%NShows a list of available arenas.", W.messages),
help_shop ("%NOpens the " + W.pluginName + " shop.", W.messages),
help_start ("%NForces an arena to start.", W.messages),
help_wand ("%NGives you the wand selection tool.", W.messages),
help_create ("%NCreates an arena from your selection.", W.messages),
@ -117,6 +129,10 @@ public enum ConfigC {
normal_ingameNowSolid ("%NYou're now a solid '%A%block%%N' block!",
W.messages),
normal_ingameNoMoreSolid ("%NYou're no longer a solid block!", W.messages),
normal_ShopBoughtItem ("%NYou've bought the '%A%itemname%%N' item!",
W.messages),
normal_ShopChoosenBlock ("%NYou've choosen to be a(n) '%A%block%%N' block!",
W.messages),
warning_lobbyNeedAtleast ("%WYou need atleast %A%1%%W player(s) to start the game!",
W.messages),
@ -159,7 +175,9 @@ public enum ConfigC {
error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.",
W.messages),
error_setNotABlock ("%EThat is not a block!", W.messages),
error_setwarpWarpNotFound ("%EWarp '%A%warp%%E' is not valid!", W.messages);
error_setwarpWarpNotFound ("%EWarp '%A%warp%%E' is not valid!", W.messages),
error_ShopNeedMoreTokens ("%EYou need more tokens before you can buy this item.",
W.messages);
public Object value;
public ConfigM config;

View File

@ -24,6 +24,7 @@ public class PlayerM {
joinsign (main + "joinsign", PType.PLAYER),
leave (main + "leave", PType.PLAYER),
list (main + "list", PType.PLAYER),
shop (main + "shop", PType.PLAYER),
start (main + "start", PType.MODERATOR),
create (main + "create", PType.ADMIN),
set (main + "set", PType.MODERATOR),

View File

@ -32,28 +32,14 @@ public class W {
public static ConfigM messages = new ConfigM("messages", "");
public static ConfigM arenas = new ConfigM("arenas", "");
public static ConfigM signs = new ConfigM("signs", "");
public static ConfigM shop = new ConfigM("shop", "");
public static ArrayList<Arena> arenaList = new ArrayList<Arena>();
public static Random random = new Random();
public static DisguiseCraftAPI dcAPI;
public static HashMap<Player, Integer> seekertime = new HashMap<Player, Integer>();
public static HashMap<Player, PlayerArenaData> pData = new HashMap<Player, PlayerArenaData>();
// public static HashMap<Player, Location> pLocation = new HashMap<Player,
// Location>();
// public static HashMap<Player, GameMode> pGameMode = new HashMap<Player,
// GameMode>();
// public static HashMap<Player, ItemStack[]> pInventory = new
// HashMap<Player, ItemStack[]>();
// public static HashMap<Player, ItemStack[]> pArmor = new HashMap<Player,
// ItemStack[]>();
// public static HashMap<Player, Float> pEXP = new HashMap<Player, Float>();
// public static HashMap<Player, Integer> pEXPL = new HashMap<Player,
// Integer>();
// public static HashMap<Player, Double> pHealth = new HashMap<Player,
// Double>();
// public static HashMap<Player, Integer> pFood = new HashMap<Player,
// Integer>();
public static HashMap<Player, ItemStack> choosenBlock = new HashMap<Player, ItemStack>();
public static HashMap<Player, ItemStack> pBlock = new HashMap<Player, ItemStack>();
public static HashMap<Player, Location> moveLoc = new HashMap<Player, Location>();