Closes gh-242. If you remove your blockhead/helmet, it gets reset, but you can't carry more than one. Incremented preview number.

This commit is contained in:
taoneill 2011-09-09 23:33:28 -04:00
parent cb9a34f5bd
commit 25e034965d
5 changed files with 53 additions and 16 deletions

View File

@ -79,6 +79,7 @@ public class War extends JavaPlugin {
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
private TeamSpawnStyle defaultSpawnStyle = TeamSpawnStyle.BIG;
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
private int helmetProtectionTask;
public War() {
super();
@ -144,7 +145,8 @@ public class War extends JavaPlugin {
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
WarMapper.load();
this.getServer().getScheduler().scheduleAsyncDelayedTask(this, new HelmetProtectionTask());
HelmetProtectionTask helmetProtectionTask = new HelmetProtectionTask();
this.helmetProtectionTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, helmetProtectionTask, 250, 100);
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
}
@ -161,6 +163,8 @@ public class War extends JavaPlugin {
this.warHub.getVolume().resetBlocks();
}
this.getServer().getScheduler().cancelTasks(this);
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
this.setLoaded(false);
}

View File

@ -67,14 +67,13 @@ public class WarPlayerListener extends PlayerListener {
// a flag thief can't drop his flag
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
event.setCancelled(true);
} else {
Item item = event.getItemDrop();
if (item != null) {
ItemStack itemStack = item.getItemStack();
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
// Can't drop your team's kind block
War.war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
War.war.badMsg(player, "Can't drop " + team.getName() + " blocks.");
event.setCancelled(true);
return;
}

View File

@ -1,5 +1,6 @@
package com.tommytony.war.jobs;
import java.util.HashMap;
import java.util.logging.Level;
import org.bukkit.Material;
@ -14,7 +15,8 @@ import com.tommytony.war.Warzone;
import bukkit.tommytony.war.War;
/**
* Sets the helmet again onto the players heads
* Sets the helmet again onto the players heads.
* Also limits the number of blocks being held.
*
* @author Tim Düsterhus
*/
@ -24,31 +26,63 @@ public class HelmetProtectionTask implements Runnable {
* @see Runnable.run()
*/
public void run() {
while (true) {
if (War.war.isLoaded()) {
for (Warzone zone : War.war.getWarzones()) {
for (Team team : zone.getTeams()) {
for (Player player : team.getPlayers()) {
PlayerInventory playerInv = player.getInventory();
Material teamBlockMaterial;
if (zone.isBlockHeads()) {
playerInv.setHelmet(new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData())));
teamBlockMaterial = team.getKind().getMaterial();
// 1) Replace missing block head
if (playerInv.getHelmet().getType() != teamBlockMaterial) {
playerInv.setHelmet(createBlockHead(team));
}
// 2) Get rid of extra blocks in inventory: only keep one
HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
int i = 0;
int removed = 0;
for (ItemStack item : playerInv.getContents()) {
// remove only same colored wool
if (item != null && item.getType() == teamBlockMaterial && item.getData().getData() == team.getKind().getData()) {
playerInv.clear(i);
removed++;
}
i++;
}
playerInv.setItem(playerInv.firstEmpty(), createBlockHead(team));
if (removed > 1) {
War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!");
}
}
} else {
if (team.getKind() == TeamKind.GOLD) {
playerInv.setHelmet(new ItemStack(Material.GOLD_HELMET));
teamBlockMaterial = Material.GOLD_HELMET;
} else if (team.getKind() == TeamKind.DIAMOND) {
playerInv.setHelmet(new ItemStack(Material.DIAMOND_HELMET));
teamBlockMaterial = Material.DIAMOND_HELMET;
} else if (team.getKind() == TeamKind.IRON) {
playerInv.setHelmet(new ItemStack(Material.IRON_HELMET));
teamBlockMaterial = Material.IRON_HELMET;
} else {
playerInv.setHelmet(new ItemStack(Material.LEATHER_HELMET));
teamBlockMaterial = Material.LEATHER_HELMET;
}
if (playerInv.getHelmet() != null && playerInv.getHelmet().getType() != teamBlockMaterial) {
playerInv.setHelmet(new ItemStack(teamBlockMaterial));
}
HashMap<Integer, ? extends ItemStack> helmets = playerInv.all(teamBlockMaterial);
if (helmets.size() > 1 || (helmets.size() == 1 && helmets.get(helmets.keySet().iterator().next()).getAmount() > 1)) {
playerInv.remove(teamBlockMaterial);
playerInv.setItem(playerInv.firstEmpty(), new ItemStack(teamBlockMaterial));
War.war.badMsg(player, "All those helmets must have been heavy!");
}
}
}
}
}
try {
Thread.sleep((War.war.isLoaded()) ? 500 : 10000);
} catch (InterruptedException e) {
}
}
}
private ItemStack createBlockHead(Team team) {
return new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData()));
}
}

View File

@ -1,5 +1,5 @@
name: War
version: 1.6 (de Gaulle) PREVIEW 5
version: 1.6 (de Gaulle) PREVIEW 6
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com

View File

@ -1,5 +1,5 @@
name: War
version: 1.6 (de Gaulle) PREVIEW 5
version: 1.6 (de Gaulle) PREVIEW 6
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com