+ Added shop/way to earn tokens.

This commit is contained in:
Steffion 2013-08-28 19:28:08 +02:00
parent 98962a1f2b
commit bcef0a336f
8 changed files with 205 additions and 11 deletions

View File

@ -34,6 +34,9 @@ public class Arena implements ConfigurationSerializable {
public List<String> seekersWinCommands;
public List<String> hidersWinCommands;
public List<String> allowedCommands;
public int seekersTokenWin;
public int hidersTokenWin;
public int killTokens;
public List<Player> playersInArena;
public ArenaState gameState;
@ -49,6 +52,7 @@ public class Arena implements ConfigurationSerializable {
LocationSerializable lobbyWarp, LocationSerializable hidersWarp,
LocationSerializable seekersWarp, List<String> seekersWinCommands,
List<String> hidersWinCommands, List<String> allowedCommands,
int seekersTokenWin, int hidersTokenWin, int killTokens,
List<Player> playersInArena, ArenaState gameState, int timer,
List<Player> seekers, Scoreboard scoreboard) {
this.arenaName = arenaName;
@ -68,6 +72,9 @@ public class Arena implements ConfigurationSerializable {
this.seekersWinCommands = seekersWinCommands;
this.hidersWinCommands = hidersWinCommands;
this.allowedCommands = allowedCommands;
this.seekersTokenWin = seekersTokenWin;
this.hidersTokenWin = hidersTokenWin;
this.killTokens = killTokens;
this.playersInArena = playersInArena;
this.gameState = gameState;
@ -83,7 +90,10 @@ public class Arena implements ConfigurationSerializable {
timeInLobbyUntilStart,
waitingTimeSeeker,
gameTime,
timeUntilHidersSword;
timeUntilHidersSword,
hidersTokenWin,
seekersTokenWin,
killTokens;
}
public enum ArenaState {
@ -110,6 +120,8 @@ public class Arena implements ConfigurationSerializable {
map.put("seekersWinCommands", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
map.put("allowedCommands", allowedCommands);
map.put("seekersTokenWin", seekersTokenWin);
map.put("hidersTokenWin", hidersTokenWin);
return map;
}
@ -136,8 +148,11 @@ public class Arena implements ConfigurationSerializable {
new ArrayList<String>()), (ArrayList<String>) M.g(map,
"hidersWinCommands", new ArrayList<String>()),
(ArrayList<String>) M.g(map, "allowedCommands",
new ArrayList<String>()), new ArrayList<Player>(),
ArenaState.WAITING, 0, new ArrayList<Player>(), Bukkit
.getScoreboardManager().getNewScoreboard());
new ArrayList<String>()), (Integer) M.g(map,
"seekersTokenWin", 10), (Integer) M.g(map,
"hidersTokenWin", 50), (Integer) M.g(map, "killTokens",
8), new ArrayList<Player>(), ArenaState.WAITING, 0,
new ArrayList<Player>(), Bukkit.getScoreboardManager()
.getNewScoreboard());
}
}

View File

@ -337,6 +337,19 @@ public class ArenaHandler {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
command.replaceAll("%player%", player.getName()));
}
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");
W.shop.getFile().set(player.getName() + ".tokens",
playerTokens + arena.seekersTokenWin);
W.shop.save();
MessageM.sendFMessage(player, ConfigC.normal_addedToken, true,
"amount-" + arena.seekersTokenWin);
}
}
@ -362,6 +375,19 @@ public class ArenaHandler {
Bukkit.getConsoleSender(),
command.replaceAll("%player%", player.getName()));
}
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");
W.shop.getFile().set(player.getName() + ".tokens",
playerTokens + arena.hidersTokenWin);
W.shop.save();
MessageM.sendFMessage(player, ConfigC.normal_addedToken,
true, "amount-" + arena.hidersTokenWin);
}
}
}

View File

@ -39,7 +39,7 @@ public class CMDcreate extends DefaultCMD {
new ArrayList<ItemStack>(), null, null,
null, new ArrayList<String>(),
new ArrayList<String>(),
new ArrayList<String>(),
new ArrayList<String>(), 10, 50, 8,
new ArrayList<Player>(),
ArenaState.WAITING, 0,
new ArrayList<Player>(), Bukkit
@ -49,7 +49,7 @@ public class CMDcreate extends DefaultCMD {
W.arenas.save();
W.signs.load();
W.arenaList.add((Arena) arena);
W.arenaList.add(arena);
ScoreboardHandler.createScoreboard(arena);
MessageM.sendFMessage(player,

View File

@ -21,6 +21,7 @@ public class CMDreload extends DefaultCMD {
W.messages.load();
W.arenas.load();
W.signs.load();
W.shop.load();
for (Arena arena : W.arenaList) {
ArenaHandler.stopArena(arena);
}

View File

@ -96,6 +96,24 @@ public class InventoryHandler {
ItemStack timeUntilHidersSword_DOWN = new ItemStack(
Material.GOLD_NUGGET, 1);
ItemStack hidersTokenWin_UP = new ItemStack(Material.GOLD_NUGGET, 1);
ItemStack hidersTokenWin = new ItemStack(
Material.PISTON_MOVING_PIECE, arena.hidersTokenWin);
ItemStack hidersTokenWin_DOWN = new ItemStack(Material.GOLD_NUGGET,
1);
ItemStack seekersTokenWin_UP = new ItemStack(Material.GOLD_NUGGET,
1);
ItemStack seekersTokenWin = new ItemStack(
Material.PISTON_MOVING_PIECE, arena.seekersTokenWin);
ItemStack seekersTokenWin_DOWN = new ItemStack(
Material.GOLD_NUGGET, 1);
ItemStack killTokens_UP = new ItemStack(Material.GOLD_NUGGET, 1);
ItemStack killTokens = new ItemStack(Material.PISTON_MOVING_PIECE,
arena.killTokens);
ItemStack killTokens_DOWN = new ItemStack(Material.GOLD_NUGGET, 1);
//
updownButton(panel, arena, ArenaType.maxPlayers, "maxPlayers", "1",
@ -126,6 +144,18 @@ public class InventoryHandler {
timeUntilHidersSword_UP, timeUntilHidersSword,
timeUntilHidersSword_DOWN, 30, 39, 48);
updownButton(panel, arena, ArenaType.hidersTokenWin,
"hidersTokenWin", "1 %Ntoken", hidersTokenWin_UP,
hidersTokenWin, hidersTokenWin_DOWN, 32, 41, 50);
updownButton(panel, arena, ArenaType.seekersTokenWin,
"seekersTokenWin", "1 %Ntoken", seekersTokenWin_UP,
seekersTokenWin, seekersTokenWin_DOWN, 33, 42, 51);
updownButton(panel, arena, ArenaType.killTokens, "killTokens",
"1 %Ntoken", killTokens_UP, killTokens, killTokens_DOWN,
34, 43, 52);
player.openInventory(panel);
} else {
MessageM.sendFMessage(player, ConfigC.error_noArena, true, "name-"
@ -165,6 +195,15 @@ public class InventoryHandler {
case timeUntilHidersSword:
setting = arena.timeUntilHidersSword;
break;
case hidersTokenWin:
setting = arena.hidersTokenWin;
break;
case seekersTokenWin:
setting = arena.seekersTokenWin;
break;
case killTokens:
setting = arena.killTokens;
break;
}
ItemMeta BUTTON_IM = BUTTON.getItemMeta();
@ -246,12 +285,38 @@ public class InventoryHandler {
shopBlockChooser_IM.setLore(lores2);
shopBlockChooser.setItemMeta(shopBlockChooser_IM);
ItemStack shopBlockHuntPass = new ItemStack(
Material.getMaterial((Integer) W.config
.get(ConfigC.shop_BlockHuntPassID)), 1);
ItemMeta shopBlockHuntPass_IM = shopBlockHuntPass.getItemMeta();
shopBlockHuntPass_IM.setDisplayName(MessageM
.replaceAll((String) W.config
.get(ConfigC.shop_BlockHuntPassName)));
lores = W.config.getFile().getStringList(
ConfigC.shop_BlockHuntPassDescription.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_BlockHuntPassPrice)));
shopBlockHuntPass_IM.setLore(lores2);
shopBlockHuntPass.setItemMeta(shopBlockHuntPass_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);
}
if ((Boolean) W.config.get(ConfigC.shop_BlockHuntPassEnabled) == true
&& (Boolean) W.shop.getFile().get(
player.getName() + ".blockhuntpass") == null) {
shop.setItem(2, shopBlockHuntPass);
}
player.openInventory(shop);
}
}

View File

@ -5,10 +5,10 @@ import nl.Steffion.BlockHunt.Arena.ArenaState;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,10 +20,14 @@ public class OnEntityDamageByEntityEvent implements Listener {
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
Entity ent = event.getEntity();
Player player = null;
if (ent instanceof Player) {
player = (Player) ent;
if (event.getEntity() instanceof Player) {
player = (Player) event.getEntity();
}
Player damager = null;
if (event.getDamager() instanceof Player) {
damager = (Player) event.getDamager();
}
if (player != null) {
@ -54,6 +58,44 @@ public class OnEntityDamageByEntityEvent implements Listener {
W.pBlock.remove(player);
if (!arena.seekers.contains(player)) {
if (W.shop.getFile().get(
damager.getName() + ".tokens") == null) {
W.shop.getFile().set(
damager.getName() + ".tokens",
0);
W.shop.save();
}
int damagerTokens = W.shop.getFile()
.getInt(damager.getName()
+ ".tokens");
W.shop.getFile().set(
damager.getName() + ".tokens",
damagerTokens + arena.killTokens);
W.shop.save();
MessageM.sendFMessage(damager,
ConfigC.normal_addedToken, true,
"amount-" + arena.killTokens);
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");
float addingTokens = ((float) arena.hidersTokenWin - (((float) arena.timer / (float) arena.gameTime) * (float) arena.hidersTokenWin));
W.shop.getFile().set(
player.getName() + ".tokens",
playerTokens + (int) addingTokens);
W.shop.save();
MessageM.sendFMessage(player,
ConfigC.normal_addedToken, true,
"amount-" + (int) addingTokens);
arena.seekers.add(player);
ArenaHandler
.sendFMessage(

View File

@ -159,6 +159,21 @@ public class OnInventoryClickEvent implements Listener {
updownButton(player, item, arena,
ArenaType.timeUntilHidersSword,
arena.timeUntilHidersSword, 1000, 0, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("hidersTokenWin")) {
updownButton(player, item, arena,
ArenaType.hidersTokenWin,
arena.hidersTokenWin, 1000, 0, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("seekersTokenWin")) {
updownButton(player, item, arena,
ArenaType.seekersTokenWin,
arena.seekersTokenWin, 1000, 0, 1, 1);
} else if (item.getItemMeta().getDisplayName()
.contains("killTokens")) {
updownButton(player, item, arena,
ArenaType.killTokens, arena.killTokens,
1000, 0, 1, 1);
}
save(arena);
@ -208,6 +223,15 @@ public class OnInventoryClickEvent implements Listener {
case timeUntilHidersSword:
arena.timeUntilHidersSword = option + add;
break;
case hidersTokenWin:
arena.hidersTokenWin = option + add;
break;
case seekersTokenWin:
arena.seekersTokenWin = option + add;
break;
case killTokens:
arena.killTokens = option + add;
break;
}
} else {
MessageM.sendFMessage(player, ConfigC.error_setTooHighNumber,
@ -238,6 +262,15 @@ public class OnInventoryClickEvent implements Listener {
case timeUntilHidersSword:
arena.timeUntilHidersSword = option - remove;
break;
case hidersTokenWin:
arena.hidersTokenWin = option - remove;
break;
case seekersTokenWin:
arena.seekersTokenWin = option - remove;
break;
case killTokens:
arena.killTokens = option - remove;
break;
}
} else {
MessageM.sendFMessage(player, ConfigC.error_setTooLowNumber,

View File

@ -43,7 +43,7 @@ public enum ConfigC {
shop_price ("%NPrice: %A%amount% %Ntokens.", W.config),
shop_blockChooserEnabled (true, W.config),
shop_blockChooserID (345, W.config),
shop_blockChooserID (340, W.config),
shop_blockChooserPrice (3000, W.config),
shop_blockChooserName ("%H&lBlock Chooser", W.config),
shop_blockChooserDescription (new String[] {
@ -51,6 +51,16 @@ public enum ConfigC {
"%ARight-Click%N in the lobby and choose",
"%Nthe block you want to be!", "&6Unlimited uses." }, W.config),
shop_BlockHuntPassEnabled (true, W.config),
shop_BlockHuntPassID (421, W.config),
shop_BlockHuntPassPrice (150, W.config),
shop_BlockHuntPassName ("%H&lBlockHunt Pass", W.config),
shop_BlockHuntPassDescription (new String[] {
"%NUse this item before the arena starts.",
"%ARight-Click%N in the lobby and choose",
"%Nif you want to be a Hider or a Seeker!", "&61 use.",
"&c&lCOMING SOON!" }, 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%",
@ -125,6 +135,8 @@ public enum ConfigC {
normal_winHiders ("%NThe %AHIDERS%N have won!", W.messages),
normal_setwarpWarpSet ("%NSet warp '%A%warp%%N' to your location!",
W.messages),
normal_addedToken ("%A%amount%%N tokens were added to your account!",
W.messages),
normal_removeRemovedArena ("%NRemoved arena '%A%name%%N'!", W.messages),
normal_ingameNowSolid ("%NYou're now a solid '%A%block%%N' block!",
W.messages),