Fix some deprecated stuff

This commit is contained in:
Connor Monahan 2018-11-19 00:43:50 -06:00
parent 69a148fc6a
commit 4e83ffada1
12 changed files with 86 additions and 121 deletions

View File

@ -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;
@ -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_SHOVEL, 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);

View File

@ -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

@ -12,21 +12,21 @@ import org.getspout.spoutapi.gui.Color;
public enum TeamKind {
WHITE (DyeColor.WHITE, Material.WHITE_WOOL, ChatColor.WHITE, 450),
ORANGE (DyeColor.ORANGE, Material.WHITE_WOOL, ChatColor.GOLD, 51),
MAGENTA (DyeColor.MAGENTA, Material.WHITE_WOOL, ChatColor.LIGHT_PURPLE, 353),
BLUE (DyeColor.LIGHT_BLUE, Material.WHITE_WOOL, ChatColor.BLUE, 23),
GOLD (DyeColor.YELLOW, Material.WHITE_WOOL, ChatColor.YELLOW, 403), // yellow = gold
GREEN (DyeColor.LIME, Material.WHITE_WOOL, ChatColor.GREEN, 612),
PINK (DyeColor.PINK, Material.WHITE_WOOL, ChatColor.LIGHT_PURPLE, 929),
GRAY (DyeColor.GRAY, Material.WHITE_WOOL, ChatColor.DARK_GRAY, 600),
IRON (DyeColor.GRAY, Material.WHITE_WOOL, ChatColor.GRAY, 154), // lightgrey = iron
DIAMOND (DyeColor.CYAN, Material.WHITE_WOOL, ChatColor.DARK_AQUA, 738), // cyan = diamond
PURPLE (DyeColor.PURPLE, Material.WHITE_WOOL, ChatColor.DARK_PURPLE, 153),
NAVY (DyeColor.BLUE, Material.WHITE_WOOL, ChatColor.DARK_BLUE, 939),
BROWN (DyeColor.BROWN, Material.WHITE_WOOL, ChatColor.DARK_RED, 908),
DARKGREEN (DyeColor.GREEN, Material.WHITE_WOOL, ChatColor.DARK_GREEN, 612),
RED (DyeColor.RED, Material.WHITE_WOOL, ChatColor.RED, 245),
BLACK (DyeColor.BLACK, Material.WHITE_WOOL, ChatColor.BLACK, 0);
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.WHITE_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.WHITE_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.*;
@ -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

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);

View File

@ -538,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) {

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

@ -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.LEGACY_STAINED_GLASS_PANE);
item = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);

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.LEGACY_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.LEGACY_STAINED_GLASS_PANE);
item = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
meta = item.getItemMeta();
meta.setDisplayName(">>>> Team Default Config >>>>");
item.setItemMeta(meta);

View File

@ -0,0 +1,19 @@
package com.tommytony.war.utility;
import org.bukkit.Material;
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;
}
}