Merge pull request #845 from Ultra03/develop

Fix a lot of errors for updating to 1.13
This commit is contained in:
Connor Monahan 2018-11-19 19:49:58 -06:00 committed by GitHub
commit 81f839a0a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 237 additions and 2609 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tommytony</groupId>
<artifactId>war</artifactId>
<version>1.10-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>War</name>
<url>http://war.tommytony.com</url>
@ -15,21 +15,17 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>maven.cmastudios.me</id>
<url>https://maven.cmastudios.me/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>cma-repo</id>
<url>http://ftp.cmastudios.me/maven/</url>
</repository>
<repository>
<id>tagapi-repo</id>
<url>http://repo.kitteh.org/content/repositories/public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
<url>https://maven.sk89q.com/repo/</url>
</repository>
</repositories>
<issueManagement>
@ -48,8 +44,8 @@
</scm>
<distributionManagement>
<repository>
<id>cma-repo</id>
<url>ftp://ftp.cmastudios.me/srv/ftp/maven</url>
<id>maven.cmastudios.me</id>
<url>s3://maven.cmastudios.me/</url>
</repository>
</distributionManagement>
<build>
@ -93,8 +89,9 @@
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<groupId>org.kuali.maven.wagons</groupId>
<artifactId>maven-s3-wagon</artifactId>
<version>1.2.1</version>
</extension>
</extensions>
<resources>
@ -121,7 +118,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.13-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>
@ -137,9 +134,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.5.8</version>
<groupId>com.tommytony</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-beta-01</version>
<type>jar</type>
</dependency>
<dependency>

View File

@ -330,7 +330,7 @@ public class Team {
this.getTeamConfig().resolveInt(
TeamConfig.LIFEPOOL)).split("\n");
}
signBlock.setType(Material.SIGN_POST);
signBlock.setType(Material.SIGN);
org.bukkit.block.Sign block = (org.bukkit.block.Sign) signBlock
.getState();
org.bukkit.material.Sign data = (Sign) block.getData();
@ -350,7 +350,6 @@ public class Team {
private void setBlock(int x, int y, int z, TeamKind kind) {
BlockState block = this.warzone.getWorld().getBlockAt(x, y, z).getState();
block.setType(kind.getMaterial());
block.setData(kind.getBlockData());
block.update(true);
}
@ -616,7 +615,6 @@ public class Team {
// flag
BlockState flagBlock = this.warzone.getWorld().getBlockAt(x, y + 1, z).getState();
flagBlock.setType(this.kind.getMaterial());
flagBlock.setData(this.kind.getBlockData());
flagBlock.update(true);
// Flag post using Orientation

View File

@ -12,10 +12,7 @@ import com.tommytony.war.mapper.WarzoneYmlMapper;
import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.*;
import com.tommytony.war.ui.UIManager;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.SizeCounter;
import com.tommytony.war.utility.WarLogFormatter;
import com.tommytony.war.utility.*;
import com.tommytony.war.volume.Volume;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
@ -83,7 +80,7 @@ public class War extends JavaPlugin {
private Economy econ = null;
private SpoutDisplayer spoutMessenger = null;
private HubLobbyMaterials warhubMaterials = new HubLobbyMaterials(
new ItemStack(Material.GLASS), new ItemStack(Material.WOOD),
new ItemStack(Material.GLASS), new ItemStack(Material.OAK_WOOD),
new ItemStack(Material.OBSIDIAN), new ItemStack(Material.GLOWSTONE));
private UIManager UIManager;
@ -224,23 +221,19 @@ public class War extends JavaPlugin {
this.getDefaultInventories().clearLoadouts();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD, 1, (byte) 8);
stoneSword.setDurability((short) 8);
ItemStack stoneSword = Compat.createDamagedIS(Material.STONE_SWORD, 1, (byte) 8);
defaultLoadout.put(0, stoneSword);
ItemStack bow = new ItemStack(Material.BOW, 1, (byte) 8);
bow.setDurability((short) 8);
ItemStack bow = Compat.createDamagedIS(Material.BOW, 1, (byte) 8);
defaultLoadout.put(1, bow);
ItemStack arrows = new ItemStack(Material.ARROW, 7);
defaultLoadout.put(2, arrows);
ItemStack stonePick = new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8);
stonePick.setDurability((short) 8);
ItemStack stonePick = Compat.createDamagedIS(Material.IRON_PICKAXE, 1, (byte) 8);
defaultLoadout.put(3, stonePick);
ItemStack stoneSpade = new ItemStack(Material.STONE_SPADE, 1, (byte) 8);
stoneSword.setDurability((short) 8);
ItemStack stoneSpade = Compat.createDamagedIS(Material.STONE_SHOVEL, 1, (byte) 8);
defaultLoadout.put(4, stoneSpade);
this.getDefaultInventories().addLoadout("default", defaultLoadout);
@ -1127,7 +1120,7 @@ public class War extends JavaPlugin {
public void addWandBearer(Player player, String zoneName) {
if (this.wandBearers.containsKey(player.getName())) {
String alreadyHaveWand = this.wandBearers.get(player.getName());
if (player.getInventory().first(Material.WOOD_SWORD) != -1) {
if (player.getInventory().first(Material.WOODEN_SWORD) != -1) {
if (zoneName.equals(alreadyHaveWand)) {
this.badMsg(player, "You already have a wand for zone " + alreadyHaveWand + ". Drop the wooden sword first.");
} else {
@ -1140,7 +1133,7 @@ public class War extends JavaPlugin {
// lost his sword, or new warzone
if (zoneName.equals(alreadyHaveWand)) {
// same zone, give him a new sword
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
player.getInventory().addItem(new ItemStack(Material.WOODEN_SWORD, 1, (byte) 8));
this.msg(player, "Here's a new sword for zone " + zoneName + ".");
}
}
@ -1149,7 +1142,7 @@ public class War extends JavaPlugin {
this.badMsg(player, "Your inventory is full. Please drop an item and try again.");
} else {
this.wandBearers.put(player.getName(), zoneName);
player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8));
player.getInventory().addItem(new ItemStack(Material.WOODEN_SWORD, 1, (byte) 8));
// player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD));
this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wooden sword for corner 1. Right-click for corner 2.");
War.war.log(player.getName() + " now has a wand for warzone " + zoneName, Level.INFO);

View File

@ -103,7 +103,7 @@ public class Warzone {
private HubLobbyMaterials lobbyMaterials = null;
private WarzoneMaterials warzoneMaterials = new WarzoneMaterials(
new ItemStack(Material.OBSIDIAN), new ItemStack(Material.FENCE),
new ItemStack(Material.OBSIDIAN), new ItemStack(Material.OAK_FENCE),
new ItemStack(Material.GLOWSTONE));
private boolean isEndOfGame = false;
@ -1123,7 +1123,7 @@ public class Warzone {
return;
if (this.getScoreboard() == null)
return;
if (this.scoreboard.getObjective(this.getScoreboardType().getDisplayName()) == null) {
if (this.scoreboard.getObjective(this.getScoreboardType().name()) == null) {
for (String entry : this.scoreboard.getEntries()) {
this.scoreboard.resetScores(entry);
}
@ -1131,8 +1131,8 @@ public class Warzone {
for (Objective obj : this.scoreboard.getObjectives()) {
obj.unregister();
}
scoreboard.registerNewObjective(this.getScoreboardType().getDisplayName(), "dummy");
Objective obj = scoreboard.getObjective(this.getScoreboardType().getDisplayName());
scoreboard.registerNewObjective(this.getScoreboardType().name(), "dummy", this.getScoreboardType().getDisplayName());
Objective obj = scoreboard.getObjective(this.getScoreboardType().name());
Validate.isTrue(obj.isModifiable(), "Cannot modify players' scores on the " + this.name + " scoreboard.");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
}

View File

@ -1,13 +1,9 @@
package com.tommytony.war.command;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.tommytony.war.War;
import com.tommytony.war.utility.Compat;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import com.tommytony.war.War;
public class SetZoneCommand extends AbstractZoneMakerCommand {
@ -30,20 +26,15 @@ public class SetZoneCommand extends AbstractZoneMakerCommand {
} else if (this.args.length > 2) {
return false;
} else if (this.args.length == 1) {
if (War.war.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
WorldEditPlugin worldEdit = (WorldEditPlugin) War.war.getServer().getPluginManager().getPlugin("WorldEdit");
Selection selection = worldEdit.getSelection(player);
if (selection != null && selection instanceof CuboidSelection) {
Location min = selection.getMinimumPoint();
Location max = selection.getMaximumPoint();
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
setter.placeCorner1(min.getBlock());
setter.placeCorner2(max.getBlock());
return true;
}
Compat.BlockPair pair = Compat.getWorldEditSelection(player);
if (pair != null) {
ZoneSetter setter = new ZoneSetter(player, this.args[0]);
setter.placeCorner1(pair.getBlock1());
setter.placeCorner2(pair.getBlock2());
return true;
}
War.war.addWandBearer(player, this.args[0]);
} else if (this.args.length == 2) {
} else {
if (!this.args[1].equals("southeast") && !this.args[1].equals("northwest") && !this.args[1].equals("se") && !this.args[1].equals("nw") && !this.args[1].equals("corner1") && !this.args[1].equals("corner2") && !this.args[1].equals("c1") && !this.args[1].equals("c2") && !this.args[1].equals("pos1") && !this.args[1].equals("pos2") && !this.args[1].equals("wand")) {
return false;
}

View File

@ -45,7 +45,7 @@ public class KillstreakReward {
section.set("5.reward.airstrike", true);
section.set("5.reward.items", ImmutableList.of(new ItemStack(Material.ARROW, 15), new ItemStack(Material.EGG)));
section.set("5.reward.effect", Effect.GHAST_SHRIEK.name());
ItemStack sword = new ItemStack(Material.WOOD_SWORD);
ItemStack sword = new ItemStack(Material.WOODEN_SWORD);
sword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
sword.addEnchantment(Enchantment.KNOCKBACK, 1);
ItemMeta meta = sword.getItemMeta();

View File

@ -11,22 +11,22 @@ import org.bukkit.material.Wool;
import org.getspout.spoutapi.gui.Color;
public enum TeamKind {
WHITE (DyeColor.WHITE, Material.WOOL, ChatColor.WHITE, 450),
ORANGE (DyeColor.ORANGE, Material.WOOL, ChatColor.GOLD, 51),
MAGENTA (DyeColor.MAGENTA, Material.WOOL, ChatColor.LIGHT_PURPLE, 353),
BLUE (DyeColor.LIGHT_BLUE, Material.WOOL, ChatColor.BLUE, 23),
GOLD (DyeColor.YELLOW, Material.WOOL, ChatColor.YELLOW, 403), // yellow = gold
GREEN (DyeColor.LIME, Material.WOOL, ChatColor.GREEN, 612),
PINK (DyeColor.PINK, Material.WOOL, ChatColor.LIGHT_PURPLE, 929),
GRAY (DyeColor.GRAY, Material.WOOL, ChatColor.DARK_GRAY, 600),
IRON (DyeColor.SILVER, Material.WOOL, ChatColor.GRAY, 154), // lightgrey = iron
DIAMOND (DyeColor.CYAN, Material.WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
PURPLE (DyeColor.PURPLE, Material.WOOL, ChatColor.DARK_PURPLE, 153),
NAVY (DyeColor.BLUE, Material.WOOL, ChatColor.DARK_BLUE, 939),
BROWN (DyeColor.BROWN, Material.WOOL, ChatColor.DARK_RED, 908),
DARKGREEN (DyeColor.GREEN, Material.WOOL, ChatColor.DARK_GREEN, 612),
RED (DyeColor.RED, Material.WOOL, ChatColor.RED, 245),
BLACK (DyeColor.BLACK, Material.WOOL, ChatColor.BLACK, 0);
WHITE (DyeColor.WHITE, Material.WHITE_WOOL, ChatColor.WHITE, 450),
ORANGE (DyeColor.ORANGE, Material.ORANGE_WOOL, ChatColor.GOLD, 51),
MAGENTA (DyeColor.MAGENTA, Material.MAGENTA_WOOL, ChatColor.LIGHT_PURPLE, 353),
BLUE (DyeColor.LIGHT_BLUE, Material.LIGHT_BLUE_WOOL, ChatColor.BLUE, 23),
GOLD (DyeColor.YELLOW, Material.YELLOW_WOOL, ChatColor.YELLOW, 403), // yellow = gold
GREEN (DyeColor.LIME, Material.LIME_WOOL, ChatColor.GREEN, 612),
PINK (DyeColor.PINK, Material.PINK_WOOL, ChatColor.LIGHT_PURPLE, 929),
GRAY (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.DARK_GRAY, 600),
IRON (DyeColor.GRAY, Material.GRAY_WOOL, ChatColor.GRAY, 154), // lightgrey = iron
DIAMOND (DyeColor.CYAN, Material.CYAN_WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
PURPLE (DyeColor.PURPLE, Material.PURPLE_WOOL, ChatColor.DARK_PURPLE, 153),
NAVY (DyeColor.BLUE, Material.BLUE_WOOL, ChatColor.DARK_BLUE, 939),
BROWN (DyeColor.BROWN, Material.BROWN_WOOL, ChatColor.DARK_RED, 908),
DARKGREEN (DyeColor.GREEN, Material.GREEN_WOOL, ChatColor.DARK_GREEN, 612),
RED (DyeColor.RED, Material.RED_WOOL, ChatColor.RED, 245),
BLACK (DyeColor.BLACK, Material.BLACK_WOOL, ChatColor.BLACK, 0);
private final DyeColor dyeColor;
private final ChatColor chatColor;
@ -61,23 +61,13 @@ public enum TeamKind {
/**
* Get wool block data for the dye color.
*
* @deprecated TODO remove all spout craft support
* @return wool color data value
*/
@SuppressWarnings("deprecation")
public byte getData() {
return this.dyeColor.getWoolData();
}
/**
* Get the color of the wool head block.
*
* @return head wool color.
*/
public DyeColor getDyeColor() {
return this.dyeColor;
}
/**
* Get the color of this team in chat messages.
*
@ -108,7 +98,7 @@ public enum TeamKind {
}
/**
* Get head block material. Should always be {@link Material#WOOL}.
* Get head block material.
*
* @return team head block material.
*/
@ -131,22 +121,12 @@ public enum TeamKind {
}
/**
* Get a single item of this team's wool head block. Creates a single block
* with data from {@link #getBlockData()}.
* Get a single item of this team's wool head block.
*
* @return single block head item.
*/
public ItemStack getBlockHead() {
return new Wool(this.dyeColor).toItemStack(1);
}
/**
* Get wool head block data (for creating blocks).
*
* @return wool head block data.
*/
public MaterialData getBlockData() {
return new Wool(this.dyeColor);
return new ItemStack(this.material, 1);
}
/**
@ -156,11 +136,7 @@ public enum TeamKind {
* @return true if block is this team's color.
*/
public boolean isTeamBlock(BlockState block) {
if (block.getType() != Material.WOOL || !(block.getData() instanceof Wool)) {
return false;
}
Wool wool = (Wool) block.getData();
return wool.getColor() == dyeColor;
return block.getType() == material;
}
/**
@ -170,21 +146,7 @@ public enum TeamKind {
* @return true if item is this team's color.
*/
public boolean isTeamItem(ItemStack item) {
if (item.getType() != Material.WOOL || !(item.getData() instanceof Wool)) {
return false;
}
Wool wool = (Wool) item.getData();
return wool.getColor() == dyeColor;
}
/**
* Check if a block data is this team's block data.
*
* @param data Wool block data.
* @return true if data is this team's data.
*/
public boolean isTeamBlock(MaterialData data) {
return data instanceof Wool && ((Wool)data).getColor() == this.dyeColor;
return item.getType() == material;
}
public String getFormattedName() {

View File

@ -1,30 +1,5 @@
package com.tommytony.war.event;
import java.util.List;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
@ -35,6 +10,26 @@ import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.structure.Cake;
import com.tommytony.war.structure.Monument;
import com.tommytony.war.utility.Compat;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer;
import java.util.ArrayList;
import java.util.List;
/**
*
@ -58,9 +53,7 @@ public class WarBlockListener implements Listener {
Team team = Team.getTeamByPlayerName(player.getName());
Warzone zone = Warzone.getZoneByLocation(player);
// Monument capturing
if (team != null && block != null && zone != null
&& zone.isMonumentCenterBlock(block)
&& team.getKind().isTeamBlock(block.getState())) {
if (team != null && zone != null && zone.isMonumentCenterBlock(block) && team.getKind().isTeamBlock(block.getState())) {
Monument monument = zone.getMonumentFromCenterBlock(block);
if (monument != null && !monument.hasOwner()) {
monument.capture(team);
@ -89,9 +82,7 @@ public class WarBlockListener implements Listener {
boolean isZoneMaker = War.war.isZoneMaker(player);
// prevent build in important parts
if (zone != null
&& (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block))
&& (!isZoneMaker || (isZoneMaker && team != null))) {
if (zone != null && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block)) && (!isZoneMaker || team != null)) {
War.war.badMsg(player, "build.denied.location");
cancelAndKeepItem(event);
return;
@ -123,7 +114,7 @@ public class WarBlockListener implements Listener {
}
// can't place a block of your team's color
if (team != null && block.getType() == team.getKind().getMaterial() && block.getState().getData() == team.getKind().getBlockData()) {
if (team != null && block.getType() == team.getKind().getMaterial()) {
War.war.badMsg(player, "build.denied.teamblock");
cancelAndKeepItem(event);
return;
@ -151,9 +142,7 @@ public class WarBlockListener implements Listener {
}
// unbreakableZoneBlocks
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
|| (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))
&& (!isZoneMaker || (isZoneMaker && team != null))) {
if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) || team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)) && (!isZoneMaker || team != null)) {
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
War.war.badMsg(player, "build.denied.zone.place");
cancelAndKeepItem(event);
@ -175,7 +164,7 @@ public class WarBlockListener implements Listener {
if (inHand.getType() == Material.FIRE) {
// Weird bukkit/mc behavior where item in hand is reported as fire while using flint & steel.
// Just give the user his f&s back but almost broken (max durability is 8).
newItemInHand = new ItemStack(Material.FLINT_AND_STEEL, 1, (short)1);
newItemInHand = Compat.createDamagedIS(Material.FLINT_AND_STEEL, 1, 1);
} else {
newItemInHand = inHand.clone();
}

View File

@ -20,6 +20,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
@ -159,7 +160,7 @@ public class WarPlayerListener implements Listener {
if (War.war.isWandBearer(player)) {
Item item = event.getItemDrop();
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
if (item.getItemStack().getType() == Material.WOODEN_SWORD) {
String zoneName = War.war.getWandBearerZone(player);
War.war.removeWandBearer(player);
War.war.msg(player, "drop.wand", zoneName);
@ -170,12 +171,15 @@ public class WarPlayerListener implements Listener {
private static final int MINIMUM_TEAM_BLOCKS = 1;
@EventHandler
public void onPlayerPickupItem(final PlayerPickupItemEvent event) {
public void onPlayerPickupItem(final EntityPickupItemEvent event) {
if (War.war.isLoaded()) {
Player player = event.getPlayer();
if (!(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
Team team = Team.getTeamByPlayerName(player.getName());
if (team != null) {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
Warzone zone = team.getZone();
if (zone.isFlagThief(player)) {
// a flag thief can't pick up anything
@ -238,7 +242,7 @@ public class WarPlayerListener implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) {
if (War.war.isLoaded()) {
Player player = event.getPlayer();
if (event.getItem() != null && event.getItem().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
if (event.getItem() != null && event.getItem().getType() == Material.WOODEN_SWORD && War.war.isWandBearer(player)) {
String zoneName = War.war.getWandBearerZone(player);
ZoneSetter setter = new ZoneSetter(player, zoneName);
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR) {
@ -269,7 +273,7 @@ public class WarPlayerListener implements Listener {
War.war.badMsg(player, "use.ender");
}
Team team = Team.getTeamByPlayerName(player.getName());
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
if (zone != null && team != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENCHANTING_TABLE && team.getTeamConfig().resolveBoolean(TeamConfig.XPKILLMETER)) {
event.setCancelled(true);
War.war.badMsg(player, "use.enchant");
if (zone.getAuthors().contains(player.getName())) {
@ -305,7 +309,7 @@ public class WarPlayerListener implements Listener {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.SOUPHEALING)) {
ItemStack item = event.getItem();
if ((item != null) && (item.getType() == Material.MUSHROOM_SOUP)) {
if ((item != null) && (item.getType() == Material.MUSHROOM_STEW)) {
if (player.getHealth() < 20) {
player.setHealth(Math.min(20, player.getHealth() + 7));
item.setType(Material.BOWL);
@ -340,7 +344,7 @@ public class WarPlayerListener implements Listener {
latestLocations.put(player.getName(), playerLoc);
// Signs can automatically teleport you to specific or random warzones
if (playerLoc.getBlock().getType() == Material.SIGN_POST) {
if (playerLoc.getBlock().getType() == Material.SIGN) {
Sign sign = (Sign) playerLoc.getBlock().getState();
if (sign.getLine(0).equals("[zone]")) {
Warzone indicated = Warzone.getZoneByName(sign.getLine(1));

View File

@ -44,7 +44,7 @@ public class HelmetProtectionTask implements Runnable {
int removed = 0;
for (ItemStack item : playerInv.getContents()) {
// remove only same colored wool
if (item != null && item.getType() == teamBlockMaterial && item.getData() == team.getKind().getBlockData()) {
if (item != null && item.getType() == teamBlockMaterial) {
playerInv.clear(i);
removed++;
}
@ -68,7 +68,7 @@ public class HelmetProtectionTask implements Runnable {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.getInventory().setHeldItemSlot(0);
player.getInventory().addItem(victim.getKind().getBlockData().toItemStack(2240));
player.getInventory().addItem(new ItemStack(victim.getKind().getMaterial(), 2240));
} else if (zone.isBombThief(player)) {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
@ -78,7 +78,7 @@ public class HelmetProtectionTask implements Runnable {
player.getInventory().setItemInMainHand(null);
player.getInventory().setItemInOffHand(null);
player.getInventory().setHeldItemSlot(0);
player.getInventory().addItem(new ItemStack(Material.CAKE_BLOCK, 2240));
player.getInventory().addItem(new ItemStack(Material.CAKE, 2240));
}
}
}

View File

@ -1,69 +0,0 @@
package com.tommytony.war.job;
import java.sql.SQLException;
import java.util.logging.Level;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.mapper.WarYmlMapper;
import com.tommytony.war.mapper.WarzoneTxtMapper;
import com.tommytony.war.mapper.WarzoneYmlMapper;
public class RestoreWarzonesJob implements Runnable {
private final String warzonesStr;
private final boolean newWarInstall;
private final boolean convertingToYml;
public RestoreWarzonesJob(String warzonesStr, boolean newWarInstall, boolean convertingToYml) {
this.warzonesStr = warzonesStr;
this.newWarInstall = newWarInstall;
this.convertingToYml = convertingToYml;
}
public void run() {
String[] warzoneSplit = this.warzonesStr.split(",");
War.war.getWarzones().clear();
for (String warzoneName : warzoneSplit) {
if (warzoneName != null && !warzoneName.equals("")) {
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
if (zone != null) { // could have failed, would've been logged already
War.war.getWarzones().add(zone);
try {
zone.getVolume().loadCorners();
} catch (SQLException ex) {
War.war.log("Failed to load warzone " + warzoneName + ": " + ex.getMessage(), Level.WARNING);
throw new RuntimeException(ex);
}
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
zone.getVolume().resetBlocks();
}
zone.initializeZone();
}
}
}
if (War.war.getWarzones().size() > 0) {
War.war.log("Warzones ready.", Level.INFO);
}
if (convertingToYml) {
// Loading process is over, we can convert (i.e. save in new format)
WarYmlMapper.save();
War.war.log("Converted war.txt to war.yml.", Level.INFO);
for (Warzone zone : War.war.getWarzones()) {
WarzoneYmlMapper.save(zone);
War.war.log("Converted warzone-" + zone.getName() + ".txt to warzone-" + zone.getName() + ".yml.", Level.INFO);
}
}
}
}

View File

@ -22,7 +22,6 @@ public class RestoreYmlWarhubJob implements Runnable {
this.warhubConfig = warhubConfig;
}
@SuppressWarnings("deprecation")
public void run() {
int hubX = warhubConfig.getInt("x");
int hubY = warhubConfig.getInt("y");
@ -35,50 +34,18 @@ public class RestoreYmlWarhubJob implements Runnable {
if (warhubConfig.isItemStack("materials.floor")) {
War.war.getWarhubMaterials().setFloorBlock(
warhubConfig.getItemStack("materials.floor"));
} else {
ConfigurationSection floorMaterialSection = warhubConfig
.getConfigurationSection("materials.floor");
if (floorMaterialSection != null) {
War.war.getWarhubMaterials().setFloorBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warhubConfig.isItemStack("materials.outline")) {
War.war.getWarhubMaterials().setOutlineBlock(
warhubConfig.getItemStack("materials.outline"));
} else {
ConfigurationSection floorMaterialSection = warhubConfig
.getConfigurationSection("materials.outline");
if (floorMaterialSection != null) {
War.war.getWarhubMaterials().setOutlineBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warhubConfig.isItemStack("materials.gate")) {
War.war.getWarhubMaterials().setGateBlock(
warhubConfig.getItemStack("materials.gate"));
} else {
ConfigurationSection floorMaterialSection = warhubConfig
.getConfigurationSection("materials.gate");
if (floorMaterialSection != null) {
War.war.getWarhubMaterials().setGateBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warhubConfig.isItemStack("materials.light")) {
War.war.getWarhubMaterials().setLightBlock(
warhubConfig.getItemStack("materials.light"));
} else {
ConfigurationSection floorMaterialSection = warhubConfig
.getConfigurationSection("materials.light");
if (floorMaterialSection != null) {
War.war.getWarhubMaterials().setLightBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
World world = War.war.getServer().getWorld(worldName);
if (world != null) {

View File

@ -1,46 +0,0 @@
package com.tommytony.war.mapper;
import java.util.HashMap;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.War;
@SuppressWarnings("deprecation")
public class LoadoutTxtMapper {
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
String[] rewardStrSplit = loadoutString.split(";");
destinationLoadout.clear();
for (String itemStr : rewardStrSplit) {
if (itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(",");
ItemStack item = null;
if (itemStrSplit.length == 3) {
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
} else if (itemStrSplit.length == 5) {
short durability = Short.parseShort(itemStrSplit[3]);
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
item.setDurability(durability);
} else if (itemStrSplit.length == 6) {
short durability = Short.parseShort(itemStrSplit[3]);
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
item.setDurability(durability);
// enchantments
String[] enchantmentsSplit = itemStrSplit[5].split("::");
for (String enchantmentStr : enchantmentsSplit) {
if (!enchantmentStr.equals("")) {
String[] enchantmentSplit = enchantmentStr.split(":");
int enchantId = Integer.parseInt(enchantmentSplit[0]);
int level = Integer.parseInt(enchantmentSplit[1]);
War.war.safelyEnchant(item, Enchantment.getById(enchantId), level);
}
}
}
destinationLoadout.put(Integer.parseInt(itemStrSplit[2]), item);
}
}
}
}

View File

@ -50,66 +50,16 @@ public class LoadoutYmlMapper {
* @param loadoutName The name of the loadout
* @return new style loadout
*/
@SuppressWarnings("deprecation")
public static Loadout fromConfigToLoadout(ConfigurationSection config, HashMap<Integer, ItemStack> loadout, String loadoutName) {
List<Integer> slots = config.getIntegerList(loadoutName + ".slots");
for (Integer slot : slots) {
if (config.isItemStack(loadoutName + "." + Integer.toString(slot))) {
loadout.put(slot, config.getItemStack(loadoutName + "." + Integer.toString(slot)));
continue;
}
String prefix = loadoutName + "." + slot + ".";
int id = config.getInt(prefix + "id");
int amount = config.getInt(prefix + "amount");
short durability = (short)config.getInt(prefix + "durability");
ItemStack stack = new ItemStack(id, amount, durability);
stack.setDurability(durability);
if (config.contains(prefix + "enchantments")) {
List<String> enchantmentStringList = config.getStringList(prefix + "enchantments");
for (String enchantmentString : enchantmentStringList) {
String[] enchantmentStringSplit = enchantmentString.split(",");
if (enchantmentStringSplit.length == 2) {
int enchantId = Integer.parseInt(enchantmentStringSplit[0]);
int level = Integer.parseInt(enchantmentStringSplit[1]);
War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level);
}
}
}
if (config.contains(prefix + "armorcolor")) {
int rgb = config.getInt(prefix + "armorcolor");
Color clr = Color.fromRGB(rgb);
LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
meta.setColor(clr);
stack.setItemMeta(meta);
}
if (config.contains(prefix + "name")) {
String itemName = config.getString(prefix + "name");
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(itemName);
stack.setItemMeta(meta);
}
if (config.contains(prefix + "lore")) {
List<String> itemLore = config.getStringList(prefix + "lore");
ItemMeta meta = stack.getItemMeta();
meta.setLore(itemLore);
stack.setItemMeta(meta);
}
loadout.put(slot, stack);
}
String permission = config.getString(loadoutName + ".permission", "");
return new Loadout(loadoutName, loadout, permission);
}
public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) {
List<String> sortedNames = sortNames(loadouts);
section.set("names", sortedNames);
for (String name : sortedNames) {
fromLoadoutToConfig(name, loadouts.get(name), section);
}
}
/**
* Serializes a list of new style loadouts to the configuration.
@ -144,11 +94,7 @@ public class LoadoutYmlMapper {
}
private static List<Integer> toIntList(Set<Integer> keySet) {
List<Integer> list = new ArrayList<Integer>();
for (Integer key : keySet) {
list.add(key);
}
return list;
return new ArrayList<Integer>(keySet);
}
/**

View File

@ -1,282 +0,0 @@
package com.tommytony.war.mapper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.tommytony.war.War;
import com.tommytony.war.job.DeferredBlockResetsJob;
import com.tommytony.war.utility.DeferredBlockReset;
import com.tommytony.war.volume.ZoneVolume;
/**
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
*
* @author tommytony
*
*/
@SuppressWarnings("deprecation")
public class PreDeGaulleZoneVolumeMapper {
private static List<ItemStack> readInventoryString(String invString) {
List<ItemStack> items = new ArrayList<ItemStack>();
String[] itemsStrSplit = invString.split(";;");
for (String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";");
if (itemStrSplit.length == 4) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
short durability = (short) Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else if (itemStrSplit.length == 3) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
short durability = (short) Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else {
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
}
}
return items;
}
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
BufferedReader in = null;
int noOfResetBlocks = 0;
try {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
String firstLine = in.readLine();
if (firstLine != null && !firstLine.equals("")) {
boolean height129Fix = false;
int x1 = Integer.parseInt(in.readLine());
int y1 = Integer.parseInt(in.readLine());
if (y1 == 128) {
height129Fix = true;
y1 = 127;
}
int z1 = Integer.parseInt(in.readLine());
in.readLine();
int x2 = Integer.parseInt(in.readLine());
int y2 = Integer.parseInt(in.readLine());
if (y2 == 128) {
height129Fix = true;
y2 = 127;
}
int z2 = Integer.parseInt(in.readLine());
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
if (!onlyLoadCorners) {
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
int diskBlockType;
byte diskBlockData;
Block worldBlock;
int worldBlockId;
volume.clearBlocksThatDontFloat();
x = volume.getMinX();
String blockLine;
String[] blockSplit;
for (i = 0; i < volume.getSizeX(); i++) {
y = volume.getMinY();
for (j = 0; j < volume.getSizeY(); j++) {
z = volume.getMinZ();
for (k = 0; k < volume.getSizeZ(); k++) {
try {
blockLine = in.readLine();
if (blockLine != null && !blockLine.equals("")) {
blockSplit = blockLine.split(",");
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
diskBlockType = Integer.parseInt(blockSplit[0]);
diskBlockData = Byte.parseByte(blockSplit[1]);
worldBlock = volume.getWorld().getBlockAt(x, y, z);
worldBlockId = worldBlock.getTypeId();
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
// Signs read
String linesStr = "";
if (blockSplit.length > 2) {
for (int o = 2; o < blockSplit.length; o++) {
linesStr += blockSplit[o];
}
String[] lines = linesStr.split(";;");
// Signs set
// A sign post hanging on a wall south of here will
if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
} else {
worldBlock.setType(Material.getMaterial(diskBlockType));
BlockState state = worldBlock.getState();
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
if (state instanceof Sign) {
Sign sign = (Sign) state;
if (lines != null && sign.getLines() != null) {
if (lines.length > 0) {
sign.setLine(0, lines[0]);
}
if (lines.length > 1) {
sign.setLine(1, lines[1]);
}
if (lines.length > 2) {
sign.setLine(2, lines[2]);
}
if (lines.length > 3) {
sign.setLine(3, lines[3]);
}
sign.update(true);
}
}
}
}
} else if (diskBlockType == Material.CHEST.getId()) {
// Chests read
List<ItemStack> items = null;
if (blockSplit.length > 2) {
String itemsStr = blockSplit[2];
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
}
// Chests set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if (state instanceof Chest) {
Chest chest = (Chest) state;
if (items != null) {
int ii = 0;
chest.getInventory().clear();
for (ItemStack item : items) {
if (item != null) {
chest.getInventory().setItem(ii, item);
ii++;
}
}
chest.update(true);
}
}
} else if (diskBlockType == Material.DISPENSER.getId()) {
// Dispensers read
List<ItemStack> items = null;
if (blockSplit.length > 2) {
String itemsStr = blockSplit[2];
// String itemsStr = lineScanner.nextLine();
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
}
// Dispensers set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if (state instanceof Dispenser) {
Dispenser dispenser = (Dispenser) state;
if (items != null) {
int ii = 0;
dispenser.getInventory().clear();
for (ItemStack item : items) {
if (item != null) {
dispenser.getInventory().setItem(ii, item);
ii++;
}
}
dispenser.update(true);
}
}
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
// Door blocks
if (j - 1 > 0) {
Block blockBelow = world.getBlockAt(x, y - 1, z);
boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId();
// Set current block to glass if block below isn't glass.
// Having a glass block below means the current block is a door top.
if (belowIsGlass) {
// Top door block. Set both it and the block below as door.
blockBelow.setType(Material.getMaterial(diskBlockType));
blockBelow.setData(diskBlockData);
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
} else {
worldBlock.setType(Material.GLASS);
}
}
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
// Change the block itself later on:
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
} else {
// regular block
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
}
noOfResetBlocks++;
}
visitedBlocks++;
}
blockReads++;
}
} catch (Exception e) {
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace();
} finally {
z++;
}
}
if (height129Fix && j == volume.getSizeY() - 1) {
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
// scanner.nextLine();
}
}
y++;
}
x++;
}
if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
}
}
}
} catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} catch (Exception e) {
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
if (in != null) {
// if (scanner != null)
try {
in.close();
in = null;
// scanner.close();
// scanner = null;
} catch (IOException e) {
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
}
return noOfResetBlocks;
}
}

View File

@ -1,459 +0,0 @@
package com.tommytony.war.mapper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Sign;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.War;
import com.tommytony.war.job.DeferredBlockResetsJob;
import com.tommytony.war.job.ZoneVolumeSaveJob;
import com.tommytony.war.utility.DeferredBlockReset;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
/**
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
*
* @author tommytony, Tim Düsterhus
* @package com.tommytony.war.mappers
*/
@SuppressWarnings("deprecation")
public class PreNimitzZoneVolumeMapper {
/**
* Loads the given volume
*
* @param ZoneVolume
* volume Volume to load
* @param String
* zoneName Zone to load the volume from
* @param World
* world The world the zone is located
* @param boolean onlyLoadCorners Should only the corners be loaded
* @return integer Changed blocks
*/
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
int noOfResetBlocks = 0;
boolean failed = false;
if (!blocksFile.exists()) {
// The post 1.6 formatted files haven't been created yet so
// we need to use the old load.
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
// so let's save to the new format as soon as the zone is fully reset.
PreNimitzZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
return noOfResetBlocks;
} else {
// 1.6 file exist, so go ahead with reset
BufferedReader cornersReader = null;
FileInputStream blocksStream = null;
BufferedReader signsReader = null;
BufferedReader invsReader = null;
try {
cornersReader = new BufferedReader(new FileReader(cornersFile));
blocksStream = new FileInputStream(blocksFile);
signsReader = new BufferedReader(new FileReader(signsFile));
invsReader = new BufferedReader(new FileReader(invsFile));
// Get the corners
cornersReader.readLine();
int x1 = Integer.parseInt(cornersReader.readLine());
int y1 = Integer.parseInt(cornersReader.readLine());
int z1 = Integer.parseInt(cornersReader.readLine());
cornersReader.readLine();
int x2 = Integer.parseInt(cornersReader.readLine());
int y2 = Integer.parseInt(cornersReader.readLine());
int z2 = Integer.parseInt(cornersReader.readLine());
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
// Allocate block byte arrays
int noOfBlocks = volume.getSizeX() * volume.getSizeY() * volume.getSizeZ();
byte[] blockBytes = new byte[noOfBlocks * 2]; // one byte for type, one for data
blocksStream.read(blockBytes); // read it all
// Now use the block bytes to reset the world blocks
if (!onlyLoadCorners) {
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
int diskBlockType;
byte diskBlockData;
Block worldBlock;
int worldBlockId;
volume.clearBlocksThatDontFloat();
x = volume.getMinX();
for (i = 0; i < volume.getSizeX(); i++) {
y = volume.getMinY();
for (j = 0; j < volume.getSizeY(); j++) {
z = volume.getMinZ();
for (k = 0; k < volume.getSizeZ(); k++) {
try {
diskBlockType = blockBytes[visitedBlocks * 2];
diskBlockData = blockBytes[visitedBlocks * 2 + 1];
worldBlock = volume.getWorld().getBlockAt(x, y, z);
worldBlockId = worldBlock.getTypeId();
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
// Signs read
String linesStr = signsReader.readLine();
String[] lines = linesStr.split(";;");
// Signs set
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
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
} else {
worldBlock.setType(Material.getMaterial(diskBlockType));
BlockState state = worldBlock.getState();
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
if (state instanceof Sign) {
Sign sign = (Sign) state;
if (lines != null && sign.getLines() != null) {
if (lines.length > 0) {
sign.setLine(0, lines[0]);
}
if (lines.length > 1) {
sign.setLine(1, lines[1]);
}
if (lines.length > 2) {
sign.setLine(2, lines[2]);
}
if (lines.length > 3) {
sign.setLine(3, lines[3]);
}
sign.update(true);
}
}
}
} else if (diskBlockType == Material.CHEST.getId()) {
// Chests read
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
// Chests set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if (state instanceof Chest) {
Chest chest = (Chest) state;
if (items != null) {
int ii = 0;
chest.getInventory().clear();
for (ItemStack item : items) {
if (item != null) {
chest.getInventory().setItem(ii, item);
ii++;
}
}
chest.update(true);
}
}
} else if (diskBlockType == Material.DISPENSER.getId()) {
// Dispensers read
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
// Dispensers set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if (state instanceof Dispenser) {
Dispenser dispenser = (Dispenser) state;
if (items != null) {
int ii = 0;
dispenser.getInventory().clear();
for (ItemStack item : items) {
if (item != null) {
dispenser.getInventory().setItem(ii, item);
ii++;
}
}
dispenser.update(true);
}
}
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
// Door blocks
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
// Change the block itself later on:
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
} else {
// regular block
if (diskBlockType >= 0) {
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
} else {
// The larger than 127 block types were stored as bytes,
// but now -128 to -1 are the result of the bad cast from byte
// to int array above. To make matters worse let's make this
// quick a dirty patch. Anyway everything will break horribly
// once block ids get higher than 255.
worldBlock.setType(Material.getMaterial(256 + diskBlockType));
worldBlock.setData(diskBlockData);
}
}
noOfResetBlocks++;
}
visitedBlocks++;
blockReads++;
} catch (Exception e) {
if (!failed) {
// Don't spam the console
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace();
failed = true;
}
} finally {
z++;
}
}
y++;
}
x++;
}
if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 2);
}
}
} catch (FileNotFoundException e) {
War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
try {
if (cornersReader != null) {
cornersReader.close();
}
if (blocksStream != null) {
blocksStream.close();
}
if (signsReader != null) {
signsReader.close();
}
if (invsReader != null) {
invsReader.close();
}
} catch (IOException e) {
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
return noOfResetBlocks;
}
}
/**
* Saves the given volume
*
* @param Volume
* volume Volume to save
* @param String
* zoneName The warzone the volume is located
* @return integer Number of written blocks
*/
public static int save(Volume volume, String zoneName) {
int noOfSavedBlocks = 0;
if (volume.hasTwoCorners()) {
BufferedWriter cornersWriter = null;
FileOutputStream blocksOutput = null;
BufferedWriter signsWriter = null;
BufferedWriter invsWriter = null;
try {
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
blocksOutput = new FileOutputStream(new File(path + ".blocks"));
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs")));
cornersWriter.write("corner1");
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockZ()));
cornersWriter.newLine();
cornersWriter.write("corner2");
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockZ()));
cornersWriter.newLine();
int x = 0;
int y = 0;
int z = 0;
Block block;
int typeId;
byte data;
BlockState state;
x = volume.getMinX();
for (int i = 0; i < volume.getSizeX(); i++) {
y = volume.getMinY();
for (int j = 0; j < volume.getSizeY(); j++) {
z = volume.getMinZ();
for (int k = 0; k < volume.getSizeZ(); k++) {
try {
block = volume.getWorld().getBlockAt(x, y, z);
typeId = block.getTypeId();
data = block.getData();
state = block.getState();
blocksOutput.write((byte) typeId);
blocksOutput.write(data);
if (state instanceof Sign) {
// Signs
String extra = "";
Sign sign = (Sign) state;
if (sign.getLines() != null) {
for (String line : sign.getLines()) {
extra += line + ";;";
}
signsWriter.write(extra);
signsWriter.newLine();
}
} else if (state instanceof Chest) {
// Chests
Chest chest = (Chest) state;
Inventory inv = chest.getInventory();
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
invsWriter.newLine();
} else if (state instanceof Dispenser) {
// Dispensers
Dispenser dispenser = (Dispenser) state;
Inventory inv = dispenser.getInventory();
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
invsWriter.newLine();
}
noOfSavedBlocks++;
} catch (Exception e) {
War.war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
z++;
}
}
y++;
}
x++;
}
} catch (IOException e) {
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} catch (Exception e) {
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
try {
if (cornersWriter != null) {
cornersWriter.close();
}
if (blocksOutput != null) {
blocksOutput.close();
}
if (signsWriter != null) {
signsWriter.close();
}
if (invsWriter != null) {
invsWriter.close();
}
} catch (IOException e) {
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
}
return noOfSavedBlocks;
}
/**
* Saves the Volume as a background-job
*
* @param ZoneVolme
* volume volume to save
* @param String
* zoneName The zone the volume is located
* @param War
* war Instance of war
* @param long tickDelay delay before beginning the task
*/
private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) {
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay);
}
/**
* Deletes the given volume
*
* @param Volume
* volume volume to delete
* @param War
* war Instance of war
*/
public static void delete(Volume volume) {
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat");
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners");
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks");
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs");
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs");
}
/**
* Deletes a volume file
*
* @param String
* path path of file
* @param War
* war Instance of war
*/
private static void deleteFile(String path) {
File volFile = new File(path);
if (volFile.exists()) {
boolean deletedData = volFile.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
}
}
}
}

View File

@ -1,31 +1,17 @@
package com.tommytony.war.mapper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import com.tommytony.war.War;
import com.tommytony.war.volume.Volume;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.tommytony.war.War;
import com.tommytony.war.volume.Volume;
import java.io.File;
import java.sql.*;
import java.util.logging.Level;
/**
*
@ -49,9 +35,8 @@ public class VolumeMapper {
volume.getName()));
}
if (!databaseFile.exists()) {
legacyLoad(volume, zoneName, world);
save(volume, zoneName);
War.war.getLogger().info("Volume " + volume.getName() + " for warzone " + zoneName + " converted to nimitz format!");
// dropped nimitz compatibility with the MC 1.13 update
War.war.log("Volume " + volume.getName() + " for zone " + zoneName + " not found. Will not attempt converting legacy War version formats.", Level.WARNING);
return;
}
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
@ -93,87 +78,6 @@ public class VolumeMapper {
databaseConnection.close();
}
@SuppressWarnings("deprecation")
public static void legacyLoad(Volume volume, String zoneName, World world) {
BufferedReader in = null;
try {
if (zoneName.equals("")) {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
} else {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
}
String firstLine = in.readLine();
if (firstLine != null && !firstLine.equals("")) {
boolean height129Fix = false;
int x1 = Integer.parseInt(in.readLine());
int y1 = Integer.parseInt(in.readLine());
if (y1 == 128) {
height129Fix = true;
y1 = 127;
}
int z1 = Integer.parseInt(in.readLine());
in.readLine();
int x2 = Integer.parseInt(in.readLine());
int y2 = Integer.parseInt(in.readLine());
if (y2 == 128) {
height129Fix = true;
y2 = 127;
}
int z2 = Integer.parseInt(in.readLine());
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
int blockReads = 0;
for (int i = 0; i < volume.getSizeX(); i++) {
for (int j = 0; j < volume.getSizeY(); j++) {
for (int k = 0; k < volume.getSizeZ(); k++) {
try {
String blockLine = in.readLine();
if (blockLine != null && !blockLine.equals("")) {
String[] blockSplit = blockLine.split(",");
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
int typeID = Integer.parseInt(blockSplit[0]);
byte data = Byte.parseByte(blockSplit[1]);
BlockState dummy = volume.getWorld().getBlockAt(x1 + i, y1 + j, z1 + k).getState();
dummy.setTypeId(typeID);
dummy.setRawData(data);
volume.getBlocks().add(dummy);
}
blockReads++;
}
} catch (Exception e) {
War.war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
if (height129Fix && j == volume.getSizeY() - 1) {
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
}
}
}
}
}
} catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} catch (Exception e) {
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
}
}
public static final int DATABASE_VERSION = 1;
public static void save(Volume volume, String zoneName) throws SQLException {
File databaseFile = new File(War.war.getDataFolder(), String.format(
@ -225,105 +129,6 @@ public class VolumeMapper {
dataStmt.close();
databaseConnection.close();
}
/**
* Parses an inventory string
*
* @param String
* invString string to parse
* @return List<ItemStack> Parsed items
*/
@Deprecated
public static List<ItemStack> readInventoryString(String invString) {
List<ItemStack> items = new ArrayList<ItemStack>();
if (invString != null && !invString.equals("")) {
String[] itemsStrSplit = invString.split(";;");
for (String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";");
if (itemStrSplit.length == 5) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
short durability = (short) Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
// enchantments
String[] enchantmentsSplit = itemStrSplit[4].split("::");
for (String enchantmentStr : enchantmentsSplit) {
if (!enchantmentStr.equals("")) {
String[] enchantmentSplit = enchantmentStr.split(":");
int enchantId = Integer.parseInt(enchantmentSplit[0]);
int level = Integer.parseInt(enchantmentSplit[1]);
War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level);
}
}
items.add(stack);
} else if (itemStrSplit.length == 4) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
short durability = (short) Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else if (itemStrSplit.length == 3) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
short durability = (short) Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else {
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
}
}
}
return items;
}
/**
* Create a string out of a list of items
*
* @param items The list of items
* @return The list as a string
*/
@Deprecated
public static String buildInventoryStringFromItemList(List<ItemStack> items) {
String extra = "";
for (ItemStack item : items) {
if (item != null) {
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
if (item.getData() != null) {
extra += ";" + item.getData().getData();
}
if (item.getEnchantments().keySet().size() > 0) {
String enchantmentsStr = "";
for (Enchantment enchantment : item.getEnchantments().keySet()) {
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
}
extra += ";" + enchantmentsStr;
}
extra += ";;";
}
}
return extra;
}
/**
* Extracts a list of items from and inventory
*
* @param inv The inventory
* @return The inventory as a list
*/
@Deprecated
public static List<ItemStack> getItemListFromInv(Inventory inv) {
int size = inv.getSize();
List<ItemStack> items = new ArrayList<ItemStack>();
for (int invIndex = 0; invIndex < size; invIndex++) {
ItemStack item = inv.getItem(invIndex);
if (item != null && item.getType().getId() != Material.AIR.getId()) {
items.add(item);
}
}
return items;
}
public static void delete(Volume volume) {
File volFile = new File(War.war.getDataFolder(), String.format(

View File

@ -1,459 +0,0 @@
package com.tommytony.war.mapper;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.War;
import com.tommytony.war.config.FlagReturn;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.job.RestoreWarhubJob;
import com.tommytony.war.job.RestoreWarzonesJob;
/**
*
* @author tommytony
*
*/
public class WarTxtMapper {
public static void load() {
load(false);
}
public static void load(boolean convertingToYml) {
(War.war.getDataFolder()).mkdir();
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
try {
warConfig.load();
} catch (IOException e) {
War.war.log("Failed to load war.txt file.", Level.WARNING);
e.printStackTrace();
}
// Create file if need be
boolean newWar = false;
if (!warConfig.containsKey("warzones")) {
newWar = true;
WarTxtMapper.save();
War.war.log("war.txt settings file created.", Level.INFO);
try {
warConfig.load();
} catch (IOException e) {
War.war.log("Failed to reload war.txt file after creating it.", Level.WARNING);
e.printStackTrace();
}
}
// warzones
String warzonesStr = warConfig.getString("warzones");
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(warzonesStr, newWar, convertingToYml);
// make sure warhub job is over before this one ends, because this job will launch conversion (which needs the warhub)
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones, 20) == -1) {
War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
}
// zone makers
String[] makers = warConfig.getString("zoneMakers").split(",");
War.war.getZoneMakerNames().clear();
for (String makerName : makers) {
if (makerName != null && !makerName.equals("")) {
War.war.getZoneMakerNames().add(makerName);
}
}
// command whitelist
String[] whitelist = warConfig.getString("commandWhitelist").split(",");
War.war.getCommandWhitelist().clear();
for (String command : whitelist) {
if (command != null && !command.equals("")) {
War.war.getCommandWhitelist().add(command);
}
}
// defaultLoadout
War.war.getDefaultInventories().clearLoadouts();
String loadoutStr = warConfig.getString("defaultLoadout");
if (loadoutStr != null && !loadoutStr.equals("")) {
War.war.getDefaultInventories().addLoadout("default", new HashMap<Integer, ItemStack>());
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadout("default"));
}
// defaultExtraLoadouts
String extraLoadoutStr = warConfig.getString("defaultExtraLoadouts");
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
for (String nameStr : extraLoadoutsSplit) {
if (nameStr != null && !nameStr.equals("")) {
War.war.getDefaultInventories().addLoadout(nameStr, new HashMap<Integer, ItemStack>());
}
}
for (String extraName : extraLoadoutsSplit) {
if (extraName != null && !extraName.equals("")) {
String loadoutString = warConfig.getString(extraName + "Loadout");
HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadout(extraName);
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
}
}
// maxZones
if (warConfig.keyExists("maxZones")) {
War.war.getWarConfig().put(WarConfig.MAXZONES, warConfig.getInt("maxZones"));
}
// defaultLifePool
if (warConfig.keyExists("defaultLifePool")) {
War.war.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warConfig.getInt("defaultLifePool"));
}
// defaultMonumentHeal
if (warConfig.keyExists("defaultMonumentHeal")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MONUMENTHEAL, warConfig.getInt("defaultMonumentHeal"));
}
// defaultFriendlyFire
if (warConfig.keyExists("defaultFriendlyFire")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.FRIENDLYFIRE, warConfig.getBoolean("defaultFriendlyFire"));
}
// defaultAutoAssignOnly
if (warConfig.keyExists("defaultAutoAssignOnly")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.AUTOASSIGN, warConfig.getBoolean("defaultAutoAssignOnly"));
}
// defaultFlagPointsOnly
if (warConfig.keyExists("defaultFlagPointsOnly")) {
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warConfig.getBoolean("defaultFlagPointsOnly"));
}
// defaultFlagMustBeHome
if (warConfig.keyExists("defaultFlagMustBeHome")) {
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warConfig.getBoolean("defaultFlagMustBeHome"));
}
// defaultTeamCap
if (warConfig.keyExists("defaultTeamCap")) {
War.war.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warConfig.getInt("defaultTeamCap"));
}
// defaultScoreCap
if (warConfig.keyExists("defaultScoreCap")) {
War.war.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warConfig.getInt("defaultScoreCap"));
}
// defaultRespawnTimer
if (warConfig.keyExists("defaultRespawnTimer")) {
War.war.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warConfig.getInt("defaultRespawnTimer"));
}
// pvpInZonesOnly
if (warConfig.keyExists("pvpInZonesOnly")) {
War.war.getWarConfig().put(WarConfig.PVPINZONESONLY, warConfig.getBoolean("pvpInZonesOnly"));
}
// defaultBlockHeads
if (warConfig.keyExists("defaultBlockHeads")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.BLOCKHEADS, warConfig.getBoolean("defaultBlockHeads"));
}
// buildInZonesOnly
if (warConfig.keyExists("buildInZonesOnly")) {
War.war.getWarConfig().put(WarConfig.BUILDINZONESONLY, warConfig.getBoolean("buildInZonesOnly"));
}
// disablePVPMessage
if (warConfig.keyExists("disablePvpMessage")) {
War.war.getWarConfig().put(WarConfig.DISABLEPVPMESSAGE, warConfig.getBoolean("disablePvpMessage"));
}
// disableBuildMessage
if (warConfig.keyExists("disableBuildMessage")) {
War.war.getWarConfig().put(WarConfig.DISABLEBUILDMESSAGE, warConfig.getBoolean("disableBuildMessage"));
}
// tntInZonesOnly
if (warConfig.keyExists("tntInZonesOnly")) {
War.war.getWarConfig().put(WarConfig.TNTINZONESONLY, warConfig.getBoolean("tntInZonesOnly"));
}
// defaultSpawnStyle
String spawnStyle = warConfig.getString("defaultspawnStyle");
if (spawnStyle != null && !spawnStyle.equals("")) {
War.war.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
}
// defaultFlagReturn
String flagReturn = warConfig.getString("defaultFlagReturn");
if (flagReturn != null && !flagReturn.equals("")) {
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
}
// defaultReward
String defaultRewardStr = warConfig.getString("defaultReward");
if (defaultRewardStr != null && !defaultRewardStr.equals("")) {
LoadoutTxtMapper.fromStringToLoadout(defaultRewardStr, War.war.getDefaultInventories().getReward());
}
// defaultUnbreakableZoneBlocks
if (warConfig.keyExists("defaultUnbreakableZoneBlocks")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.UNBREAKABLE, warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
}
// defaultNoCreatures
if (warConfig.keyExists("defaultNoCreatures")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NOCREATURES, warConfig.getBoolean("defaultNoCreatures"));
}
// defaultGlassWalls
if (warConfig.keyExists("defaultGlassWalls")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.GLASSWALLS, warConfig.getBoolean("defaultGlassWalls"));
}
// defaultPvpInZone
if (warConfig.keyExists("defaultPvpInZone")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.PVPINZONE, warConfig.getBoolean("defaultPvpInZone"));
}
// defaultInstaBreak
if (warConfig.keyExists("defaultInstaBreak")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.INSTABREAK, warConfig.getBoolean("defaultInstaBreak"));
}
// defaultNoDrops
if (warConfig.keyExists("defaultNoDrops")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NODROPS, warConfig.getBoolean("defaultNoDrops"));
}
// defaultNoHunger
if (warConfig.keyExists("defaultNoHunger")) {
War.war.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warConfig.getBoolean("defaultNoHunger"));
}
// defaultSaturation
if (warConfig.keyExists("defaultSaturation")) {
War.war.getTeamDefaultConfig().put(TeamConfig.SATURATION, warConfig.getInt("defaultSaturation"));
}
// defaultMinPlayers
if (warConfig.keyExists("defaultMinPlayers")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINPLAYERS, warConfig.getInt("defaultMinPlayers"));
}
// defaultMinTeams
if (warConfig.keyExists("defaultMinTeams")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINTEAMS, warConfig.getInt("defaultMinTeams"));
}
// defaultResetOnEmpty
if (warConfig.keyExists("defaultResetOnEmpty")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONEMPTY, warConfig.getBoolean("defaultResetOnEmpty"));
}
// defaultResetOnLoad
if (warConfig.keyExists("defaultResetOnLoad")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONLOAD, warConfig.getBoolean("defaultResetOnLoad"));
}
// defaultResetOnUnload
if (warConfig.keyExists("defaultResetOnUnload")) {
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONUNLOAD, warConfig.getBoolean("defaultResetOnUnload"));
}
// warhub
String hubStr = warConfig.getString("warhub");
if (hubStr != null && !hubStr.equals("")) {
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(hubStr);
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) {
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
}
}
warConfig.close();
}
public static void save() {
// PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
// String warzonesStr = "";
War.war.log("Saving War with WarTxtMapper", Level.SEVERE);
// // warzones
// for (Warzone zone : War.war.getWarzones()) {
// warzonesStr += zone.getName() + ",";
// }
// warConfig.setString("warzones", warzonesStr);
//
// // zone makers: default is none and it means everyone can use /setzone
// String makersStr = ""; // everyone
// for (String name : War.war.getZoneMakerNames()) {
// makersStr += name + ",";
// }
// warConfig.setString("zoneMakers", makersStr);
//
// // whitelisted commands during a game
// String commandWhitelistStr = ""; // everyone
// for (String command : War.war.getCommandWhitelist()) {
// commandWhitelistStr += command + ",";
// }
// warConfig.setString("commandWhitelist", commandWhitelistStr);
//
// // defaultLoadout
// HashMap<Integer, ItemStack> items = War.war.getDefaultInventories().getLoadouts().get("default");
// warConfig.setString("defaultLoadout", LoadoutTxtMapper.fromLoadoutToString(items));
//
// // defaultExtraLoadouts
// String extraLoadoutsStr = "";
// for (String name : War.war.getDefaultInventories().getLoadouts().keySet()) {
// if (!name.equals("default")) {
// extraLoadoutsStr += name + ",";
//
// HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadouts().get(name);
// warConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
// }
// }
// warConfig.setString("defaultExtraLoadouts", extraLoadoutsStr);
//
// // maxZones
// warConfig.setInt("maxZones", War.war.getWarConfig().getInt(WarConfig.MAXZONES));
//
// // defaultLifepool
// warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool());
//
// // defaultMonumentHeal
// warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal());
//
// // defaultFriendlyFire
// warConfig.setBoolean("defaultFriendlyFire", War.war.isDefaultFriendlyFire());
//
// // defaultAutoAssignOnly
// warConfig.setBoolean("defaultAutoAssignOnly", War.war.isDefaultAutoAssignOnly());
//
// // defaultFlagPointsOnly
// warConfig.setBoolean("defaultFlagPointsOnly", War.war.isDefaultFlagPointsOnly());
//
// // defaultFlagMustBeHome
// warConfig.setBoolean("defaultFlagMustBeHome", War.war.isDefaultFlagMustBeHome());
//
// // defaultTeamCap
// warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap());
//
// // defaultScoreCap
// warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap());
//
// // defaultRespawnTimer
// warConfig.setInt("defaultRespawnTimer", War.war.getDefaultRespawnTimer());
//
// // pvpInZonesOnly
// warConfig.setBoolean("pvpInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY));
//
// // defaultBlockHeads
// warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads());
//
// // buildInZonesOnly
// warConfig.setBoolean("buildInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY));
//
// // disablePVPMessage
// warConfig.setBoolean("disablePvpMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE));
//
// // disableBuildMessage
// warConfig.setBoolean("disableBuildMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE));
//
// // tntInZonesOnly
// warConfig.setBoolean("tntInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY));
//
// // spawnStyle
// warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
//
// // flagReturn
// warConfig.setString("flagReturn", War.war.getDefaultFlagReturn().toString());
//
// // defaultReward
// String defaultRewardStr = "";
// HashMap<Integer, ItemStack> rewardItems = War.war.getDefaultInventories().getReward();
// for (Integer slot : rewardItems.keySet()) {
// ItemStack item = items.get(slot);
// if (item != null) {
// defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
// }
// }
// warConfig.setString("defaultReward", defaultRewardStr);
//
// // defaultUnbreakableZoneBlocks
// warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks());
//
// // defaultNoCreatures
// warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures());
//
// // defaultGlassWalls
// warConfig.setBoolean("defaultGlassWalls", War.war.isDefaultGlassWalls());
//
// // defaultPvpInZone
// warConfig.setBoolean("defaultPvpInZone", War.war.isDefaultPvpInZone());
//
// // defaultInstaBreak
// warConfig.setBoolean("defaultInstaBreak", War.war.isDefaultInstaBreak());
//
// // defaultNoDrops
// warConfig.setBoolean("defaultNoDrops", War.war.isDefaultNoDrops());
//
// // defaultNoHunger
// warConfig.setBoolean("defaultNoHunger", War.war.isDefaultNoHunger());
//
// // defaultSaturation
// warConfig.setInt("defaultSaturation", War.war.getDefaultSaturation());
//
// // defaultMinPlayers
// warConfig.setInt("defaultMinPlayers", War.war.getDefaultMinPlayers());
//
// // defaultMinTeams
// warConfig.setInt("defaultMinTeams", War.war.getDefaultMinTeams());
//
// // defaultResetOnEmpty
// warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty());
//
// // defaultResetOnLoad
// warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad());
//
// // defaultResetOnUnload
// warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload());
//
// // warhub
// String hubStr = "";
// WarHub hub = War.war.getWarHub();
// if (hub != null) {
// String orientationStr = "";
// switch (hub.getOrientation()) {
// case SOUTH:
// orientationStr = "south";
// break;
// case EAST:
// orientationStr = "east";
// break;
// case NORTH:
// orientationStr = "north";
// break;
// case WEST:
// default:
// orientationStr = "west";
// break;
// }
// hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
// + hub.getLocation().getWorld().getName() + "," + orientationStr;
// VolumeMapper.save(hub.getVolume(), "");
// }
// warConfig.setString("warhub", hubStr);
//
// warConfig.save();
// warConfig.close();
}
}

View File

@ -32,9 +32,8 @@ public class WarYmlMapper {
boolean newWar = false;
if (warTxtFile.exists() && !warYmlFile.exists()) {
// Load both War and warzones (with delay) in old format, save War to new format immediatly
WarTxtMapper.load(true);
// Warzones are getting loaded by TxtMapper launched job. That job will in turn save the Warzones to their new format.
// dropped nimitz compatibility with the MC 1.13 update
War.war.log("Failed to load War config file from older version - backwards compatibility was dropped with MC 1.13. Please delete war.txt to continue.", Level.WARNING);
return;
} else if (!warTxtFile.exists() && !warYmlFile.exists()) {
// Save defaults to disk

View File

@ -1,657 +0,0 @@
package com.tommytony.war.mapper;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.FlagReturn;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.structure.Monument;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
import java.util.Arrays;
/**
*
* @author tommytony
*
*/
public class WarzoneTxtMapper {
public static Warzone load(String name, boolean createNewVolume) {
// war.getLogger().info("Loading warzone " + name + " config and blocks...");
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
try {
warzoneConfig.load();
} catch (IOException e) {
War.war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
e.printStackTrace();
}
// world
String worldStr = warzoneConfig.getProperty("world");
World world = null;
if (worldStr == null || worldStr.equals("")) {
world = War.war.getServer().getWorlds().get(0); // default to first world
} else {
world = War.war.getServer().getWorld(worldStr);
}
if (world == null) {
War.war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING);
} else {
// Create the zone
Warzone warzone = new Warzone(world, name);
// Create file if needed
if (!warzoneConfig.containsKey("name")) {
WarzoneTxtMapper.save(warzone, false);
War.war.getLogger().info("Warzone " + name + " config file created.");
try {
warzoneConfig.load();
} catch (IOException e) {
// war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
e.printStackTrace();
}
}
// teleport
String teleportStr = warzoneConfig.getString("teleport");
if (teleportStr != null && !teleportStr.equals("")) {
String[] teleportSplit = teleportStr.split(",");
int teleX = Integer.parseInt(teleportSplit[0]);
int teleY = Integer.parseInt(teleportSplit[1]);
int teleZ = Integer.parseInt(teleportSplit[2]);
int yaw = Integer.parseInt(teleportSplit[3]);
warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0));
}
// ff
if (warzoneConfig.containsKey("friendlyFire")) {
warzone.getWarzoneConfig().put(WarzoneConfig.FRIENDLYFIRE, warzoneConfig.getBoolean("friendlyFire"));
}
// loadout
warzone.getDefaultInventories().clearLoadouts();
String loadoutStr = warzoneConfig.getString("loadout");
if (loadoutStr != null && !loadoutStr.equals("")) {
warzone.getDefaultInventories().setLoadout("default", new HashMap<Integer, ItemStack>());
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadout("default"));
}
// extraLoadouts
String extraLoadoutStr = warzoneConfig.getString("extraLoadouts");
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
for (String nameStr : extraLoadoutsSplit) {
if (nameStr != null && !nameStr.equals("")) {
warzone.getDefaultInventories().setLoadout(nameStr, new HashMap<Integer, ItemStack>());
}
}
for (String extraName : extraLoadoutsSplit) {
if (extraName != null && !extraName.equals("")) {
String loadoutString = warzoneConfig.getString(extraName + "Loadout");
HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadout(extraName);
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
}
}
// authors
if (warzoneConfig.containsKey("author") && !warzoneConfig.getString("author").equals("")) {
for(String authorStr : warzoneConfig.getString("author").split(",")) {
if (!authorStr.equals("")) {
warzone.addAuthor(authorStr);
}
}
}
// life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter)
if (warzoneConfig.containsKey("lifePool")) {
warzone.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warzoneConfig.getInt("lifePool"));
}
// monument heal
if (warzoneConfig.containsKey("monumentHeal")) {
warzone.getWarzoneConfig().put(WarzoneConfig.MONUMENTHEAL, warzoneConfig.getInt("monumentHeal"));
}
// autoAssignOnly
if (warzoneConfig.containsKey("autoAssignOnly")) {
warzone.getWarzoneConfig().put(WarzoneConfig.AUTOASSIGN, warzoneConfig.getBoolean("autoAssignOnly"));
}
// flagPointsOnly
if (warzoneConfig.containsKey("flagPointsOnly")) {
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warzoneConfig.getBoolean("flagPointsOnly"));
}
// flagMustBeHome
if (warzoneConfig.containsKey("flagMustBeHome")) {
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warzoneConfig.getBoolean("flagMustBeHome"));
}
// team cap
if (warzoneConfig.containsKey("teamCap")) {
warzone.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warzoneConfig.getInt("teamCap"));
}
// score cap
if (warzoneConfig.containsKey("scoreCap")) {
warzone.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warzoneConfig.getInt("scoreCap"));
}
// respawn timer
if (warzoneConfig.containsKey("respawnTimer")) {
warzone.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warzoneConfig.getInt("respawnTimer"));
}
// blockHeads
if (warzoneConfig.containsKey("blockHeads")) {
warzone.getWarzoneConfig().put(WarzoneConfig.BLOCKHEADS, warzoneConfig.getBoolean("blockHeads"));
}
// spawnStyle
String spawnStyle = warzoneConfig.getString("spawnStyle");
if (spawnStyle != null && !spawnStyle.equals("")) {
warzone.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
}
// flagReturn
String flagReturn = warzoneConfig.getString("flagReturn");
if (flagReturn != null && !flagReturn.equals("")) {
warzone.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
}
// reward
String rewardStr = warzoneConfig.getString("reward");
if (rewardStr != null && !rewardStr.equals("")) {
HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
LoadoutTxtMapper.fromStringToLoadout(rewardStr, reward);
warzone.getDefaultInventories().setReward(reward);
}
// unbreakableZoneBlocks
if (warzoneConfig.containsKey("unbreakableZoneBlocks")) {
warzone.getWarzoneConfig().put(WarzoneConfig.UNBREAKABLE, warzoneConfig.getBoolean("unbreakableZoneBlocks"));
}
// disabled
if (warzoneConfig.containsKey("disabled")) {
warzone.getWarzoneConfig().put(WarzoneConfig.DISABLED, warzoneConfig.getBoolean("disabled"));
}
// noCreatures
if (warzoneConfig.containsKey("noCreatures")) {
warzone.getWarzoneConfig().put(WarzoneConfig.NOCREATURES, warzoneConfig.getBoolean("noCreatures"));
}
// glassWalls
if (warzoneConfig.containsKey("glassWalls")) {
warzone.getWarzoneConfig().put(WarzoneConfig.GLASSWALLS, warzoneConfig.getBoolean("glassWalls"));
}
// pvpInZone
if (warzoneConfig.containsKey("pvpInZone")) {
warzone.getWarzoneConfig().put(WarzoneConfig.PVPINZONE, warzoneConfig.getBoolean("pvpInZone"));
}
// instaBreak
if (warzoneConfig.containsKey("instaBreak")) {
warzone.getWarzoneConfig().put(WarzoneConfig.INSTABREAK, warzoneConfig.getBoolean("instaBreak"));
}
// noDrops
if (warzoneConfig.containsKey("noDrops")) {
warzone.getWarzoneConfig().put(WarzoneConfig.NODROPS, warzoneConfig.getBoolean("noDrops"));
}
// noHunger
if (warzoneConfig.containsKey("noHunger")) {
warzone.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warzoneConfig.getBoolean("noHunger"));
}
// saturation
if (warzoneConfig.containsKey("saturation")) {
warzone.getTeamDefaultConfig().put(TeamConfig.SATURATION, warzoneConfig.getInt("saturation"));
}
// minPlayers
if (warzoneConfig.containsKey("minPlayers")) {
warzone.getWarzoneConfig().put(WarzoneConfig.MINPLAYERS, warzoneConfig.getInt("minPlayers"));
}
// minTeams
if (warzoneConfig.containsKey("minTeams")) {
warzone.getWarzoneConfig().put(WarzoneConfig.MINTEAMS, warzoneConfig.getInt("minTeams"));
}
// resetOnEmpty
if (warzoneConfig.containsKey("resetOnEmpty")) {
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONEMPTY, warzoneConfig.getBoolean("resetOnEmpty"));
}
// resetOnLoad
if (warzoneConfig.containsKey("resetOnLoad")) {
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONLOAD, warzoneConfig.getBoolean("resetOnLoad"));
}
// resetOnUnload
if (warzoneConfig.containsKey("resetOnUnload")) {
warzone.getWarzoneConfig().put(WarzoneConfig.RESETONUNLOAD, warzoneConfig.getBoolean("resetOnUnload"));
}
// rallyPoint
String rallyPointStr = warzoneConfig.getString("rallyPoint");
if (rallyPointStr != null && !rallyPointStr.equals("")) {
String[] rallyPointStrSplit = rallyPointStr.split(",");
int rpX = Integer.parseInt(rallyPointStrSplit[0]);
int rpY = Integer.parseInt(rallyPointStrSplit[1]);
int rpZ = Integer.parseInt(rallyPointStrSplit[2]);
Location rallyPoint = new Location(world, rpX, rpY, rpZ);
warzone.setRallyPoint(rallyPoint);
}
// monuments
String monumentsStr = warzoneConfig.getString("monuments");
if (monumentsStr != null && !monumentsStr.equals("")) {
String[] monumentsSplit = monumentsStr.split(";");
warzone.getMonuments().clear();
for (String monumentStr : monumentsSplit) {
if (monumentStr != null && !monumentStr.equals("")) {
String[] monumentStrSplit = monumentStr.split(",");
int monumentX = Integer.parseInt(monumentStrSplit[1]);
int monumentY = Integer.parseInt(monumentStrSplit[2]);
int monumentZ = Integer.parseInt(monumentStrSplit[3]);
Monument monument = new Monument(monumentStrSplit[0], warzone, new Location(world, monumentX, monumentY, monumentZ));
warzone.getMonuments().add(monument);
}
}
}
// teams
String teamsStr = warzoneConfig.getString("teams");
if (teamsStr != null && !teamsStr.equals("")) {
String[] teamsSplit = teamsStr.split(";");
warzone.getTeams().clear();
for (String teamStr : teamsSplit) {
if (teamStr != null && !teamStr.equals("")) {
String[] teamStrSplit = teamStr.split(",");
int teamX = Integer.parseInt(teamStrSplit[1]);
int teamY = Integer.parseInt(teamStrSplit[2]);
int teamZ = Integer.parseInt(teamStrSplit[3]);
Location teamLocation = new Location(world, teamX, teamY, teamZ);
if (teamStrSplit.length > 4) {
int yaw = Integer.parseInt(teamStrSplit[4]);
teamLocation.setYaw(yaw);
}
File original = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamStrSplit[0] + ".dat");
File modified = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamStrSplit[0] + "0.dat");
try {
original.renameTo(modified);
} catch (Exception ignored) {
}
Team team = new Team(teamStrSplit[0], TeamKind.teamKindFromString(teamStrSplit[0]), Arrays.asList(teamLocation), warzone);
team.setRemainingLives(warzone.getTeamDefaultConfig().resolveInt(TeamConfig.LIFEPOOL));
warzone.getTeams().add(team);
}
}
}
// teamFlags
String teamFlagsStr = warzoneConfig.getString("teamFlags");
if (teamFlagsStr != null && !teamFlagsStr.equals("")) {
String[] teamFlagsSplit = teamFlagsStr.split(";");
for (String teamFlagStr : teamFlagsSplit) {
if (teamFlagStr != null && !teamFlagStr.equals("")) {
String[] teamFlagStrSplit = teamFlagStr.split(",");
Team team = warzone.getTeamByKind(TeamKind.teamKindFromString(teamFlagStrSplit[0]));
if (team != null) {
int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]);
int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]);
int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]);
Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ);
if (teamFlagStrSplit.length > 4) {
int yaw = Integer.parseInt(teamFlagStrSplit[4]);
teamFlagLocation.setYaw(yaw);
}
team.setTeamFlag(teamFlagLocation); // this may screw things up
}
}
}
}
// lobby
String lobbyStr = warzoneConfig.getString("lobby");
warzoneConfig.close();
if (createNewVolume) {
ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
warzone.setVolume(zoneVolume);
}
// monument blocks
for (Monument monument : warzone.getMonuments()) {
try {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
}
}
// team spawn blocks
for (Team team : warzone.getTeams()) {
for (Location spawnLocation : team.getTeamSpawns()) {
try {
team.setSpawnVolume(spawnLocation, VolumeMapper.loadVolume(team.getName() + "0", warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
}
}
if (team.getTeamFlag() != null) {
try {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
}
}
}
// lobby
BlockFace lobbyFace = null;
if (lobbyStr != null && !lobbyStr.equals("")) {
String[] lobbyStrSplit = lobbyStr.split(",");
if (lobbyStrSplit.length > 0) {
// lobby orientation
if (lobbyStrSplit[0].equals("south")) {
lobbyFace = Direction.SOUTH();
} else if (lobbyStrSplit[0].equals("east")) {
lobbyFace = Direction.EAST();
} else if (lobbyStrSplit[0].equals("north")) {
lobbyFace = Direction.NORTH();
} else if (lobbyStrSplit[0].equals("west")) {
lobbyFace = Direction.WEST();
}
// lobby world
World lobbyWorld = world; // by default, warzone world
if (lobbyStrSplit.length > 1) {
World strWorld = War.war.getServer().getWorld(lobbyStrSplit[1]);
if (strWorld != null) {
lobbyWorld = strWorld;
}
}
// create the lobby
Volume lobbyVolume = null;
try {
lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
} catch (SQLException e) {
// if the zone is this old is there any reason the lobby should be nimitz format
War.war.getLogger().log(Level.WARNING, "Failed to load lobby for a really old warzone", e);
}
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
warzone.setLobby(lobby);
}
}
return warzone;
}
return null;
}
public static void save(Warzone warzone, boolean saveAllBlocks) {
War.war.log("Saving War with WarzoneTxtMapper", Level.SEVERE);
// (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
// PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
// // war.getLogger().info("Saving warzone " + warzone.getName() + "...");
//
// // name
// warzoneConfig.setString("name", warzone.getName());
//
// // world
// warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now
//
// // teleport
// String teleportStr = "";
// Location tele = warzone.getTeleport();
// if (tele != null) {
// int intYaw = 0;
// if (tele.getYaw() >= 0) {
// intYaw = (int) (tele.getYaw() % 360);
// } else {
// intYaw = (int) (360 + (tele.getYaw() % 360));
// }
// teleportStr = tele.getBlockX() + "," + tele.getBlockY() + "," + tele.getBlockZ() + "," + intYaw;
// }
// warzoneConfig.setString("teleport", teleportStr);
//
// // teams
// String teamsStr = "";
// List<Team> teams = warzone.getTeams();
// for (Team team : teams) {
// Location spawn = team.getTeamSpawn();
// int intYaw = 0;
// if (spawn.getYaw() >= 0) {
// intYaw = (int) (spawn.getYaw() % 360);
// } else {
// intYaw = (int) (360 + (spawn.getYaw() % 360));
// }
// teamsStr += team.getName() + "," + spawn.getBlockX() + "," + spawn.getBlockY() + "," + spawn.getBlockZ() + "," + intYaw + ";";
// }
// warzoneConfig.setString("teams", teamsStr);
//
// // team flags
// String teamFlagsStr = "";;
// for (Team team : teams) {
// if (team.getFlagVolume() != null) {
// Location flag = team.getTeamFlag();
// int intYaw = 0;
// if (flag.getYaw() >= 0) {
// intYaw = (int) (flag.getYaw() % 360);
// } else {
// intYaw = (int) (360 + (flag.getYaw() % 360));
// }
// teamFlagsStr += team.getName() + "," + flag.getBlockX() + "," + flag.getBlockY() + "," + flag.getBlockZ() + "," + intYaw + ";";
// }
// }
// warzoneConfig.setString("teamFlags", teamFlagsStr);
//
// // ff
// warzoneConfig.setBoolean("friendlyFire", warzone.getFriendlyFire());
//
// // loadout
// HashMap<Integer, ItemStack> items = warzone.getDefaultInventories().getLoadouts().get("default");
// warzoneConfig.setString("loadout", LoadoutTxtMapper.fromLoadoutToString(items));
//
// // defaultExtraLoadouts
// String extraLoadoutsStr = "";
// for (String name : warzone.getDefaultInventories().getLoadouts().keySet()) {
// if (!name.equals("default")) {
// extraLoadoutsStr += name + ",";
//
// HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(name);
// warzoneConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
// }
// }
// warzoneConfig.setString("extraLoadouts", extraLoadoutsStr);
//
// // authors
// warzoneConfig.setString("author", warzone.getAuthorsString());
//
// // life pool
// warzoneConfig.setInt("lifePool", warzone.getLifePool());
//
// // monument heal
// warzoneConfig.setInt("monumentHeal", warzone.getMonumentHeal());
//
// // autoAssignOnly
// warzoneConfig.setBoolean("autoAssignOnly", warzone.isAutoAssignOnly());
//
// // flagPointsOnly
// warzoneConfig.setBoolean("flagPointsOnly", warzone.isFlagPointsOnly());
//
// // flagMustBeHome
// warzoneConfig.setBoolean("flagMustBeHome", warzone.isFlagMustBeHome());
//
// // team cap
// warzoneConfig.setInt("teamCap", warzone.getTeamCap());
//
// // score cap
// warzoneConfig.setInt("scoreCap", warzone.getScoreCap());
//
// // respawn timer
// warzoneConfig.setInt("respawnTimer", warzone.getRespawnTimer());
//
// // blockHeads
// warzoneConfig.setBoolean("blockHeads", warzone.isBlockHeads());
//
// // spawnStyle
// warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle().toString());
//
// // flagReturn
// warzoneConfig.setString("flagReturn", warzone.getFlagReturn().toString());
//
// // reward
// HashMap<Integer, ItemStack> rewardItems = warzone.getDefaultInventories().getReward();
// warzoneConfig.setString("reward", LoadoutTxtMapper.fromLoadoutToString(rewardItems));
//
// // unbreakableZoneBlocks
// warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks());
//
// // disabled
// warzoneConfig.setBoolean("disabled", warzone.isDisabled());
//
// // noCreatures
// warzoneConfig.setBoolean("noCreatures", warzone.isNoCreatures());
//
// // glassWalls
// warzoneConfig.setBoolean("glassWalls", warzone.isGlassWalls());
//
// // pvpInZone
// warzoneConfig.setBoolean("pvpInZone", warzone.isPvpInZone());
//
// // instaBreak
// warzoneConfig.setBoolean("instaBreak", warzone.isInstaBreak());
//
// // noDrops
// warzoneConfig.setBoolean("noDrops", warzone.isNoDrops());
//
// // noHunger
// warzoneConfig.setBoolean("noHunger", warzone.isNoHunger());
//
// // saturation
// warzoneConfig.setInt("saturation", warzone.getSaturation());
//
// // minPlayers
// warzoneConfig.setInt("minPlayers", warzone.getMinPlayers());
//
// // minTeams
// warzoneConfig.setInt("minTeams", warzone.getMinTeams());
//
// // resetOnEmpty
// warzoneConfig.setBoolean("resetOnEmpty", warzone.isResetOnEmpty());
//
// // resetOnLoad
// warzoneConfig.setBoolean("resetOnLoad", warzone.isResetOnLoad());
//
// // resetOnUnload
// warzoneConfig.setBoolean("resetOnUnload", warzone.isResetOnUnload());
//
// // rallyPoint
// String rpStr = "";
// Location rp = warzone.getRallyPoint();
// if (rp != null) {
// rpStr = rp.getBlockX() + "," + rp.getBlockY() + "," + rp.getBlockZ();
// }
// warzoneConfig.setString("rallyPoint", rpStr);
//
// // defaultDropLootOnDeath
// // warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());
//
// // monuments
// String monumentsStr = "";
// List<Monument> monuments = warzone.getMonuments();
// for (Monument monument : monuments) {
// Location monumentLoc = monument.getLocation();
// monumentsStr += monument.getName() + "," + monumentLoc.getBlockX() + "," + monumentLoc.getBlockY() + "," + monumentLoc.getBlockZ() + ";";
// }
// warzoneConfig.setString("monuments", monumentsStr);
//
// // lobby
// String lobbyStr = "";
// if (warzone.getLobby() != null) {
// if (Direction.SOUTH() == warzone.getLobby().getWall()) {
// lobbyStr = "south";
// } else if (Direction.EAST() == warzone.getLobby().getWall()) {
// lobbyStr = "east";
// } else if (Direction.NORTH() == warzone.getLobby().getWall()) {
// lobbyStr = "north";
// } else if (Direction.WEST() == warzone.getLobby().getWall()) {
// lobbyStr = "west";
// }
// }
// warzoneConfig.setString("lobby", lobbyStr + "," + warzone.getLobby().getVolume().getWorld().getName());
//
// warzoneConfig.save();
// warzoneConfig.close();
//
// // monument blocks
// for (Monument monument : monuments) {
// VolumeMapper.save(monument.getVolume(), warzone.getName());
// }
//
// // team spawn & flag blocks
// for (Team team : teams) {
// VolumeMapper.save(team.getSpawnVolume(), warzone.getName());
// if (team.getFlagVolume() != null) {
// VolumeMapper.save(team.getFlagVolume(), warzone.getName());
// }
// }
//
// if (warzone.getLobby() != null) {
// VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
// }
}
public static void delete(String name) {
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
File[] files = zoneFolder.listFiles();
for (File file : files) {
boolean deletedData = file.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + file.getName(), Level.WARNING);
}
}
boolean deletedData = zoneFolder.delete();
if (!deletedData) {
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
}
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
deletedData = zoneFile.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
}
}
}

View File

@ -30,18 +30,15 @@ import com.tommytony.war.volume.ZoneVolume;
public class WarzoneYmlMapper {
@SuppressWarnings("deprecation")
public static Warzone load(String name) { // removed createNewVolume, as it did nothing
File warzoneTxtFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
File warzoneYmlFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
// Convert from TXT to YML if needed
if (warzoneTxtFile.exists() && !warzoneYmlFile.exists()) {
// Since we're converting, WarTxtMapper didn't load the warzones.
// We need to load the old-text-format-Warzone into memory.
Warzone zoneToConvert = WarzoneTxtMapper.load(name, false);
WarzoneYmlMapper.save(zoneToConvert);
War.war.log("Converted warzone-" + name + ".txt to warzone-" + name + ".yml", Level.INFO);
// dropped nimitz compatibility with the MC 1.13 update
War.war.log("Failed to load Warzone " + name + " - backwards compatibility was dropped with MC 1.13. Please delete this zone to continue.", Level.WARNING);
return null;
}
if (!warzoneYmlFile.exists()) {
@ -385,50 +382,18 @@ public class WarzoneYmlMapper {
if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.floor")) {
warzone.getLobbyMaterials().setFloorBlock(
warzoneRootSection.getItemStack(lobbyPrefix + "materials.floor"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(lobbyPrefix + "materials.floor");
if (floorMaterialSection != null) {
warzone.getLobbyMaterials().setFloorBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.outline")) {
warzone.getLobbyMaterials().setOutlineBlock(
warzoneRootSection.getItemStack(lobbyPrefix + "materials.outline"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(lobbyPrefix + "materials.outline");
if (floorMaterialSection != null) {
warzone.getLobbyMaterials().setOutlineBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.gate")) {
warzone.getLobbyMaterials().setGateBlock(
warzoneRootSection.getItemStack(lobbyPrefix + "materials.gate"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(lobbyPrefix + "materials.gate");
if (floorMaterialSection != null) {
warzone.getLobbyMaterials().setGateBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.light")) {
warzone.getLobbyMaterials().setLightBlock(
warzoneRootSection.getItemStack(lobbyPrefix + "materials.light"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(lobbyPrefix + "materials.light");
if (floorMaterialSection != null) {
warzone.getLobbyMaterials().setLightBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
// lobby world
@ -449,38 +414,14 @@ public class WarzoneYmlMapper {
if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.main")) {
warzone.getWarzoneMaterials().setMainBlock(
warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.main"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(zoneInfoPrefix + "materials.main");
if (floorMaterialSection != null) {
warzone.getWarzoneMaterials().setMainBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.stand")) {
warzone.getWarzoneMaterials().setStandBlock(
warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.stand"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(zoneInfoPrefix + "materials.stand");
if (floorMaterialSection != null) {
warzone.getWarzoneMaterials().setStandBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.light")) {
warzone.getWarzoneMaterials().setLightBlock(
warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.light"));
} else {
ConfigurationSection floorMaterialSection = warzoneRootSection
.getConfigurationSection(zoneInfoPrefix + "materials.light");
if (floorMaterialSection != null) {
warzone.getWarzoneMaterials().setLightBlock(
new ItemStack(floorMaterialSection.getInt("id"), 1,
(short) floorMaterialSection.getInt("data")));
}
}
try {
connection.close();

View File

@ -56,10 +56,8 @@ public class ZoneVolumeMapper {
public static Connection getZoneConnection(ZoneVolume volume, String zoneName, World world) throws SQLException {
File databaseFile = new File(War.war.getDataFolder(), String.format("/dat/warzone-%s/volume-%s.sl3", zoneName, volume.getName()));
if (!databaseFile.exists()) {
// Convert warzone to nimitz file format.
PreNimitzZoneVolumeMapper.load(volume, zoneName, world, false);
ZoneVolumeMapper.save(volume, zoneName);
War.war.log("Warzone " + zoneName + " converted to nimitz format!", Level.INFO);
// dropped nimitz compatibility with the MC 1.13 update
War.war.log("Warzone " + zoneName + " not found - creating new file. Will not attempt converting legacy War version formats.", Level.WARNING);
}
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement();
@ -314,7 +312,7 @@ public class ZoneVolumeMapper {
case SUNSET: // Use same as 4x3
// 4x3
case DONKEYKONG:
case DONKEY_KONG:
case SKELETON:
if(facing == BlockFace.WEST)
return loc.getBlock().getLocation().add(0, 0, -1);
@ -335,7 +333,7 @@ public class ZoneVolumeMapper {
case FIGHTERS: // Use same as 4x4
// 4x4
case BURNINGSKULL:
case BURNING_SKULL:
case PIGSCENE:
case POINTER:
if(facing == BlockFace.WEST)
@ -540,6 +538,7 @@ public class ZoneVolumeMapper {
// TODO upgrade to store owning player by UUID
dataStmt.setString(6, String.format("%s\n%s\n%s",
((Skull) block.getState()).hasOwner() ? ((Skull) block.getState()).getOwningPlayer().getName() : "",
// TODO remove deprecation when Spigot updates their docs about the replacement
((Skull) block.getState()).getSkullType().toString(),
((Skull) block.getState()).getRotation().toString()));
} else if (state instanceof CommandBlock) {
@ -547,7 +546,9 @@ public class ZoneVolumeMapper {
+ "\n" + ((CommandBlock) block.getState()).getCommand());
} else if (state instanceof CreatureSpawner) {
dataStmt.setString(6, ((CreatureSpawner) block.getState()).getSpawnedType().toString());
}
} else {
dataStmt.setString(6, "");
}
dataStmt.addBatch();

View File

@ -97,7 +97,7 @@ public class Cake {
current.setType(this.warzone.getWarzoneMaterials().getStandBlock().getType());
current.setData(this.warzone.getWarzoneMaterials().getStandBlock().getData());
current.update(true);
this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(Material.CAKE_BLOCK);
this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(Material.CAKE);
}
public boolean isCakeBlock(Location otherLocation) {

View File

@ -106,7 +106,6 @@ public class CapturePoint {
1 + Math.round(Math.cos(Math.toRadians(location.getYaw()))));
BlockState state = origin.clone().add(dir).getBlock().getState();
state.setType(controller.getMaterial());
state.setData(controller.getBlockData());
state.update(true);
}
}

View File

@ -214,7 +214,7 @@ public class WarHub {
}
// War hub sign
locationBlock.getRelative(front, 2).setType(Material.SIGN_POST);
locationBlock.getRelative(front, 2).setType(Material.SIGN);
String[] lines = War.war.getString("sign.warhub").split("\n");
org.bukkit.block.Sign locationBlockFront = (org.bukkit.block.Sign) locationBlock.getRelative(front, 2).getState();
for (int i = 0; i < 4; i++) {

View File

@ -368,7 +368,7 @@ public class ZoneLobby {
// set zone sign
Block zoneSignBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 4);
zoneSignBlock.setType(Material.SIGN_POST);
zoneSignBlock.setType(Material.SIGN);
org.bukkit.block.Sign block = (org.bukkit.block.Sign) zoneSignBlock.getState();
org.bukkit.material.Sign data = (Sign) block.getData();
data.setFacingDirection(this.wall);
@ -552,10 +552,7 @@ public class ZoneLobby {
}
private void setBlock(Block block, TeamKind kind) {
BlockState blockState = block.getState();
blockState.setType(kind.getBlockHead().getType());
blockState.setData(kind.getBlockHead().getData());
blockState.update(true);
block.setType(kind.getMaterial());
}
private void placeAutoAssignGate() {

View File

@ -29,15 +29,15 @@ public class ZoneWallGuard {
public static final Material[] glassifyBlocks = {
Material.AIR,
Material.WATER,
Material.LONG_GRASS,
Material.TALL_GRASS,
Material.VINE,
Material.WATER_LILY,
Material.YELLOW_FLOWER,
Material.RED_ROSE,
Material.LILY_PAD,
Material.DANDELION_YELLOW,
Material.ROSE_RED,
Material.RED_MUSHROOM,
Material.BROWN_MUSHROOM,
Material.DEAD_BUSH,
Material.SUGAR_CANE_BLOCK
Material.SUGAR_CANE
};
public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) {

View File

@ -47,7 +47,7 @@ class EditLoadoutListUI extends ChestUI {
ItemStack item;
ItemMeta meta;
int i = 0;
item = new ItemStack(Material.GOLD_SPADE, 1);
item = new ItemStack(Material.GOLDEN_SHOVEL, 1);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "Create new loadout");
item.setItemMeta(meta);

View File

@ -1,14 +1,11 @@
package com.tommytony.war.ui;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.command.ZoneSetter;
import com.tommytony.war.utility.Compat;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@ -22,7 +19,7 @@ public class EditOrCreateZoneUI extends ChestUI {
@Override
public void build(final Player player, Inventory inv) {
int i = 0;
ItemStack item = new ItemStack(Material.WOOD_AXE, 1);
ItemStack item = new ItemStack(Material.WOODEN_AXE, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.YELLOW + "Create Warzone");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to create a " + ChatColor.AQUA + "Warzone"));
@ -34,18 +31,17 @@ public class EditOrCreateZoneUI extends ChestUI {
player.sendTitle("", ChatColor.RED + "This feature requires WorldEdit.", 10, 20, 10);
return;
}
player.getInventory().addItem(new ItemStack(Material.WOOD_AXE, 1));
player.getInventory().addItem(new ItemStack(Material.WOODEN_AXE, 1));
War.war.getUIManager().getPlayerMessage(player, "Select region for zone using WorldEdit and then type a name:", new StringRunnable() {
@Override
public void run() {
WorldEditPlugin worldEdit = (WorldEditPlugin) War.war.getServer().getPluginManager().getPlugin("WorldEdit");
Selection selection = worldEdit.getSelection(player);
if (selection != null && selection instanceof CuboidSelection) {
Location min = selection.getMinimumPoint();
Location max = selection.getMaximumPoint();
Compat.BlockPair pair = Compat.getWorldEditSelection(player);
if (pair != null) {
ZoneSetter setter = new ZoneSetter(player, this.getValue());
setter.placeCorner1(min.getBlock());
setter.placeCorner2(max.getBlock());
setter.placeCorner1(pair.getBlock1());
setter.placeCorner2(pair.getBlock2());
} else {
War.war.badMsg(player, "Invalid selection. Creation cancelled.");
}
}
});
@ -55,7 +51,7 @@ public class EditOrCreateZoneUI extends ChestUI {
if (!War.war.isWarAdmin(player) && !zone.isAuthor(player)) {
continue;
}
item = new ItemStack(Material.BOOK_AND_QUILL);
item = new ItemStack(Material.WRITABLE_BOOK);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + zone.getName());
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to edit"));

View File

@ -29,7 +29,7 @@ class EditTeamUI extends ChestUI {
ItemStack item;
ItemMeta meta;
int i = 0;
item = new ItemStack(Material.GOLD_SPADE, 1);
item = new ItemStack(Material.GOLDEN_SHOVEL, 1);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "Add additional spawn");
item.setItemMeta(meta);
@ -77,7 +77,7 @@ class EditTeamUI extends ChestUI {
War.war.msg(player, "Team " + team.getName() + " removed.");
}
});
item = new ItemStack(Material.SNOW_BALL);
item = new ItemStack(Material.SNOWBALL);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "Restore Defaults");
item.setItemMeta(meta);

View File

@ -28,7 +28,7 @@ public class EditZoneConfigUI extends ChestUI {
int i = 0;
i = UIConfigHelper.addWarzoneConfigOptions(this, player, inv, zone.getWarzoneConfig(), zone, i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
item = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);
@ -39,7 +39,7 @@ public class EditZoneConfigUI extends ChestUI {
}
});
UIConfigHelper.addTeamConfigOptions(this, player, inv, zone.getTeamDefaultConfig(), null, zone, i);
item = new ItemStack(Material.SNOW_BALL);
item = new ItemStack(Material.SNOWBALL);
meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "Restore Defaults");
item.setItemMeta(meta);

View File

@ -26,12 +26,14 @@ public class JoinZoneUI extends ChestUI {
ChatColor.DARK_GRAY + "Warzone doors located here"));
item.setItemMeta(meta);
int i = 0;
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.teleport(War.war.getWarHub().getLocation());
}
});
if (War.war.getWarHub() != null) {
this.addItem(inv, i++, item, new Runnable() {
@Override
public void run() {
player.teleport(War.war.getWarHub().getLocation());
}
});
}
for (final Warzone zone : War.war.getEnabledWarzones()) {
item = new ItemStack(Material.ENDER_PEARL);
meta = item.getItemMeta();

View File

@ -41,7 +41,7 @@ public class UIConfigHelper {
}
if (option.getConfigType() == Boolean.class) {
status += config.resolveBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.resolveBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
item = new ItemStack(config.resolveBoolean(option) ? Material.LIME_DYE : Material.GRAY_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -55,7 +55,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.resolveValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
item = new ItemStack(Material.PURPLE_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -80,7 +80,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == FlagReturn.class) {
status += ChatColor.YELLOW + config.resolveValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
item = new ItemStack(Material.PINK_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -103,7 +103,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == TeamSpawnStyle.class) {
status += ChatColor.YELLOW + config.resolveValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
item = new ItemStack(Material.PINK_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -174,7 +174,7 @@ public class UIConfigHelper {
}
if (option.getConfigType() == Boolean.class) {
status += config.getBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.getBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
item = new ItemStack(config.getBoolean(option) ? Material.LIME_DYE : Material.GRAY_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -188,7 +188,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.getValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
item = new ItemStack(Material.PURPLE_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -213,7 +213,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == ScoreboardType.class) {
status += ChatColor.YELLOW + config.getValue(option).toString();
item = new Dye(DyeColor.PINK).toItemStack(1);
item = new ItemStack(Material.PINK_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).add(inheritance).build());
@ -277,7 +277,7 @@ public class UIConfigHelper {
}
if (option.getConfigType() == Boolean.class) {
status += config.getBoolean(option) ? ChatColor.GREEN + "true" : ChatColor.DARK_GRAY + "false";
item = new Dye(config.getBoolean(option) ? DyeColor.LIME : DyeColor.GRAY).toItemStack(1);
item = new ItemStack(config.getBoolean(option) ? Material.LIME_DYE : Material.GRAY_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).build());
@ -291,7 +291,7 @@ public class UIConfigHelper {
});
} else if (option.getConfigType() == Integer.class || option.getConfigType() == Double.class || option.getConfigType() == String.class) {
status += ChatColor.LIGHT_PURPLE + config.getValue(option).toString();
item = new Dye(DyeColor.PURPLE).toItemStack(1);
item = new ItemStack(Material.PURPLE_DYE, 1);
meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(new ImmutableList.Builder<String>().add(desc).add(status).build());

View File

@ -19,7 +19,7 @@ public class WarAdminUI extends ChestUI {
int i = 0;
i = UIConfigHelper.addWarConfigOptions(this, player, inv, War.war.getWarConfig(), i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
item = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Warzone Default Config >>>>");
item.setItemMeta(meta);
@ -30,7 +30,7 @@ public class WarAdminUI extends ChestUI {
}
});
i = UIConfigHelper.addWarzoneConfigOptions(this, player, inv, War.war.getWarzoneDefaultConfig(), null, i);
item = new ItemStack(Material.STAINED_GLASS_PANE);
item = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);

View File

@ -47,7 +47,7 @@ public class WarUI extends ChestUI {
}
private ItemStack getCreateWarzoneItem() {
ItemStack item = new ItemStack(Material.WOOD_AXE, 1);
ItemStack item = new ItemStack(Material.WOODEN_AXE, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Create Warzone");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to create, or edit a " + ChatColor.AQUA + "Warzone" + ChatColor.GRAY + "."));
@ -66,7 +66,7 @@ public class WarUI extends ChestUI {
}
private ItemStack getWarAdminItem() {
ItemStack item = new ItemStack(Material.EYE_OF_ENDER, 1);
ItemStack item = new ItemStack(Material.ENDER_EYE, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Manage War");
meta.setLore(ImmutableList.of(ChatColor.GRAY + "Click to display " + ChatColor.DARK_RED + "Admin" + ChatColor.GRAY + " access panel",

View File

@ -0,0 +1,69 @@
package com.tommytony.war.utility;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.tommytony.war.War;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Simple fixes to account for removed Bukkit functionality
*/
public class Compat {
public static ItemStack createDamagedIS(Material mat, int amount, int damage) {
ItemStack is = new ItemStack(mat, amount);
ItemMeta meta = is.getItemMeta();
((Damageable) meta).setDamage(damage); // hope this works
is.setItemMeta(meta);
return is;
}
public static class BlockPair {
final Block block1;
final Block block2;
BlockPair(Block block1, Block block2) {
this.block1 = block1;
this.block2 = block2;
}
public Block getBlock1() {
return block1;
}
public Block getBlock2() {
return block2;
}
}
public static BlockPair getWorldEditSelection(Player player) {
if (!War.war.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
return null;
}
BukkitPlayer wp = BukkitAdapter.adapt(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wp);
try {
Region selection = session.getSelection(wp.getWorld());
if (selection instanceof CuboidRegion) {
return new BlockPair(
player.getWorld().getBlockAt(selection.getMinimumPoint().getBlockX(), selection.getMinimumPoint().getBlockY(), selection.getMinimumPoint().getBlockZ()),
player.getWorld().getBlockAt(selection.getMaximumPoint().getBlockX(), selection.getMaximumPoint().getBlockY(), selection.getMaximumPoint().getBlockZ())
);
}
return null;
} catch (IncompleteRegionException e) {
return null;
}
}
}

View File

@ -261,63 +261,6 @@ public class Volume {
}
}
public void replaceMaterial(Material original, Material replacement) {
Validate.isTrue(this.hasTwoCorners(), "Incomplete volume");
for (int x = this.getMinX(); x <= this.getMaxX(); x++) {
for (int y = this.getMinY(); y <= this.getMaxY(); y++) {
for (int z = this.getMinZ(); z <= this.getMaxZ(); z++) {
if (this.getWorld().getBlockAt(x, y, z).getType() == original) {
this.getWorld().getBlockAt(x, y, z).setType(replacement);
}
}
}
}
}
public void replaceMaterials(Material[] materials, Material replacement) {
for (Material mat: materials) {
this.replaceMaterial(mat, replacement);
}
}
public void clearBlocksThatDontFloat() {
Validate.isTrue(this.hasTwoCorners(), "Incomplete volume");
for (int x = this.getMinX(); x <= this.getMaxX(); x++) {
for (int y = this.getMinY(); y <= this.getMaxY(); y++) {
for (int z = this.getMinZ(); z <= this.getMaxZ(); z++) {
switch (this.getWorld().getBlockAt(x, y, z).getType()) {
case SIGN_POST:
case WALL_SIGN:
case IRON_DOOR:
case WOOD_DOOR:
case LADDER:
case YELLOW_FLOWER:
case RED_ROSE:
case RED_MUSHROOM:
case BROWN_MUSHROOM:
case SAPLING:
case TORCH:
case RAILS:
case STONE_BUTTON:
case STONE_PLATE:
case WOOD_PLATE:
case LEVER:
case REDSTONE:
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
case CACTUS:
case SNOW:
case ICE:
this.getWorld().getBlockAt(x, y, z)
.setType(Material.AIR);
default:
break;
}
}
}
}
}
@Override
public void finalize() {
this.blocks.clear();

View File

@ -1,5 +1,6 @@
name: ${project.name}
version: ${project.version}
api-version: 1.13
description: ${project.description}
author: tommytony
website: ${project.url}