Skip to content

Commit

Permalink
Do not cancel block break event. Fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Jun 8, 2020
1 parent bded8f1 commit b5122b8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 149 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.15.2-2.1.4] - 2020-06-08
- Do not cancel event so other mods can see it. Project MMO should now gather stats about the broken log (#11).

## [1.15.2-2.1.3] - 2020-05-02
- Add whitelist/blacklist for leaves.

Expand Down
131 changes: 5 additions & 126 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ javadoc {
}

archivesBaseName = project.archivesBaseName
def versionInfo = getModVersion()
System.out.println(versionInfo)
version = "${versionInfo['version']}"
def build_num = getBuildNumber()

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'

minecraft {
Expand Down Expand Up @@ -95,7 +90,7 @@ jar {
"Specification-Vendor" : "RakSrinaNa",
"Specification-Version" : "0.2",
"Implementation-Title" : project.name,
"Implementation-Version" : "${version}",
"Implementation-Version" : project.version,
"Implementation-Vendor" : "RakSrinaNa",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")],)
}
Expand Down Expand Up @@ -142,7 +137,7 @@ githubRelease {
repo = project.repoName
token = buildProperties.secrets['github_token'].string
tagName = "${project.mc_version}-${project.version}"
releaseName = "${project.mc_version}-${versionInfo['version_short']}"
releaseName = "${project.mc_version}-${project.version}"
targetCommitish = "${project.mc_version}"
body {
return getLatestChangeLog()
Expand All @@ -161,122 +156,6 @@ artifacts {
}
}

// Version stuff

def getModVersion() {
try {
return getGitVersion()
} catch (Exception ex) {
System.out.println("Git version failed, falling back to old method")
return getVersion('VERSION', getModFile())
}
}

def getGitVersion() {
// Call git command
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = ['describe', '--long']
standardOutput = outStream
}

def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+).(\d+)-(.*)/

def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = getBuildNumber()

return makeVersionMap(maj, min, rev, bn, matcher[0][4])
}

static def makeVersionMap(maj, min, rev, bn, githash) {
def out = [:]
out['build.major.number'] = maj.toString()
out['build.minor.number'] = min.toString()
out['build.revision.number'] = rev.toString()
out['build.githash'] = githash
out['build.number'] = bn.toString()
out['version_short'] = "${maj}.${min}.${rev}".toString()
out['version'] = "${maj}.${min}.${rev}+${bn}".toString()
return out
}

// Modified old version getter
def getVersion(String type, String mod_file) {
String maj = '0'
String min = '0'
String rev = '0'
String bn = getBuildNumber()

File file = file(mod_file)
def prefix = ~/^(?:public|protected|private) static final String $type = ".*$/
file.eachLine { String s ->
s = s.trim()
if (s ==~ prefix || prefix.matcher(s).matches()) {
String[] bits = s.split("=")
String interesting = bits[1].trim()
interesting = interesting.substring(1, interesting.length() - 2)
String[] pts = interesting.trim().split("\\.")

maj = pts[0] ?: '0'
min = pts[1] ?: '0'
rev = pts[2] ?: '0'
}
}

return makeVersionMap(maj, min, rev, bn, 'unknown')
}

// Used by old getVersion
String getModFile() {
String path = ''
FileTree tree = fileTree(dir: 'src/main/java')
tree.include '**/*.java'
tree.visit { element ->
if (element.file.isFile()) {
element.file.eachLine { String s ->
s = s.trim()
if (s.startsWith('@Mod(')) {
path = "src/main/java/$element.relativePath"
}
}
}
}
return path
}

// Build number tracking

String getBuildNumber() {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
return versionProps['build_num'].toString()
}
return "1"
}

task incrementBuild {
doFirst {
def versionFile = file('version.properties')
if (versionFile.canRead()) {
Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionFile))
def num = versionProps['build_num'].toInteger() + 1
println("incrementing BuildNumber to: " + num)
versionProps['build_num'] = num.toString()
versionProps.store(versionFile.newWriter(), null)
} else {
println("version.properties file not found! Ignoring.")
}
}
}
build.finalizedBy incrementBuild // only increment on successful builds

// Update JSON management

import groovy.json.JsonOutput
Expand All @@ -287,7 +166,7 @@ import java.time.format.DateTimeFormatter
import java.util.concurrent.TimeUnit

def writeUpdateJson() {
def version = getModVersion()['version_short']
def version = project.version
def slurper = new JsonSlurper()
def file = new File('update.json')
def json = slurper.parse(file)
Expand Down Expand Up @@ -340,10 +219,10 @@ void moveOldLog() {
if (new_log_file.exists()) {
if (!old_log_file.exists())
old_log_file.createNewFile()
def version = getModVersion()
def version = project.version
def dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd")
def currDate = LocalDate.now()
def combined = "## [${project.mc_version}-${version['version_short']}] - " + currDate.format(dateFormat) + System.lineSeparator() + new_log_file.text.trim() + System.lineSeparator() + System.lineSeparator() + old_log_file.text
def combined = "## [${project.mc_version}-${version}] - " + currDate.format(dateFormat) + System.lineSeparator() + new_log_file.text.trim() + System.lineSeparator() + System.lineSeparator() + old_log_file.text
old_log_file.setText(combined)
}
}
Expand Down
2 changes: 1 addition & 1 deletion changes.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add whitelist/blacklist for leaves.
- Do not cancel event so other mods can see it. Project MMO should now gather stats about the broken log (#11).
26 changes: 11 additions & 15 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

group = fr.raksrinana
archivesBaseName = FallingTree
mod_id = falling_tree
repoName = FallingTree
name = Falling Tree
vcsUrl = https://github.com/RakSrinaNa/FallingTree.git
changelogUrl = https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md

mc_version = 1.15.2

group=fr.raksrinana
archivesBaseName=FallingTree
mod_id=falling_tree
repoName=FallingTree
name=Falling Tree
version=2.1.4
vcsUrl=https://github.com/RakSrinaNa/FallingTree.git
changelogUrl=https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md
mc_version=1.15.2
forge_version=1.15.2-31.1.77
mcp_channel=snapshot
mcp_mappings=20200509-1.15.1

curseforge_project_id=349559
curseforge_release_type=release

doDeobfJar = true
doSourceJar = true
doDeobfJar=false
doSourceJar=false
2 changes: 0 additions & 2 deletions src/main/java/fr/raksrinana/fallingtree/FallingTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
@Mod(FallingTree.MOD_ID)
public class FallingTree{
public static final String MOD_ID = "falling_tree";
public static final String MOD_NAME = "Falling Tree";
public static final String VERSION = "2.1.3";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public FallingTree(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public static void onBlockBreakEvent(@Nonnull BlockEvent.BreakEvent event){
if(isPlayerInRightState(event.getPlayer()) && event.getWorld() instanceof World){
TreeHandler.getTree((World) event.getWorld(), event.getPos()).ifPresent(tree -> {
if(Config.COMMON.getTreesConfiguration().getMaxSize() >= tree.getLogCount()){
if(TreeHandler.destroy(tree, event.getPlayer(), event.getPlayer().getHeldItem(Hand.MAIN_HAND))){
event.setCanceled(true);
}
TreeHandler.destroy(tree, event.getPlayer(), event.getPlayer().getHeldItem(Hand.MAIN_HAND));
}
else{
event.getPlayer().sendMessage(new TranslationTextComponent("chat.falling_tree.tree_too_big", tree.getLogCount(), Config.COMMON.getTreesConfiguration().getMaxSize()));
Expand Down
5 changes: 3 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"homepage": "https://github.com/RakSrinaNa/FallingTree",
"changelog": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"1.15.2": {
"2.1.4": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.1.3": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.1.2": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.1.1": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
Expand All @@ -11,7 +12,7 @@
"2.0.2": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md"
},
"promos": {
"1.15.2-latest": "2.1.3",
"1.15.2-recommended": "2.1.3"
"1.15.2-latest": "2.1.4",
"1.15.2-recommended": "2.1.4"
}
}

0 comments on commit b5122b8

Please sign in to comment.