mirror of
https://github.com/garbagemule/MobArena.git
synced 2025-01-24 01:01:49 +01:00
Replace some deprecated API calls with non-deprecated alternatives.
This commit does not fix all deprecated API problems, but deals with some of the most straightforward ones.
This commit is contained in:
parent
574a4fdb5f
commit
9bb7bc1f11
@ -1,5 +1,7 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import static org.bukkit.Material.*;
|
||||
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import org.bukkit.Location;
|
||||
@ -12,6 +14,7 @@ import org.bukkit.permissions.PermissionAttachment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -287,8 +290,15 @@ public class ArenaClass
|
||||
/**
|
||||
* Used by isWeapon() to determine if an ItemStack is a weapon type.
|
||||
*/
|
||||
private static int[] weaponTypes = {256,257,258,259,261,267,268,269,270,271,272,273,274,275,276,277,278,279,283,284,285,286,290,291,292,293,294,346,398};
|
||||
|
||||
private static EnumSet<Material> weaponTypes = EnumSet.of(
|
||||
WOOD_SWORD, GOLD_SWORD, STONE_SWORD, IRON_SWORD, DIAMOND_SWORD,
|
||||
WOOD_AXE, GOLD_AXE, STONE_AXE, IRON_AXE, DIAMOND_AXE,
|
||||
WOOD_PICKAXE, GOLD_PICKAXE, STONE_PICKAXE, IRON_PICKAXE, DIAMOND_PICKAXE,
|
||||
WOOD_SPADE, GOLD_SPADE, STONE_SPADE, IRON_SPADE, DIAMOND_SPADE,
|
||||
WOOD_HOE, GOLD_HOE, STONE_HOE, IRON_HOE, DIAMOND_HOE,
|
||||
BOW, FISHING_ROD, FLINT_AND_STEEL, SHEARS, CARROT_STICK, SHIELD
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns true, if the ItemStack appears to be a weapon, in which case
|
||||
* the addItem() method will set the weapon durability to the absolute
|
||||
@ -298,7 +308,7 @@ public class ArenaClass
|
||||
*/
|
||||
public static boolean isWeapon(ItemStack stack) {
|
||||
if (stack == null) return false;
|
||||
return Arrays.binarySearch(weaponTypes, stack.getTypeId()) > -1;
|
||||
return weaponTypes.contains(stack.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,28 +318,44 @@ public class ArenaClass
|
||||
* 'armor'-node.
|
||||
*/
|
||||
public enum ArmorType {
|
||||
HELMET (298,302,306,310,314),
|
||||
CHESTPLATE (299,303,307,311,315),
|
||||
LEGGINGS (300,304,308,312,316),
|
||||
BOOTS (301,305,309,313,317);
|
||||
|
||||
private int[] types;
|
||||
|
||||
ArmorType(int... types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
HELMET,
|
||||
CHESTPLATE,
|
||||
LEGGINGS,
|
||||
BOOTS;
|
||||
|
||||
public static ArmorType getType(ItemStack stack) {
|
||||
int id = stack.getTypeId();
|
||||
|
||||
for (ArmorType armorType : ArmorType.values()) {
|
||||
for (int type : armorType.types) {
|
||||
if (id == type) {
|
||||
return armorType;
|
||||
}
|
||||
}
|
||||
switch (stack.getType()) {
|
||||
case LEATHER_HELMET:
|
||||
case CHAINMAIL_HELMET:
|
||||
case IRON_HELMET:
|
||||
case DIAMOND_HELMET:
|
||||
case GOLD_HELMET:
|
||||
return HELMET;
|
||||
|
||||
case LEATHER_CHESTPLATE:
|
||||
case CHAINMAIL_CHESTPLATE:
|
||||
case IRON_CHESTPLATE:
|
||||
case DIAMOND_CHESTPLATE:
|
||||
case GOLD_CHESTPLATE:
|
||||
return CHESTPLATE;
|
||||
|
||||
case LEATHER_LEGGINGS:
|
||||
case CHAINMAIL_LEGGINGS:
|
||||
case IRON_LEGGINGS:
|
||||
case DIAMOND_LEGGINGS:
|
||||
case GOLD_LEGGINGS:
|
||||
return LEGGINGS;
|
||||
|
||||
case LEATHER_BOOTS:
|
||||
case CHAINMAIL_BOOTS:
|
||||
case IRON_BOOTS:
|
||||
case DIAMOND_BOOTS:
|
||||
case GOLD_BOOTS:
|
||||
return BOOTS;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1368,7 +1368,7 @@ public class ArenaImpl implements Arena
|
||||
|
||||
private void removeBlocks() {
|
||||
for (Block b : blocks) {
|
||||
b.setTypeId(0);
|
||||
b.setType(Material.AIR);
|
||||
}
|
||||
blocks.clear();
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ public class ArenaListener
|
||||
arena.addRepairable(r);
|
||||
|
||||
if (!softRestoreDrops)
|
||||
b.setTypeId(0);
|
||||
b.setType(Material.AIR);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ public class ArenaListener
|
||||
if (b.getType() == Material.TNT) {
|
||||
Player planter = getPlanter(b);
|
||||
if (planter != null) {
|
||||
b.setTypeId(0);
|
||||
b.setType(Material.AIR);
|
||||
TNTPrimed tnt = b.getWorld().spawn(b.getLocation(), TNTPrimed.class);
|
||||
setPlanter(tnt, planter);
|
||||
}
|
||||
@ -504,7 +504,7 @@ public class ArenaListener
|
||||
if (mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
|
||||
arena.removeBlock(b);
|
||||
else if (arena.removeBlock(b))
|
||||
arena.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(state.getTypeId(), 1));
|
||||
arena.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(state.getType(), 1));
|
||||
else if (softRestore)
|
||||
arena.addRepairable(r);
|
||||
else
|
||||
@ -791,7 +791,7 @@ public class ArenaListener
|
||||
Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS,
|
||||
Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS,
|
||||
// Misc
|
||||
Material.BOW, Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SHEARS, Material.CARROT_STICK
|
||||
Material.BOW, Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SHEARS, Material.CARROT_STICK, Material.SHIELD
|
||||
);
|
||||
|
||||
private void repairWeapon(Player p) {
|
||||
@ -799,7 +799,8 @@ public class ArenaListener
|
||||
if (ap != null) {
|
||||
ArenaClass ac = ap.getArenaClass();
|
||||
if (ac != null && ac.hasUnbreakableWeapons()) {
|
||||
repair(p.getItemInHand());
|
||||
repair(p.getInventory().getItemInMainHand());
|
||||
repair(p.getInventory().getItemInOffHand());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -999,7 +1000,7 @@ public class ArenaListener
|
||||
return;
|
||||
|
||||
if (!arena.isRunning()) {
|
||||
event.getBlockClicked().getRelative(event.getBlockFace()).setTypeId(0);
|
||||
event.getBlockClicked().getRelative(event.getBlockFace()).setType(Material.AIR);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1024,7 +1025,7 @@ public class ArenaListener
|
||||
return;
|
||||
|
||||
// Iron block
|
||||
if (event.getClickedBlock().getTypeId() == 42) {
|
||||
if (event.getClickedBlock().getType() == Material.IRON_BLOCK) {
|
||||
handleReadyBlock(p);
|
||||
}
|
||||
// Sign
|
||||
|
@ -338,29 +338,29 @@ public class MAUtils
|
||||
{
|
||||
for (int j = y1; j <= y2; j++)
|
||||
{
|
||||
world.getBlockAt(i,j,z1).setTypeId(24);
|
||||
world.getBlockAt(i,j,z2).setTypeId(24);
|
||||
world.getBlockAt(i,j,z1).setType(Material.SANDSTONE);
|
||||
world.getBlockAt(i,j,z2).setType(Material.SANDSTONE);
|
||||
}
|
||||
}
|
||||
for (int k = z1; k <= z2; k++)
|
||||
{
|
||||
for (int j = y1; j <= y2; j++)
|
||||
{
|
||||
world.getBlockAt(x1,j,k).setTypeId(24);
|
||||
world.getBlockAt(x2,j,k).setTypeId(24);
|
||||
world.getBlockAt(x1,j,k).setType(Material.SANDSTONE);
|
||||
world.getBlockAt(x2,j,k).setType(Material.SANDSTONE);
|
||||
}
|
||||
}
|
||||
|
||||
// Add some hippie light.
|
||||
for (int i = x1; i <= x2; i++)
|
||||
{
|
||||
world.getBlockAt(i,y1+2,z1).setTypeId(89);
|
||||
world.getBlockAt(i,y1+2,z2).setTypeId(89);
|
||||
world.getBlockAt(i,y1+2,z1).setType(Material.GLOWSTONE);
|
||||
world.getBlockAt(i,y1+2,z2).setType(Material.GLOWSTONE);
|
||||
}
|
||||
for (int k = z1; k <= z2; k++)
|
||||
{
|
||||
world.getBlockAt(x1,y1+2,k).setTypeId(89);
|
||||
world.getBlockAt(x2,y1+2,k).setTypeId(89);
|
||||
world.getBlockAt(x1,y1+2,k).setType(Material.GLOWSTONE);
|
||||
world.getBlockAt(x2,y1+2,k).setType(Material.GLOWSTONE);
|
||||
}
|
||||
|
||||
// Build a monster floor, and some Obsidian foundation.
|
||||
@ -368,8 +368,8 @@ public class MAUtils
|
||||
{
|
||||
for (int k = z1; k <= z2; k++)
|
||||
{
|
||||
world.getBlockAt(i,y1,k).setTypeId(24);
|
||||
world.getBlockAt(i,y1-1,k).setTypeId(49);
|
||||
world.getBlockAt(i,y1,k).setType(Material.SANDSTONE);
|
||||
world.getBlockAt(i,y1-1,k).setType(Material.OBSIDIAN);
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,48 +377,48 @@ public class MAUtils
|
||||
for (int i = x1; i <= x2; i++)
|
||||
{
|
||||
for (int k = z1; k <= z2; k++)
|
||||
world.getBlockAt(i,y2,k).setTypeId(20);
|
||||
world.getBlockAt(i,y2,k).setType(Material.GLASS);
|
||||
}
|
||||
|
||||
// Monster bulldoze
|
||||
for (int i = x1+1; i < x2; i++)
|
||||
for (int j = y1+1; j < y2; j++)
|
||||
for (int k = z1+1; k < z2; k++)
|
||||
world.getBlockAt(i,j,k).setTypeId(0);
|
||||
world.getBlockAt(i,j,k).setType(Material.AIR);
|
||||
|
||||
// Build a hippie lobby
|
||||
for (int i = lx1; i <= lx2; i++) // Walls
|
||||
{
|
||||
for (int j = ly1; j <= ly2; j++)
|
||||
{
|
||||
world.getBlockAt(i,j,lz1).setTypeId(24);
|
||||
world.getBlockAt(i,j,lz2).setTypeId(24);
|
||||
world.getBlockAt(i,j,lz1).setType(Material.SANDSTONE);
|
||||
world.getBlockAt(i,j,lz2).setType(Material.SANDSTONE);
|
||||
}
|
||||
}
|
||||
for (int k = lz1; k <= lz2; k++) // Walls
|
||||
{
|
||||
for (int j = ly1; j <= ly2; j++)
|
||||
{
|
||||
world.getBlockAt(lx1,j,k).setTypeId(24);
|
||||
world.getBlockAt(lx2,j,k).setTypeId(24);
|
||||
world.getBlockAt(lx1,j,k).setType(Material.SANDSTONE);
|
||||
world.getBlockAt(lx2,j,k).setType(Material.SANDSTONE);
|
||||
}
|
||||
}
|
||||
for (int k = lz1; k <= lz2; k++) // Lights
|
||||
{
|
||||
world.getBlockAt(lx1,ly1+2,k).setTypeId(89);
|
||||
world.getBlockAt(lx2,ly1+2,k).setTypeId(89);
|
||||
world.getBlockAt(lx1,ly1+3,k).setTypeId(89);
|
||||
world.getBlockAt(lx2,ly1+3,k).setTypeId(89);
|
||||
world.getBlockAt(lx1,ly1+2,k).setType(Material.GLOWSTONE);
|
||||
world.getBlockAt(lx2,ly1+2,k).setType(Material.GLOWSTONE);
|
||||
world.getBlockAt(lx1,ly1+3,k).setType(Material.GLOWSTONE);
|
||||
world.getBlockAt(lx2,ly1+3,k).setType(Material.GLOWSTONE);
|
||||
}
|
||||
for (int i = lx1; i <= lx2; i++) // Floor
|
||||
{
|
||||
for (int k = lz1; k <= lz2; k++)
|
||||
world.getBlockAt(i,ly1,k).setTypeId(24);
|
||||
world.getBlockAt(i,ly1,k).setType(Material.SANDSTONE);
|
||||
}
|
||||
for (int i = x1+1; i < lx2; i++) // Bulldoze
|
||||
for (int j = ly1+1; j <= ly2; j++)
|
||||
for (int k = lz1+1; k < lz2; k++)
|
||||
world.getBlockAt(i,j,k).setTypeId(0);
|
||||
world.getBlockAt(i,j,k).setType(Material.AIR);
|
||||
|
||||
// Place the hippie signs
|
||||
//Iterator<String> iterator = am.getClasses().iterator();
|
||||
|
@ -310,7 +310,7 @@ public class MobArena extends JavaPlugin
|
||||
|
||||
public boolean giveMoney(Player p, ItemStack item) {
|
||||
if (economy != null) {
|
||||
EconomyResponse result = economy.depositPlayer(p.getName(), getAmount(item));
|
||||
EconomyResponse result = economy.depositPlayer(p, getAmount(item));
|
||||
return (result.type == ResponseType.SUCCESS);
|
||||
}
|
||||
return false;
|
||||
@ -322,7 +322,7 @@ public class MobArena extends JavaPlugin
|
||||
|
||||
public boolean takeMoney(Player p, double amount) {
|
||||
if (economy != null) {
|
||||
EconomyResponse result = economy.withdrawPlayer(p.getName(), amount);
|
||||
EconomyResponse result = economy.withdrawPlayer(p, amount);
|
||||
return (result.type == ResponseType.SUCCESS);
|
||||
}
|
||||
return false;
|
||||
@ -333,7 +333,7 @@ public class MobArena extends JavaPlugin
|
||||
}
|
||||
|
||||
public boolean hasEnough(Player p, double amount) {
|
||||
return economy == null || (economy.getBalance(p.getName()) >= amount);
|
||||
return economy == null || (economy.getBalance(p) >= amount);
|
||||
}
|
||||
|
||||
public String economyFormat(ItemStack item) {
|
||||
|
@ -208,7 +208,7 @@ public class SetupCommand implements Command, Listener {
|
||||
}
|
||||
|
||||
private boolean isTool(ItemStack item) {
|
||||
if (item == null || item.getTypeId() == 0) return false;
|
||||
if (item == null || item.getType() == Material.AIR) return false;
|
||||
|
||||
String name = item.getItemMeta().getDisplayName();
|
||||
if (name == null) return false;
|
||||
|
@ -2,6 +2,7 @@ package com.garbagemule.MobArena.util.inventory;
|
||||
|
||||
import com.garbagemule.MobArena.MobArena;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -116,12 +117,12 @@ public class InventoryManager
|
||||
|
||||
// Check for null or id 0, or AIR
|
||||
for (ItemStack stack : inventory) {
|
||||
if (stack != null && stack.getTypeId() != 0)
|
||||
if (stack != null && stack.getType() != Material.AIR)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ItemStack stack : armor) {
|
||||
if (stack != null && stack.getTypeId() != 0)
|
||||
if (stack != null && stack.getType() != Material.AIR)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.garbagemule.MobArena.waves.MABoss;
|
||||
import com.garbagemule.MobArena.waves.ability.Ability;
|
||||
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
|
||||
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -19,8 +20,8 @@ public class Flood implements Ability
|
||||
Player p = AbilityUtils.getRandomPlayer(arena);
|
||||
Block block = p.getLocation().getBlock();
|
||||
|
||||
if (block.getTypeId() == 0) {
|
||||
block.setTypeId(8);
|
||||
if (block.getType() == Material.AIR) {
|
||||
block.setType(Material.WATER);
|
||||
arena.addBlock(block);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user