1.8-1.12 support

This commit is contained in:
Esophose 2019-03-31 01:50:42 -06:00
parent e94a0c6259
commit 86dbb57ac2
8 changed files with 174 additions and 116 deletions

View File

@ -3,10 +3,7 @@ package com.songoda.ultimatetimber.adapter.current;
import com.songoda.ultimatetimber.adapter.IBlockData;
import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.adapter.VersionAdapterType;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeBlockType;
import com.songoda.ultimatetimber.tree.*;
import com.songoda.ultimatetimber.utils.Methods;
import org.bukkit.Location;
import org.bukkit.Material;
@ -43,14 +40,16 @@ public class CurrentAdapter implements VersionAdapter {
}
@Override
public Collection<ItemStack> getBlockDrops(ITreeBlock treeBlock) {
public Collection<ItemStack> getBlockDrops(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
Set<ItemStack> drops = new HashSet<>();
if (treeBlock.getBlock() instanceof Block) {
Block block = (Block)treeBlock.getBlock();
Set<ItemStack> drops = new HashSet<>();
drops.add(new ItemStack(block.getType()));
return drops; // TODO: Do this properly
} else if (treeBlock.getBlock() instanceof FallingBlock) {
FallingBlock fallingBlock = (FallingBlock)treeBlock.getBlock();
drops.add(new ItemStack(fallingBlock.getBlockData().getMaterial()));
}
return new HashSet<>();
return drops;
}
@Override
@ -95,7 +94,7 @@ public class CurrentAdapter implements VersionAdapter {
}
@Override
public void playFallingParticles(ITreeBlock treeBlock) {
public void playFallingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
BlockData blockData;
if (treeBlock.getBlock() instanceof Block) {
blockData = ((Block)treeBlock.getBlock()).getBlockData();
@ -108,7 +107,7 @@ public class CurrentAdapter implements VersionAdapter {
}
@Override
public void playLandingParticles(ITreeBlock treeBlock) {
public void playLandingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
BlockData blockData;
if (treeBlock.getBlock() instanceof Block) {
blockData = ((Block)treeBlock.getBlock()).getBlockData();

View File

@ -3,17 +3,18 @@ package com.songoda.ultimatetimber.adapter.legacy;
import com.songoda.ultimatetimber.adapter.IBlockData;
import com.songoda.ultimatetimber.adapter.VersionAdapter;
import com.songoda.ultimatetimber.adapter.VersionAdapterType;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.*;
import com.songoda.ultimatetimber.utils.Methods;
import com.songoda.ultimatetimber.utils.NMSUtil;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import java.util.Collection;
import java.util.*;
@SuppressWarnings("deprecation")
public class LegacyAdapter implements VersionAdapter {
@ -25,27 +26,94 @@ public class LegacyAdapter implements VersionAdapter {
@Override
public IBlockData parseBlockDataFromString(String blockDataString) {
return null;
String[] split = blockDataString.split(":");
Material material = Material.matchMaterial(split[0]);
List<Byte> data = new ArrayList<>();
if (split.length > 1) {
String[] splitData = split[1].split(",");
for (String dataValue : splitData)
data.add(Byte.parseByte(dataValue));
} else {
data.add((byte)0);
}
return new LegacyBlockData(material, data);
}
@Override
public ItemStack parseItemStackFromString(String itemStackString) {
return null;
String[] split = itemStackString.split(":");
Material material = Material.matchMaterial(split[0]);
byte data = 0;
if (split.length > 1) {
data = Byte.parseByte(split[1]);
}
return new ItemStack(material, 1, data);
}
@Override
public Collection<ItemStack> getBlockDrops(ITreeBlock treeBlock) {
return null;
public Collection<ItemStack> getBlockDrops(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
Set<ItemStack> drops = new HashSet<>();
IBlockData treeBlockData;
if (treeBlock.getBlock() instanceof Block) {
Block block = (Block)treeBlock.getBlock();
List<Byte> data = new ArrayList<>();
data.add(block.getData());
treeBlockData = new LegacyBlockData(block.getType(), data);
} else if (treeBlock.getBlock() instanceof FallingBlock) {
FallingBlock fallingBlock = (FallingBlock)treeBlock.getBlock();
List<Byte> data = new ArrayList<>();
data.add(fallingBlock.getBlockData());
treeBlockData = new LegacyBlockData(fallingBlock.getMaterial(), data);
} else return drops;
IBlockData definitionBlockData = null;
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
for (IBlockData blockData : treeDefinition.getLogBlockData()) {
if (blockData.getMaterial().equals(treeBlockData.getMaterial())) {
definitionBlockData = blockData;
break;
}
}
} else {
for (IBlockData blockData : treeDefinition.getLeafBlockData()) {
if (blockData.getMaterial().equals(treeBlockData.getMaterial())) {
definitionBlockData = blockData;
break;
}
}
}
if (definitionBlockData != null && definitionBlockData.isSimilar(treeBlockData))
drops.add(new ItemStack(definitionBlockData.getMaterial(), 1, definitionBlockData.getData()));
return drops;
}
@Override
public void applyToolDurability(Player player, int damage) {
ItemStack tool = this.getItemInHand(player);
if (tool.getType().getMaxDurability() <= 1)
return;
int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY);
int actualDamage = 0;
for (int i = 0; i < damage; i++)
if (Methods.checkUnbreakingChance(unbreakingLevel))
actualDamage++;
tool.setDurability((short)(tool.getDurability() + actualDamage));
if (!this.hasEnoughDurability(tool, 1))
this.removeItemInHand(player);
}
@Override
public boolean hasEnoughDurability(ItemStack tool, int requiredAmount) {
return false;
if (tool.getType().getMaxDurability() <= 1)
return true;
return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability();
}
@Override
@ -59,32 +127,58 @@ public class LegacyAdapter implements VersionAdapter {
}
@Override
public void playFallingParticles(ITreeBlock treeBlock) {
public void playFallingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
Collection<ItemStack> blockDrops = this.getBlockDrops(treeDefinition, treeBlock);
if (!blockDrops.iterator().hasNext())
return;
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().spawnParticle(Particle.BLOCK_CRACK, location, 10, 0, 0, 0, blockDrops.iterator().next().getData());
} else {
location.getWorld().playEffect(location, Effect.SMOKE, 4);
}
}
@Override
public void playLandingParticles(ITreeBlock treeBlock) {
public void playLandingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock) {
Collection<ItemStack> blockDrops = this.getBlockDrops(treeDefinition, treeBlock);
if (!blockDrops.iterator().hasNext())
return;
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().spawnParticle(Particle.BLOCK_DUST, location, 10, 0, 0, 0, blockDrops.iterator().next().getData());
} else {
location.getWorld().playEffect(location, Effect.SMOKE, 4);
}
}
@Override
public void playFallingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 3F, 0.1F);
location.getWorld().playSound(location, Sound.BLOCK_CHEST_OPEN, 2F, 0.1F);
} else {
location.getWorld().playSound(location, Sound.valueOf("CHEST_OPEN"), 3F, 0.1F);
location.getWorld().playSound(location, Sound.valueOf("CHEST_OPEN"), 2F, 0.1F);
}
}
@Override
public void playLandingSound(ITreeBlock treeBlock) {
Location location = treeBlock.getLocation();
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_WOOD_FALL, 3F, 0.1F);
if (treeBlock.getTreeBlockType().equals(TreeBlockType.LOG)) {
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_WOOD_FALL, 3F, 0.1F);
} else {
location.getWorld().playSound(location, Sound.valueOf("DIG_WOOD"), 3F, 0.1F);
}
} else {
location.getWorld().playSound(location, Sound.valueOf("DIG_WOOD"), 3F, 0.1F);
if (NMSUtil.getVersionNumber() > 8) {
location.getWorld().playSound(location, Sound.BLOCK_GRASS_BREAK, 0.5F, 0.75F);
} else {
location.getWorld().playSound(location, Sound.valueOf("DIG_GRASS"), 0.5F, 0.75F);
}
}
}

View File

@ -4,13 +4,16 @@ import com.songoda.ultimatetimber.adapter.IBlockData;
import org.bukkit.Material;
import org.bukkit.block.Block;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("deprecation")
public class LegacyBlockData implements IBlockData {
private final Material material;
private final byte data;
private final List<Byte> data;
public LegacyBlockData(Material material, byte data) {
public LegacyBlockData(Material material, List<Byte> data) {
this.material = material;
this.data = data;
}
@ -22,25 +25,37 @@ public class LegacyBlockData implements IBlockData {
@Override
public byte getData() {
return this.data;
return this.data.get(0);
}
@Override
public boolean isSimilar(IBlockData otherBlockData) {
return this.getMaterial().equals(otherBlockData.getMaterial()) && this.getData() == otherBlockData.getData();
Material blockMaterial = otherBlockData.getMaterial();
byte blockData = otherBlockData.getData();
if (!this.material.equals(blockMaterial))
return false;
for (byte value : this.data)
if (value == blockData)
return true;
return false;
}
@Override
public boolean isSimilar(Block block) {
Material blockMaterial = block.getType();
byte blockData = block.getData();
return this.material.equals(blockMaterial) && this.data == blockData;
if (!this.material.equals(blockMaterial))
return false;
for (byte value : this.data)
if (value == blockData)
return true;
return false;
}
@Override
public void setBlock(Block block) {
block.setType(this.material);
block.setData(this.data);
block.setData(this.data.get(0));
}
}

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatetimber.adapter;
import com.songoda.ultimatetimber.tree.FallingTreeBlock;
import com.songoda.ultimatetimber.tree.ITreeBlock;
import com.songoda.ultimatetimber.tree.TreeBlockSet;
import com.songoda.ultimatetimber.tree.TreeDefinition;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -37,10 +38,11 @@ public interface VersionAdapter {
/**
* Get the items that a tree block should drop when it breaks
*
* @param treeDefinition The tree definition to get the items for
* @param treeBlock The tree block
* @return A Set of ItemStacks that should be dropped
*/
Collection<ItemStack> getBlockDrops(ITreeBlock treeBlock);
Collection<ItemStack> getBlockDrops(TreeDefinition treeDefinition, ITreeBlock treeBlock);
/**
* Applies damage to a tool
@ -77,16 +79,18 @@ public interface VersionAdapter {
/**
* Plays particles to indicate a tree block has started falling
*
* @param treeDefinition The TreeDefinition of the block
* @param treeBlock The TreeBlock to play the particles for
*/
void playFallingParticles(ITreeBlock treeBlock);
void playFallingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock);
/**
* Plays particles to indicate a tree block has hit the ground
*
* @param treeDefinition The TreeDefinition of the block
* @param treeBlock The TreeBlock to play the particles for
*/
void playLandingParticles(ITreeBlock treeBlock);
void playLandingParticles(TreeDefinition treeDefinition, ITreeBlock treeBlock);
/**
* Plays a sound to indicate a tree block has started falling

View File

@ -64,7 +64,7 @@ public class TreeAnimationDisintegrate extends TreeAnimation {
for (ITreeBlock<Block> treeBlock : toDestroy) {
if (useCustomParticles)
versionAdapter.playFallingParticles(treeBlock);
versionAdapter.playFallingParticles(td, treeBlock);
treeDefinitionManager.dropTreeLoot(td, treeBlock, p);
TreeAnimationDisintegrate.this.replaceBlock(treeBlock.getBlock());
}

View File

@ -27,7 +27,7 @@ public class TreeAnimationNone extends TreeAnimation {
if (ConfigurationManager.Setting.USE_CUSTOM_PARTICLES.getBoolean())
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks())
versionAdapter.playFallingParticles(treeBlock);
versionAdapter.playFallingParticles(this.detectedTree.getTreeDefinition(), treeBlock);
for (ITreeBlock<Block> treeBlock : this.detectedTree.getDetectedTreeBlocks().getAllTreeBlocks()) {
treeDefinitionManager.dropTreeLoot(this.detectedTree.getTreeDefinition(), treeBlock, this.player);

View File

@ -233,13 +233,13 @@ public class TreeDefinitionManager extends Manager {
toTry.addAll(treeDefinition.getLogLoot());
toTry.addAll(this.globalLogLoot);
if (treeDefinition.shouldDropOriginalLog() || hasSilkTouch)
lootedItems.addAll(versionAdapter.getBlockDrops(treeBlock));
lootedItems.addAll(versionAdapter.getBlockDrops(treeDefinition, treeBlock));
break;
case LEAF:
toTry.addAll(treeDefinition.getLeafLoot());
toTry.addAll(this.globalLeafLoot);
if (treeDefinition.shouldDropOriginalLeaf() || hasSilkTouch)
lootedItems.addAll(versionAdapter.getBlockDrops(treeBlock));
lootedItems.addAll(versionAdapter.getBlockDrops(treeDefinition, treeBlock));
break;
}
@ -257,8 +257,12 @@ public class TreeDefinitionManager extends Manager {
// Add to inventory or drop on ground
if (addToInventory) {
Set<ItemStack> extraItems = new HashSet<>();
for (ItemStack lootedItem : lootedItems)
player.getInventory().addItem(lootedItem);
extraItems.addAll(player.getInventory().addItem(lootedItem).values());
Location location = player.getLocation();
for (ItemStack extraItem : extraItems)
location.getWorld().dropItemNaturally(location, extraItem);
} else {
Location location = treeBlock.getLocation().clone().add(0.5, 0.5, 0.5);
for (ItemStack lootedItem : lootedItems)

View File

@ -134,15 +134,9 @@ mix-all-tree-types: false
trees:
oak:
logs:
- LOG:0
- LOG:4
- LOG:8
- LOG:12
- LOG:0,4,8,12
leaves:
- LEAVES:0
- LEAVES:4
- LEAVES:8
- LEAVES:12
- LEAVES:0,4,8,12
sapling: SAPLING:0
plantable-soil: []
max-leaf-distance-from-log: 6
@ -160,15 +154,9 @@ trees:
required-tools: []
spruce:
logs:
- LOG:1
- LOG:5
- LOG:9
- LOG:13
- LOG:1,5,9,13
leaves:
- LEAVES:1
- LEAVES:5
- LEAVES:9
- LEAVES:13
- LEAVES:1,5,9,13
sapling: SAPLING:1
plantable-soil: []
max-leaf-distance-from-log: 6
@ -183,15 +171,9 @@ trees:
required-tools: []
birch:
logs:
- LOG:2
- LOG:6
- LOG:10
- LOG:14
- LOG:2,6,10,14
leaves:
- LEAVES:2
- LEAVES:6
- LEAVES:10
- LEAVES:14
- LEAVES:2,6,10,14
sapling: SAPLING:2
plantable-soil: []
max-leaf-distance-from-log: 4
@ -206,15 +188,9 @@ trees:
required-tools: []
jungle:
logs:
- LOG:3
- LOG:7
- LOG:11
- LOG:15
- LOG:3,7,11,15
leaves:
- LEAVES:3
- LEAVES:7
- LEAVES:11
- LEAVES:15
- LEAVES:3,7,11,15
sapling: SAPLING:3
plantable-soil: []
max-leaf-distance-from-log: 6
@ -229,15 +205,9 @@ trees:
required-tools: []
acacia:
logs:
- LOG_2:0
- LOG_2:4
- LOG_2:8
- LOG_2:12
- LOG_2:0,4,8,12
leaves:
- LEAVES_2:0
- LEAVES_2:4
- LEAVES_2:8
- LEAVES_2:12
- LEAVES_2:0,4,8,12
sapling: SAPLING:4
plantable-soil: []
max-leaf-distance-from-log: 5
@ -252,15 +222,9 @@ trees:
required-tools: []
dark_oak:
logs:
- LOG:1
- LOG:5
- LOG:9
- LOG:13
- LOG:1,5,9,13
leaves:
- LEAVES:1
- LEAVES:5
- LEAVES:9
- LEAVES:13
- LEAVES:1,5,9,13
sapling: SAPLING:5
plantable-soil: []
max-leaf-distance-from-log: 5
@ -278,20 +242,9 @@ trees:
required-tools: []
brown_mushroom:
logs:
- HUGE_MUSHROOM_1:10
- HUGE_MUSHROOM_1:15
- HUGE_MUSHROOM_1:15,10
leaves:
- HUGE_MUSHROOM_1:0
- HUGE_MUSHROOM_1:1
- HUGE_MUSHROOM_1:2
- HUGE_MUSHROOM_1:3
- HUGE_MUSHROOM_1:4
- HUGE_MUSHROOM_1:5
- HUGE_MUSHROOM_1:6
- HUGE_MUSHROOM_1:7
- HUGE_MUSHROOM_1:8
- HUGE_MUSHROOM_1:9
- HUGE_MUSHROOM_1:14
- HUGE_MUSHROOM_1:14,0,1,2,3,4,5,6,7,8,9
sapling: BROWN_MUSHROOM
plantable-soil:
- MYCEL
@ -307,20 +260,9 @@ trees:
required-tools: []
red_mushroom:
logs:
- HUGE_MUSHROOM_2:10
- HUGE_MUSHROOM_2:15
- HUGE_MUSHROOM_2:15,10
leaves:
- HUGE_MUSHROOM_2:0
- HUGE_MUSHROOM_2:1
- HUGE_MUSHROOM_2:2
- HUGE_MUSHROOM_2:3
- HUGE_MUSHROOM_2:4
- HUGE_MUSHROOM_2:5
- HUGE_MUSHROOM_2:6
- HUGE_MUSHROOM_2:7
- HUGE_MUSHROOM_2:8
- HUGE_MUSHROOM_2:9
- HUGE_MUSHROOM_2:14
- HUGE_MUSHROOM_2:14,0,1,2,3,4,5,6,7,8,9
sapling: RED_MUSHROOM
plantable-soil:
- MYCEL