mirror of
https://github.com/taoneill/war.git
synced 2024-11-24 03:05:54 +01:00
Closes gh-260. Added tntinzonesonly setting. Re-made explosion protection to let everything blow up except important stuff. Warhub, lobbies, spawns, flags and zone walls are protected. Stuff that is near the warzone wall but outside gets rolled back (because the explosion was inside the warzone, those outside blocks really explode, but get rolled back with a new fancy DeferredBlockResetJob which handles chests et al. on top of signs). If tntinzonesonly is on, tnt explosions outside warzones are cancelled (this makes sure any projected tnt block doesn't cause damage). Only bad thing here is that tntinzonesonly is server-wide, not world specific. Also, explosion handling is much more heavy.
This commit is contained in:
parent
0811431b0a
commit
00c6397df4
@ -63,6 +63,7 @@ public class War extends JavaPlugin {
|
|||||||
private boolean pvpInZonesOnly = false;
|
private boolean pvpInZonesOnly = false;
|
||||||
private boolean disablePvpMessage = false;
|
private boolean disablePvpMessage = false;
|
||||||
private boolean buildInZonesOnly = false;
|
private boolean buildInZonesOnly = false;
|
||||||
|
private boolean tntInZonesOnly = false;
|
||||||
private final List<String> deadlyAdjectives = new ArrayList<String>();
|
private final List<String> deadlyAdjectives = new ArrayList<String>();
|
||||||
private final List<String> killerVerbs = new ArrayList<String>();
|
private final List<String> killerVerbs = new ArrayList<String>();
|
||||||
|
|
||||||
@ -458,6 +459,11 @@ public class War extends JavaPlugin {
|
|||||||
this.setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
this.setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
||||||
returnMessage.append(" buildinzonesonly set to " + String.valueOf(war.isBuildInZonesOnly()) + ".");
|
returnMessage.append(" buildinzonesonly set to " + String.valueOf(war.isBuildInZonesOnly()) + ".");
|
||||||
}
|
}
|
||||||
|
if (namedParams.containsKey("tntinzonesonly")) {
|
||||||
|
String onOff = namedParams.get("tntinzonesonly");
|
||||||
|
this.setTntInZonesOnly(onOff.equals("on") || onOff.equals("true"));
|
||||||
|
returnMessage.append(" tntinzonesonly set to " + String.valueOf(war.isTntInZonesOnly()) + ".");
|
||||||
|
}
|
||||||
|
|
||||||
if (namedParams.containsKey("lifepool")) {
|
if (namedParams.containsKey("lifepool")) {
|
||||||
this.setDefaultLifepool(Integer.parseInt(namedParams.get("lifepool")));
|
this.setDefaultLifepool(Integer.parseInt(namedParams.get("lifepool")));
|
||||||
@ -643,6 +649,7 @@ public class War extends JavaPlugin {
|
|||||||
+ " pvpinzonesonly:" + String.valueOf(this.isPvpInZonesOnly())
|
+ " pvpinzonesonly:" + String.valueOf(this.isPvpInZonesOnly())
|
||||||
+ " disablepvpmessage:" + String.valueOf(this.isDisablePvpMessage())
|
+ " disablepvpmessage:" + String.valueOf(this.isDisablePvpMessage())
|
||||||
+ " buildinzonesonly:" + String.valueOf(this.isBuildInZonesOnly())
|
+ " buildinzonesonly:" + String.valueOf(this.isBuildInZonesOnly())
|
||||||
|
+ " tntinzonesonly:" + String.valueOf(this.isTntInZonesOnly())
|
||||||
+ " - Warzone defaults -"
|
+ " - Warzone defaults -"
|
||||||
+ " lifepool:" + this.getDefaultLifepool()
|
+ " lifepool:" + this.getDefaultLifepool()
|
||||||
+ " teamsize:" + this.getDefaultTeamCap()
|
+ " teamsize:" + this.getDefaultTeamCap()
|
||||||
@ -1174,4 +1181,12 @@ public class War extends JavaPlugin {
|
|||||||
public List<String> getKillerVerbs() {
|
public List<String> getKillerVerbs() {
|
||||||
return killerVerbs;
|
return killerVerbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTntInZonesOnly() {
|
||||||
|
return tntInZonesOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTntInZonesOnly(boolean tntInZonesOnly) {
|
||||||
|
this.tntInZonesOnly = tntInZonesOnly;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package bukkit.tommytony.war;
|
package bukkit.tommytony.war;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -8,12 +9,17 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.ContainerBlock;
|
||||||
|
import org.bukkit.block.NoteBlock;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftCreeper;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.entity.CraftTNTPrimed;
|
import org.bukkit.craftbukkit.entity.CraftTNTPrimed;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.event.entity.EntityCombustEvent;
|
import org.bukkit.event.entity.EntityCombustEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
@ -22,9 +28,12 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
|||||||
import org.bukkit.event.entity.EntityListener;
|
import org.bukkit.event.entity.EntityListener;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
|
import com.tommytony.war.jobs.DeferredBlockResetsJob;
|
||||||
|
import com.tommytony.war.utils.DeferredBlockReset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles Entity-Events
|
* Handles Entity-Events
|
||||||
@ -34,7 +43,7 @@ import com.tommytony.war.Warzone;
|
|||||||
*/
|
*/
|
||||||
public class WarEntityListener extends EntityListener {
|
public class WarEntityListener extends EntityListener {
|
||||||
|
|
||||||
private Random killSeed = new Random();
|
private final Random killSeed = new Random();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles PVP-Damage
|
* Handles PVP-Damage
|
||||||
@ -157,11 +166,8 @@ public class WarEntityListener extends EntityListener {
|
|||||||
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
|
||||||
String deathMessage = "";
|
String deathMessage = "";
|
||||||
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName();
|
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName();
|
||||||
/* if (event.getDamager() instanceof Projectile && ((Projectile)event.getDamager()).getShooter() instanceof Player){
|
|
||||||
Player shooter = ((Player)((Projectile)event.getDamager()).getShooter());
|
if (event.getDamager() instanceof CraftTNTPrimed) {
|
||||||
Team shooterTeam = Team.getTeamByPlayerName(shooter.getName());
|
|
||||||
deathMessage = shooterTeam.getKind().getColor() + shooter.getDisplayName() + ChatColor.WHITE + "'s deadly aim killed " + defenderString;
|
|
||||||
} else */ if (event.getDamager() instanceof CraftTNTPrimed) {
|
|
||||||
deathMessage = defenderString + ChatColor.WHITE + " exploded";
|
deathMessage = defenderString + ChatColor.WHITE + " exploded";
|
||||||
} else {
|
} else {
|
||||||
deathMessage = defenderString + ChatColor.WHITE + " died";
|
deathMessage = defenderString + ChatColor.WHITE + " died";
|
||||||
@ -187,25 +193,101 @@ public class WarEntityListener extends EntityListener {
|
|||||||
}
|
}
|
||||||
// protect zones elements, lobbies and warhub from creepers
|
// protect zones elements, lobbies and warhub from creepers
|
||||||
List<Block> explodedBlocks = event.blockList();
|
List<Block> explodedBlocks = event.blockList();
|
||||||
|
List<Block> dontExplode = new ArrayList<Block>();
|
||||||
|
|
||||||
|
boolean explosionInAWarzone = Warzone.getZoneByLocation(event.getEntity().getLocation()) != null;
|
||||||
|
|
||||||
|
if (!explosionInAWarzone && War.war.isTntInZonesOnly() && event.getEntity() instanceof TNTPrimed) {
|
||||||
|
// if tntinzonesonly:true, no tnt blows up outside zones
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (Block block : explodedBlocks) {
|
for (Block block : explodedBlocks) {
|
||||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||||
event.setCancelled(true);
|
dontExplode.add(block);
|
||||||
War.war.log("Explosion prevented at warhub.", Level.INFO);
|
} else {
|
||||||
return;
|
boolean inOneZone = false;
|
||||||
}
|
for (Warzone zone : War.war.getWarzones()) {
|
||||||
|
if (zone.isImportantBlock(block)) {
|
||||||
|
dontExplode.add(block);
|
||||||
|
inOneZone = true;
|
||||||
|
break;
|
||||||
|
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
||||||
|
dontExplode.add(block);
|
||||||
|
inOneZone = true;
|
||||||
|
break;
|
||||||
|
} else if (zone.getVolume().contains(block)) {
|
||||||
|
inOneZone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Warzone zone : War.war.getWarzones()) {
|
if (!inOneZone && explosionInAWarzone) {
|
||||||
if (zone.isImportantBlock(block)) {
|
// if the explosion originated in warzone, always rollback
|
||||||
event.setCancelled(true);
|
dontExplode.add(block);
|
||||||
War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
|
|
||||||
return;
|
|
||||||
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dontExplodeSize = dontExplode.size();
|
||||||
|
if (dontExplode.size() > 0) {
|
||||||
|
// Reset the exploded blocks that shouldn't have exploded (some of these are zone artifacts, if rollbackexplosion some may be outside-of-zone blocks
|
||||||
|
DeferredBlockResetsJob job = new DeferredBlockResetsJob(dontExplode.get(0).getWorld());
|
||||||
|
List<Block> doors = new ArrayList<Block>();
|
||||||
|
for (Block dont : dontExplode) {
|
||||||
|
DeferredBlockReset deferred = null;
|
||||||
|
if (dont.getState() instanceof Sign) {
|
||||||
|
String[] lines = ((Sign)dont.getState()).getLines();
|
||||||
|
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), lines);
|
||||||
|
} else if (dont.getState() instanceof ContainerBlock) {
|
||||||
|
ItemStack[] contents = ((ContainerBlock)dont.getState()).getInventory().getContents();
|
||||||
|
Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation());
|
||||||
|
if (worldBlock.getState() instanceof ContainerBlock) {
|
||||||
|
((ContainerBlock)worldBlock.getState()).getInventory().clear();
|
||||||
|
}
|
||||||
|
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), copyItems(contents));
|
||||||
|
} else if (dont.getTypeId() == Material.NOTE_BLOCK.getId()) {
|
||||||
|
Block worldBlock = dont.getWorld().getBlockAt(dont.getLocation());
|
||||||
|
if (worldBlock.getState() instanceof NoteBlock) {
|
||||||
|
NoteBlock noteBlock = ((NoteBlock)worldBlock.getState());
|
||||||
|
if (noteBlock != null) {
|
||||||
|
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData(), noteBlock.getRawNote());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (dont.getTypeId() != Material.TNT.getId()) {
|
||||||
|
deferred = new DeferredBlockReset(dont.getX(), dont.getY(), dont.getZ(), dont.getTypeId(), dont.getData());
|
||||||
|
if (dont.getTypeId() == Material.WOODEN_DOOR.getId() || dont.getTypeId() == Material.IRON_DOOR_BLOCK.getId()) {
|
||||||
|
doors.add(dont);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deferred != null) {
|
||||||
|
job.add(deferred);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||||
|
|
||||||
|
// Changed explosion yeild following proportion of explosion prevention (makes drops less buggy too)
|
||||||
|
int explodedSize = explodedBlocks.size();
|
||||||
|
float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize;
|
||||||
|
float newYeild = middleYeild * event.getYield();
|
||||||
|
|
||||||
|
float old = event.getYield();
|
||||||
|
event.setYield(newYeild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> copyItems(ItemStack[] contents) {
|
||||||
|
List<ItemStack> list = new ArrayList<ItemStack>();
|
||||||
|
for (ItemStack stack : contents) {
|
||||||
|
if (stack != null) {
|
||||||
|
if (stack.getData() != null) {
|
||||||
|
list.add(new ItemStack(stack.getType(), stack.getAmount(), stack.getDurability(), stack.getData().getData()));
|
||||||
|
} else {
|
||||||
|
list.add(new ItemStack(stack.getType(), stack.getAmount(), stack.getDurability()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,7 @@ public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
|||||||
for (Player p : team.getPlayers()) {
|
for (Player p : team.getPlayers()) {
|
||||||
zone.restorePlayerState(p);
|
zone.restorePlayerState(p);
|
||||||
p.teleport(zone.getTeleport());
|
p.teleport(zone.getTeleport());
|
||||||
War.war.msg(p, "You have left the warzone. Your inventory has been restored.");
|
War.war.msg(p, "You have left the warzone. Your inventory is being restored.");
|
||||||
}
|
}
|
||||||
team.resetPoints();
|
team.resetPoints();
|
||||||
team.getPlayers().clear();
|
team.getPlayers().clear();
|
||||||
|
@ -903,7 +903,7 @@ public class Warzone {
|
|||||||
player.setFireTicks(0);
|
player.setFireTicks(0);
|
||||||
player.setRemainingAir(300);
|
player.setRemainingAir(300);
|
||||||
|
|
||||||
War.war.msg(player, "Left the zone. Your inventory has been restored.");
|
War.war.msg(player, "Left the zone. Your inventory is being restored.");
|
||||||
if (War.war.getWarHub() != null) {
|
if (War.war.getWarHub() != null) {
|
||||||
War.war.getWarHub().resetZoneSign(this);
|
War.war.getWarHub().resetZoneSign(this);
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,30 @@ package com.tommytony.war.jobs;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.block.ContainerBlock;
|
||||||
|
import org.bukkit.block.Dispenser;
|
||||||
|
import org.bukkit.block.Furnace;
|
||||||
|
import org.bukkit.block.NoteBlock;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import bukkit.tommytony.war.War;
|
||||||
|
|
||||||
|
import com.tommytony.war.mappers.ZoneVolumeMapper;
|
||||||
import com.tommytony.war.utils.DeferredBlockReset;
|
import com.tommytony.war.utils.DeferredBlockReset;
|
||||||
|
import com.tommytony.war.volumes.Volume;
|
||||||
|
|
||||||
public class DeferredBlockResetsJob implements Runnable {
|
public class DeferredBlockResetsJob implements Runnable {
|
||||||
|
|
||||||
@ -30,37 +46,130 @@ public class DeferredBlockResetsJob implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
for (DeferredBlockReset reset : this.deferred) {
|
ArrayList<DeferredBlockReset> doors = new ArrayList<DeferredBlockReset>();
|
||||||
Block worldBlock = this.world.getBlockAt(reset.getX(), reset.getY(), reset.getZ());
|
|
||||||
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
|
||||||
|
|
||||||
if (reset.getBlockType() == Material.SIGN_POST.getId()) {
|
for (DeferredBlockReset reset : this.deferred) {
|
||||||
BlockState state = worldBlock.getState();
|
if (this.world != null && reset != null) {
|
||||||
state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData()));
|
Block worldBlock = this.world.getBlockAt(reset.getX(), reset.getY(), reset.getZ());
|
||||||
if (state instanceof Sign) {
|
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||||
Sign sign = (Sign) state;
|
|
||||||
// String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
|
if (reset.getBlockType() == Material.WALL_SIGN.getId() || reset.getBlockType() == Material.SIGN_POST.getId()) {
|
||||||
if (reset.getLines() != null && sign.getLines() != null) {
|
BlockState state = worldBlock.getState();
|
||||||
if (reset.getLines().length > 0) {
|
state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData()));
|
||||||
sign.setLine(0, reset.getLines()[0]);
|
if (state instanceof Sign) {
|
||||||
|
Sign sign = (Sign) state;
|
||||||
|
if (reset.getLines() != null && sign.getLines() != null) {
|
||||||
|
if (reset.getLines().length > 0) {
|
||||||
|
sign.setLine(0, reset.getLines()[0]);
|
||||||
|
}
|
||||||
|
if (reset.getLines().length > 1) {
|
||||||
|
sign.setLine(1, reset.getLines()[1]);
|
||||||
|
}
|
||||||
|
if (reset.getLines().length > 2) {
|
||||||
|
sign.setLine(2, reset.getLines()[2]);
|
||||||
|
}
|
||||||
|
if (reset.getLines().length > 3) {
|
||||||
|
sign.setLine(3, reset.getLines()[3]);
|
||||||
|
}
|
||||||
|
sign.update(true);
|
||||||
}
|
}
|
||||||
if (reset.getLines().length > 1) {
|
}
|
||||||
sign.setLine(1, reset.getLines()[1]);
|
} else if (reset.getBlockType() == Material.CHEST.getId()
|
||||||
|
|| reset.getBlockType() == Material.DISPENSER.getId()
|
||||||
|
|| reset.getBlockType() == Material.FURNACE.getId()
|
||||||
|
|| reset.getBlockType() == Material.BURNING_FURNACE.getId()) {
|
||||||
|
List<ItemStack> items = reset.getItems();
|
||||||
|
|
||||||
|
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||||
|
worldBlock.setData(reset.getBlockData());
|
||||||
|
BlockState state = worldBlock.getState();
|
||||||
|
if (state instanceof ContainerBlock) {
|
||||||
|
ContainerBlock container = (ContainerBlock) state;
|
||||||
|
if (items != null) {
|
||||||
|
int ii = 0;
|
||||||
|
container.getInventory().clear();
|
||||||
|
for (ItemStack item : items) {
|
||||||
|
if (item != null) {
|
||||||
|
container.getInventory().setItem(ii, item);
|
||||||
|
ii++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
state.update(true);
|
||||||
|
items.clear();
|
||||||
}
|
}
|
||||||
if (reset.getLines().length > 2) {
|
} else {
|
||||||
sign.setLine(2, reset.getLines()[2]);
|
// normal reset
|
||||||
}
|
worldBlock.setData(reset.getBlockData());
|
||||||
if (reset.getLines().length > 3) {
|
}
|
||||||
sign.setLine(3, reset.getLines()[3]);
|
} else if (reset.getBlockType() == Material.NOTE_BLOCK.getId()) {
|
||||||
}
|
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
|
||||||
sign.update(true);
|
worldBlock.setData(reset.getBlockData());
|
||||||
|
BlockState state = worldBlock.getState();
|
||||||
|
if (state instanceof NoteBlock && reset.getRawNote() != null) {
|
||||||
|
NoteBlock noteBlock = (NoteBlock) state;
|
||||||
|
noteBlock.setRawNote(reset.getRawNote());
|
||||||
|
noteBlock.update(true);
|
||||||
|
} else {
|
||||||
|
// normal reset
|
||||||
|
worldBlock.setData(reset.getBlockData());
|
||||||
|
}
|
||||||
|
} else if (reset.getBlockType() == Material.WOODEN_DOOR.getId() || reset.getBlockType() == Material.IRON_DOOR_BLOCK.getId()) {
|
||||||
|
// Door blocks
|
||||||
|
doors.add(reset);
|
||||||
|
} else {
|
||||||
|
// normal data reset
|
||||||
|
worldBlock.setData(reset.getBlockData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take care of doors last
|
||||||
|
for (DeferredBlockReset doorBlock : doors) {
|
||||||
|
Block worldBlock = world.getBlockAt(doorBlock.getX(), doorBlock.getY(), doorBlock.getZ());
|
||||||
|
if (worldBlock.getTypeId() != doorBlock.getBlockType() || worldBlock.getData() != doorBlock.getBlockData()) {
|
||||||
|
// find its friend
|
||||||
|
for (DeferredBlockReset other : doors) {
|
||||||
|
if (other.getX() == doorBlock.getX()
|
||||||
|
&& other.getY() == doorBlock.getY() - 1
|
||||||
|
&& other.getZ() == doorBlock.getZ()) {
|
||||||
|
// doorBlock is above
|
||||||
|
Block above = worldBlock;
|
||||||
|
Block below = world.getBlockAt(other.getX(), other.getY(), other.getZ());
|
||||||
|
above.setTypeId(doorBlock.getBlockType());
|
||||||
|
above.setData(doorBlock.getBlockData());
|
||||||
|
below.setTypeId(other.getBlockType());
|
||||||
|
below.setData(other.getBlockData());
|
||||||
|
scrubDroppedDoors(below);
|
||||||
|
break;
|
||||||
|
} else if (other.getX() == doorBlock.getX()
|
||||||
|
&& other.getY() == doorBlock.getY() + 1
|
||||||
|
&& other.getZ() == doorBlock.getZ()) {
|
||||||
|
// doorBlock is below
|
||||||
|
Block above = world.getBlockAt(other.getX(), other.getY(), other.getZ());
|
||||||
|
Block below = worldBlock;
|
||||||
|
above.setTypeId(doorBlock.getBlockType());
|
||||||
|
above.setData(doorBlock.getBlockData());
|
||||||
|
below.setTypeId(other.getBlockType());
|
||||||
|
below.setData(other.getBlockData());
|
||||||
|
scrubDroppedDoors(below);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// normal data reset
|
|
||||||
worldBlock.setData(reset.getBlockData());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scrubDroppedDoors(Block block) {
|
||||||
|
Chunk chunk = block.getWorld().getChunkAt(block);
|
||||||
|
Volume scrubVolume = new Volume("scrub", block.getWorld());
|
||||||
|
scrubVolume.setCornerOne(block.getRelative(BlockFace.DOWN).getRelative(BlockFace.EAST).getRelative(BlockFace.NORTH));
|
||||||
|
scrubVolume.setCornerTwo(block.getRelative(BlockFace.UP).getRelative(BlockFace.WEST).getRelative(BlockFace.SOUTH));
|
||||||
|
for (Entity entity : chunk.getEntities()) {
|
||||||
|
if ((entity instanceof Item && (((Item)entity).getItemStack().getTypeId() == Material.IRON_DOOR.getId()
|
||||||
|
|| ((Item)entity).getItemStack().getTypeId() == Material.WOOD_DOOR.getId()))
|
||||||
|
&& scrubVolume.contains(entity.getLocation())) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,11 @@ public class WarMapper {
|
|||||||
War.war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage"));
|
War.war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tntInZonesOnly
|
||||||
|
if (warConfig.keyExists("tntInZonesOnly")) {
|
||||||
|
War.war.setTntInZonesOnly(warConfig.getBoolean("tntInZonesOnly"));
|
||||||
|
}
|
||||||
|
|
||||||
// defaultSpawnStyle
|
// defaultSpawnStyle
|
||||||
String spawnStyle = warConfig.getString("defaultspawnStyle");
|
String spawnStyle = warConfig.getString("defaultspawnStyle");
|
||||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||||
@ -338,6 +343,9 @@ public class WarMapper {
|
|||||||
// disablePVPMessage
|
// disablePVPMessage
|
||||||
warConfig.setBoolean("disablePvpMessage", War.war.isDisablePvpMessage());
|
warConfig.setBoolean("disablePvpMessage", War.war.isDisablePvpMessage());
|
||||||
|
|
||||||
|
// tntInZonesOnly
|
||||||
|
warConfig.setBoolean("tntInZonesOnly", War.war.isTntInZonesOnly());
|
||||||
|
|
||||||
// spawnStyle
|
// spawnStyle
|
||||||
warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
|
warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class ZoneVolumeMapper {
|
|||||||
String[] lines = linesStr.split(";;");
|
String[] lines = linesStr.split(";;");
|
||||||
|
|
||||||
// Signs set
|
// Signs set
|
||||||
if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
if (diskBlockType == Material.WALL_SIGN.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
||||||
// A sign post hanging on a wall south of here needs that block to be set first
|
// A sign post hanging on a wall south of here needs that block to be set first
|
||||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.tommytony.war.utils;
|
package com.tommytony.war.utils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class DeferredBlockReset {
|
public class DeferredBlockReset {
|
||||||
|
|
||||||
private final int x;
|
private final int x;
|
||||||
@ -8,6 +12,8 @@ public class DeferredBlockReset {
|
|||||||
private final int blockType;
|
private final int blockType;
|
||||||
private final byte blockData;
|
private final byte blockData;
|
||||||
private String[] lines;
|
private String[] lines;
|
||||||
|
private List<ItemStack> items;
|
||||||
|
private Byte rawNote;
|
||||||
|
|
||||||
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) {
|
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -27,6 +33,26 @@ public class DeferredBlockReset {
|
|||||||
this.lines = signLines;
|
this.lines = signLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container block
|
||||||
|
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, List<ItemStack> contents) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.blockType = blockType;
|
||||||
|
this.blockData = blockData;
|
||||||
|
this.items = contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Noteblock
|
||||||
|
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, byte rawNote) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.blockType = blockType;
|
||||||
|
this.blockData = blockData;
|
||||||
|
this.rawNote = rawNote;
|
||||||
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return this.x;
|
return this.x;
|
||||||
}
|
}
|
||||||
@ -50,4 +76,12 @@ public class DeferredBlockReset {
|
|||||||
public String[] getLines() {
|
public String[] getLines() {
|
||||||
return this.lines;
|
return this.lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ItemStack> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Byte getRawNote() {
|
||||||
|
return rawNote;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user