mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Moved block to item conversion to Util class
This commit is contained in:
parent
42f4bba320
commit
8591023ad5
2 changed files with 84 additions and 65 deletions
|
@ -28,71 +28,7 @@ public class EssentialsBlockListener extends BlockListener
|
|||
final User user = ess.getUser(event.getPlayer());
|
||||
// Do not rely on getItemInHand();
|
||||
// http://leaky.bukkit.org/issues/663
|
||||
final ItemStack is = new ItemStack(event.getBlockPlaced().getType(), 1, (short)0, event.getBlockPlaced().getData());
|
||||
switch (is.getType())
|
||||
{
|
||||
case WOODEN_DOOR:
|
||||
is.setType(Material.WOOD_DOOR);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case IRON_DOOR_BLOCK:
|
||||
is.setType(Material.IRON_DOOR);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case SIGN_POST:
|
||||
case WALL_SIGN:
|
||||
is.setType(Material.SIGN);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case CROPS:
|
||||
is.setType(Material.SEEDS);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case CAKE_BLOCK:
|
||||
is.setType(Material.CAKE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case BED_BLOCK:
|
||||
is.setType(Material.BED);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case REDSTONE_WIRE:
|
||||
is.setType(Material.REDSTONE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case REDSTONE_TORCH_OFF:
|
||||
case REDSTONE_TORCH_ON:
|
||||
is.setType(Material.REDSTONE_TORCH_ON);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case DIODE_BLOCK_OFF:
|
||||
case DIODE_BLOCK_ON:
|
||||
is.setType(Material.DIODE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case DOUBLE_STEP:
|
||||
is.setType(Material.STEP);
|
||||
break;
|
||||
case TORCH:
|
||||
case RAILS:
|
||||
case LADDER:
|
||||
case WOOD_STAIRS:
|
||||
case COBBLESTONE_STAIRS:
|
||||
case LEVER:
|
||||
case STONE_BUTTON:
|
||||
case FURNACE:
|
||||
case DISPENSER:
|
||||
case PUMPKIN:
|
||||
case JACK_O_LANTERN:
|
||||
case WOOD_PLATE:
|
||||
case STONE_PLATE:
|
||||
case PISTON_STICKY_BASE:
|
||||
case PISTON_BASE:
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case FIRE:
|
||||
return;
|
||||
}
|
||||
final ItemStack is = Util.convertBlockToItem(event.getBlockPlaced());
|
||||
boolean unlimitedForUser = user.hasUnlimited(is);
|
||||
if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL)
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Util
|
||||
|
@ -331,6 +332,88 @@ public class Util
|
|||
}
|
||||
return isBlockAboveAir(world, x, y, z);
|
||||
}
|
||||
|
||||
public static ItemStack convertBlockToItem(final Block block)
|
||||
{
|
||||
final ItemStack is = new ItemStack(block.getType(), 1, (short)0, block.getData());
|
||||
switch (is.getType())
|
||||
{
|
||||
case WOODEN_DOOR:
|
||||
is.setType(Material.WOOD_DOOR);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case IRON_DOOR_BLOCK:
|
||||
is.setType(Material.IRON_DOOR);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case SIGN_POST:
|
||||
case WALL_SIGN:
|
||||
is.setType(Material.SIGN);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case CROPS:
|
||||
is.setType(Material.SEEDS);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case CAKE_BLOCK:
|
||||
is.setType(Material.CAKE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case BED_BLOCK:
|
||||
is.setType(Material.BED);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case REDSTONE_WIRE:
|
||||
is.setType(Material.REDSTONE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case REDSTONE_TORCH_OFF:
|
||||
case REDSTONE_TORCH_ON:
|
||||
is.setType(Material.REDSTONE_TORCH_ON);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case DIODE_BLOCK_OFF:
|
||||
case DIODE_BLOCK_ON:
|
||||
is.setType(Material.DIODE);
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case DOUBLE_STEP:
|
||||
is.setType(Material.STEP);
|
||||
break;
|
||||
case TORCH:
|
||||
case RAILS:
|
||||
case LADDER:
|
||||
case WOOD_STAIRS:
|
||||
case COBBLESTONE_STAIRS:
|
||||
case LEVER:
|
||||
case STONE_BUTTON:
|
||||
case FURNACE:
|
||||
case DISPENSER:
|
||||
case PUMPKIN:
|
||||
case JACK_O_LANTERN:
|
||||
case WOOD_PLATE:
|
||||
case STONE_PLATE:
|
||||
case PISTON_STICKY_BASE:
|
||||
case PISTON_BASE:
|
||||
case IRON_FENCE:
|
||||
case THIN_GLASS:
|
||||
case TRAP_DOOR:
|
||||
case FENCE:
|
||||
case FENCE_GATE:
|
||||
case NETHER_FENCE:
|
||||
is.setDurability((short)0);
|
||||
break;
|
||||
case FIRE:
|
||||
return null;
|
||||
case PUMPKIN_STEM:
|
||||
is.setType(Material.PUMPKIN_SEEDS);
|
||||
break;
|
||||
case MELON_STEM:
|
||||
is.setType(Material.MELON_SEEDS);
|
||||
break;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
private static DecimalFormat df = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
|
||||
|
||||
public static String formatCurrency(final double value, final IEssentials ess)
|
||||
|
|
Loading…
Reference in a new issue