mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Tree Feller now partially destroys trees if the whole tree is too big
Fixes #4811
This commit is contained in:
parent
fb738d85f6
commit
101c43a4bc
@ -1,5 +1,7 @@
|
|||||||
Version 2.1.217
|
Version 2.1.217
|
||||||
Fixed mouse-hover tooltips (thanks Greymagic27)
|
Fixed mouse-hover tooltips (thanks Greymagic27)
|
||||||
|
Tree Feller will now break blocks within the limit instead of refusing to fell the entire tree (partial big tree destruction)
|
||||||
|
Mangrove trees resulting from growth are now marked as natural (existing trees marked unnatural before this update will not be retroactively fixed)
|
||||||
|
|
||||||
Version 2.1.216
|
Version 2.1.216
|
||||||
Reverted Unarmed changes from 2.1.215 (fixes block breaker/beserk active at all time for all players)
|
Reverted Unarmed changes from 2.1.215 (fixes block breaker/beserk active at all time for all players)
|
||||||
|
@ -25,7 +25,7 @@ public abstract class BukkitConfig {
|
|||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.dataFolder = dataFolder;
|
this.dataFolder = dataFolder;
|
||||||
configFile = new File(dataFolder, fileName);
|
configFile = new File(dataFolder, fileName);
|
||||||
purgeComments(true);
|
// purgeComments(true);
|
||||||
this.config = initConfig();
|
this.config = initConfig();
|
||||||
initDefaults();
|
initDefaults();
|
||||||
updateFile();
|
updateFile();
|
||||||
@ -124,84 +124,84 @@ public abstract class BukkitConfig {
|
|||||||
return configFile;
|
return configFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Somewhere between December 2021-January 2022 Spigot updated their
|
// * Somewhere between December 2021-January 2022 Spigot updated their
|
||||||
* SnakeYAML dependency/API and due to our own crappy legacy code
|
// * SnakeYAML dependency/API and due to our own crappy legacy code
|
||||||
* this introduced a very problematic bug where comments got duplicated
|
// * this introduced a very problematic bug where comments got duplicated
|
||||||
* <p>
|
// * <p>
|
||||||
* This method hotfixes the problem by just deleting any existing comments
|
// * This method hotfixes the problem by just deleting any existing comments
|
||||||
* it's ugly, but it gets the job done
|
// * it's ugly, but it gets the job done
|
||||||
*
|
// *
|
||||||
* @param silentFail when true mcMMO will report errors during the patch process or debug information
|
// * @param silentFail when true mcMMO will report errors during the patch process or debug information
|
||||||
* the option to have it fail silently is because mcMMO wants to check files before they are parsed as a file with a zillion comments will fail to even load
|
// * the option to have it fail silently is because mcMMO wants to check files before they are parsed as a file with a zillion comments will fail to even load
|
||||||
*/
|
// */
|
||||||
private void purgeComments(boolean silentFail) {
|
// private void purgeComments(boolean silentFail) {
|
||||||
if(!configFile.exists())
|
// if(!configFile.exists())
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
int dupedLines = 0, lineCount = 0, lineCountAfter = 0;
|
// int dupedLines = 0, lineCount = 0, lineCountAfter = 0;
|
||||||
try (FileReader fileReader = new FileReader(configFile);
|
// try (FileReader fileReader = new FileReader(configFile);
|
||||||
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
|
// BufferedReader bufferedReader = new BufferedReader(fileReader)) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
// StringBuilder stringBuilder = new StringBuilder();
|
||||||
String line;
|
// String line;
|
||||||
Set<String> seenBefore = new HashSet<>();
|
// Set<String> seenBefore = new HashSet<>();
|
||||||
|
//
|
||||||
stringBuilder.append(CURRENT_CONFIG_PATCH_VER).append(System.lineSeparator());
|
// stringBuilder.append(CURRENT_CONFIG_PATCH_VER).append(System.lineSeparator());
|
||||||
boolean noPatchNeeded = false;
|
// boolean noPatchNeeded = false;
|
||||||
|
//
|
||||||
// While not at the end of the file
|
// // While not at the end of the file
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
// while ((line = bufferedReader.readLine()) != null) {
|
||||||
lineCount++;
|
// lineCount++;
|
||||||
|
//
|
||||||
if(line.startsWith(CURRENT_CONFIG_PATCH_VER)) {
|
// if(line.startsWith(CURRENT_CONFIG_PATCH_VER)) {
|
||||||
noPatchNeeded = true;
|
// noPatchNeeded = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//Older version, don't append this line
|
// //Older version, don't append this line
|
||||||
if(line.startsWith(CONFIG_PATCH_PREFIX))
|
// if(line.startsWith(CONFIG_PATCH_PREFIX))
|
||||||
continue;
|
// continue;
|
||||||
|
//
|
||||||
if (isFirstCharAsciiCharacter(line, COMMENT_PREFIX)) {
|
// if (isFirstCharAsciiCharacter(line, COMMENT_PREFIX)) {
|
||||||
if(seenBefore.contains(line))
|
// if(seenBefore.contains(line))
|
||||||
dupedLines++;
|
// dupedLines++;
|
||||||
else
|
// else
|
||||||
seenBefore.add(line);
|
// seenBefore.add(line);
|
||||||
|
//
|
||||||
continue; //Delete the line by not appending it
|
// continue; //Delete the line by not appending it
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
stringBuilder
|
// stringBuilder
|
||||||
.append(line) //Convert existing files into two-spaced format
|
// .append(line) //Convert existing files into two-spaced format
|
||||||
.append(System.lineSeparator());
|
// .append(System.lineSeparator());
|
||||||
lineCountAfter++;
|
// lineCountAfter++;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(noPatchNeeded)
|
// if(noPatchNeeded)
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
if(lineCount == 0 && !silentFail) {
|
// if(lineCount == 0 && !silentFail) {
|
||||||
mcMMO.p.getLogger().info("[config patcher] Config line count: " + lineCount);
|
// mcMMO.p.getLogger().info("[config patcher] Config line count: " + lineCount);
|
||||||
throw new InvalidConfigurationException("[config patcher] Patching of config file resulted in an empty file, this will not be saved. Contact the mcMMO devs!");
|
// throw new InvalidConfigurationException("[config patcher] Patching of config file resulted in an empty file, this will not be saved. Contact the mcMMO devs!");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if(dupedLines > 0 && !silentFail) {
|
// if(dupedLines > 0 && !silentFail) {
|
||||||
mcMMO.p.getLogger().info("[config patcher] Found "+dupedLines+" duplicate comments in config file: " + configFile.getName());
|
// mcMMO.p.getLogger().info("[config patcher] Found "+dupedLines+" duplicate comments in config file: " + configFile.getName());
|
||||||
mcMMO.p.getLogger().info("[config patcher] Purging the duplicate comments... (Nothing is broken, this is just info used for debugging)");
|
// mcMMO.p.getLogger().info("[config patcher] Purging the duplicate comments... (Nothing is broken, this is just info used for debugging)");
|
||||||
mcMMO.p.getLogger().info("[config patcher] Line count before: "+lineCount);
|
// mcMMO.p.getLogger().info("[config patcher] Line count before: "+lineCount);
|
||||||
mcMMO.p.getLogger().info("[config patcher] Line count after: "+lineCountAfter);
|
// mcMMO.p.getLogger().info("[config patcher] Line count after: "+lineCountAfter);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// Write out the *patched* file
|
// // Write out the *patched* file
|
||||||
// AKA the file without any comments
|
// // AKA the file without any comments
|
||||||
try (FileWriter fileWriter = new FileWriter(configFile)) {
|
// try (FileWriter fileWriter = new FileWriter(configFile)) {
|
||||||
fileWriter.write(stringBuilder.toString());
|
// fileWriter.write(stringBuilder.toString());
|
||||||
}
|
// }
|
||||||
} catch (IOException | InvalidConfigurationException ex) {
|
// } catch (IOException | InvalidConfigurationException ex) {
|
||||||
mcMMO.p.getLogger().severe("Failed to patch config file: " + configFile.getName());
|
// mcMMO.p.getLogger().severe("Failed to patch config file: " + configFile.getName());
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private boolean isFirstCharAsciiCharacter(String line, char character) {
|
private boolean isFirstCharAsciiCharacter(String line, char character) {
|
||||||
if(line == null || line.isEmpty()) {
|
if(line == null || line.isEmpty()) {
|
||||||
|
@ -85,6 +85,9 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processWoodcuttingBlockXP(@NotNull BlockState blockState) {
|
public void processWoodcuttingBlockXP(@NotNull BlockState blockState) {
|
||||||
|
if(mcMMO.getPlaceStore().isTrue(blockState))
|
||||||
|
return;
|
||||||
|
|
||||||
int xp = getExperienceFromLog(blockState);
|
int xp = getExperienceFromLog(blockState);
|
||||||
applyXpGain(xp, XPGainReason.PVE);
|
applyXpGain(xp, XPGainReason.PVE);
|
||||||
}
|
}
|
||||||
@ -102,19 +105,6 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
|
|
||||||
processTree(blockState, treeFellerBlocks);
|
processTree(blockState, treeFellerBlocks);
|
||||||
|
|
||||||
// If the player is trying to break too many blocks
|
|
||||||
if (treeFellerReachedThreshold) {
|
|
||||||
treeFellerReachedThreshold = false;
|
|
||||||
|
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Woodcutting.Skills.TreeFeller.Threshold");
|
|
||||||
|
|
||||||
//Tree feller won't be activated for this block, award normal xp.
|
|
||||||
processWoodcuttingBlockXP(blockState);
|
|
||||||
processHarvestLumber(blockState);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the tool can't sustain the durability loss
|
// If the tool can't sustain the durability loss
|
||||||
if (!handleDurabilityLoss(treeFellerBlocks, player.getInventory().getItemInMainHand(), player)) {
|
if (!handleDurabilityLoss(treeFellerBlocks, player.getInventory().getItemInMainHand(), player)) {
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Woodcutting.Skills.TreeFeller.Splinter");
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Woodcutting.Skills.TreeFeller.Splinter");
|
||||||
@ -352,6 +342,9 @@ public class WoodcuttingManager extends SkillManager {
|
|||||||
* @return Amount of experience
|
* @return Amount of experience
|
||||||
*/
|
*/
|
||||||
private static int processTreeFellerXPGains(BlockState blockState, int woodCount) {
|
private static int processTreeFellerXPGains(BlockState blockState, int woodCount) {
|
||||||
|
if(mcMMO.getPlaceStore().isTrue(blockState))
|
||||||
|
return 0;
|
||||||
|
|
||||||
int rawXP = ExperienceConfig.getInstance().getXp(PrimarySkillType.WOODCUTTING, blockState.getType());
|
int rawXP = ExperienceConfig.getInstance().getXp(PrimarySkillType.WOODCUTTING, blockState.getType());
|
||||||
|
|
||||||
if(rawXP <= 0)
|
if(rawXP <= 0)
|
||||||
|
@ -510,32 +510,34 @@ public final class ItemUtils {
|
|||||||
* @return true if the item is a woodcutting drop, false otherwise
|
* @return true if the item is a woodcutting drop, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isWoodcuttingDrop(ItemStack item) {
|
public static boolean isWoodcuttingDrop(ItemStack item) {
|
||||||
switch (item.getType()) {
|
switch (item.getType().toString()) {
|
||||||
case ACACIA_LOG:
|
case "ACACIA_LOG":
|
||||||
case BIRCH_LOG:
|
case "BIRCH_LOG":
|
||||||
case DARK_OAK_LOG:
|
case "DARK_OAK_LOG":
|
||||||
case JUNGLE_LOG:
|
case "JUNGLE_LOG":
|
||||||
case OAK_LOG:
|
case "OAK_LOG":
|
||||||
case SPRUCE_LOG:
|
case "SPRUCE_LOG":
|
||||||
case STRIPPED_ACACIA_LOG:
|
case "STRIPPED_ACACIA_LOG":
|
||||||
case STRIPPED_BIRCH_LOG:
|
case "STRIPPED_BIRCH_LOG":
|
||||||
case STRIPPED_DARK_OAK_LOG:
|
case "STRIPPED_DARK_OAK_LOG":
|
||||||
case STRIPPED_JUNGLE_LOG:
|
case "STRIPPED_JUNGLE_LOG":
|
||||||
case STRIPPED_OAK_LOG:
|
case "STRIPPED_OAK_LOG":
|
||||||
case STRIPPED_SPRUCE_LOG:
|
case "STRIPPED_SPRUCE_LOG":
|
||||||
case ACACIA_SAPLING:
|
case "STRIPPED_MANGROVE_LOG":
|
||||||
case SPRUCE_SAPLING:
|
case "ACACIA_SAPLING":
|
||||||
case BIRCH_SAPLING:
|
case "SPRUCE_SAPLING":
|
||||||
case DARK_OAK_SAPLING:
|
case "BIRCH_SAPLING":
|
||||||
case JUNGLE_SAPLING:
|
case "DARK_OAK_SAPLING":
|
||||||
case OAK_SAPLING:
|
case "JUNGLE_SAPLING":
|
||||||
case ACACIA_LEAVES:
|
case "OAK_SAPLING":
|
||||||
case BIRCH_LEAVES:
|
case "ACACIA_LEAVES":
|
||||||
case DARK_OAK_LEAVES:
|
case "BIRCH_LEAVES":
|
||||||
case JUNGLE_LEAVES:
|
case "DARK_OAK_LEAVES":
|
||||||
case OAK_LEAVES:
|
case "JUNGLE_LEAVES":
|
||||||
case SPRUCE_LEAVES:
|
case "OAK_LEAVES":
|
||||||
case APPLE:
|
case "SPRUCE_LEAVES":
|
||||||
|
case "BEE_NEST":
|
||||||
|
case "APPLE":
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user