mirror of
https://github.com/taoneill/war.git
synced 2024-11-14 06:17:01 +01:00
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:
parent
cb9a34f5bd
commit
25e034965d
@ -79,6 +79,7 @@ public class War extends JavaPlugin {
|
|||||||
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
|
private boolean defaultResetOnEmpty = false, defaultResetOnLoad = false, defaultResetOnUnload = false;
|
||||||
private TeamSpawnStyle defaultSpawnStyle = TeamSpawnStyle.BIG;
|
private TeamSpawnStyle defaultSpawnStyle = TeamSpawnStyle.BIG;
|
||||||
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
|
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
|
||||||
|
private int helmetProtectionTask;
|
||||||
|
|
||||||
public War() {
|
public War() {
|
||||||
super();
|
super();
|
||||||
@ -144,7 +145,8 @@ public class War extends JavaPlugin {
|
|||||||
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
|
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
|
||||||
|
|
||||||
WarMapper.load();
|
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);
|
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.warHub.getVolume().resetBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getServer().getScheduler().cancelTasks(this);
|
||||||
|
|
||||||
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO);
|
||||||
this.setLoaded(false);
|
this.setLoaded(false);
|
||||||
}
|
}
|
||||||
|
@ -67,14 +67,13 @@ public class WarPlayerListener extends PlayerListener {
|
|||||||
// a flag thief can't drop his flag
|
// a flag thief can't drop his flag
|
||||||
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
|
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Item item = event.getItemDrop();
|
Item item = event.getItemDrop();
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
ItemStack itemStack = item.getItemStack();
|
ItemStack itemStack = item.getItemStack();
|
||||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
|
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
|
||||||
// Can't drop your team's kind block
|
// 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);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.tommytony.war.jobs;
|
package com.tommytony.war.jobs;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -14,7 +15,8 @@ import com.tommytony.war.Warzone;
|
|||||||
import bukkit.tommytony.war.War;
|
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
|
* @author Tim Düsterhus
|
||||||
*/
|
*/
|
||||||
@ -24,31 +26,63 @@ public class HelmetProtectionTask implements Runnable {
|
|||||||
* @see Runnable.run()
|
* @see Runnable.run()
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
if (War.war.isLoaded()) {
|
||||||
for (Warzone zone : War.war.getWarzones()) {
|
for (Warzone zone : War.war.getWarzones()) {
|
||||||
for (Team team : zone.getTeams()) {
|
for (Team team : zone.getTeams()) {
|
||||||
for (Player player : team.getPlayers()) {
|
for (Player player : team.getPlayers()) {
|
||||||
PlayerInventory playerInv = player.getInventory();
|
PlayerInventory playerInv = player.getInventory();
|
||||||
|
Material teamBlockMaterial;
|
||||||
if (zone.isBlockHeads()) {
|
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 {
|
} else {
|
||||||
if (team.getKind() == TeamKind.GOLD) {
|
if (team.getKind() == TeamKind.GOLD) {
|
||||||
playerInv.setHelmet(new ItemStack(Material.GOLD_HELMET));
|
teamBlockMaterial = Material.GOLD_HELMET;
|
||||||
} else if (team.getKind() == TeamKind.DIAMOND) {
|
} else if (team.getKind() == TeamKind.DIAMOND) {
|
||||||
playerInv.setHelmet(new ItemStack(Material.DIAMOND_HELMET));
|
teamBlockMaterial = Material.DIAMOND_HELMET;
|
||||||
} else if (team.getKind() == TeamKind.IRON) {
|
} else if (team.getKind() == TeamKind.IRON) {
|
||||||
playerInv.setHelmet(new ItemStack(Material.IRON_HELMET));
|
teamBlockMaterial = Material.IRON_HELMET;
|
||||||
} else {
|
} 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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: War
|
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.
|
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
|
||||||
author: tommytony
|
author: tommytony
|
||||||
website: war.tommytony.com
|
website: war.tommytony.com
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: War
|
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.
|
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
|
||||||
author: tommytony
|
author: tommytony
|
||||||
website: war.tommytony.com
|
website: war.tommytony.com
|
||||||
|
Loading…
Reference in New Issue
Block a user