Skip to content

Commit

Permalink
b23: crash plugin when configuration uses an unknown version
Browse files Browse the repository at this point in the history
  • Loading branch information
confor committed Jan 10, 2022
1 parent f2764ef commit b57f13f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
plugins {
id 'java'
id 'eclipse'
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0.1"
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.0.1'
id 'com.github.johnrengelman.shadow' version '7.0.0'
}

def versionPropsFile = file('version.properties')
def versionBuild = 6

if (!versionPropsFile.canRead())
throw new FileNotFoundException("Could not read version.properties")
throw new FileNotFoundException('Could not read version.properties')

def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['BUILD'].toInteger()
def versionBuild = versionProps['BUILD'].toInteger()

group = 'me.confor.velocity'
version = '0.0.6.' + versionBuild
Expand All @@ -31,8 +30,8 @@ dependencies {
annotationProcessor 'com.velocitypowered:velocity-api:3.1.0'

// templating dependency
implementation "net.kyori:adventure-api:4.9.3"
implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT"
implementation 'net.kyori:adventure-api:4.9.3'
implementation 'net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT'
}

def targetJavaVersion = 11
Expand Down Expand Up @@ -74,13 +73,13 @@ void autoIncrementBuildNumber() {
def versionBuild = 6

if (!versionPropsFile.canWrite())
throw new FileNotFoundException("Could not read+write version.properties") // filenotfound??
throw new FileNotFoundException('Could not read+write version.properties') // filenotfound??

def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
versionBuild = versionProps['BUILD'].toInteger()
versionBuild = versionBuild + 1
versionProps["BUILD"] = versionBuild.toString()
versionProps['BUILD'] = versionBuild.toString()
versionProps.store(versionPropsFile.newWriter(), null)
}

Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
#20: add server switch messages, increment config version
#21: try to fix minor bug where server switch messages showed up for everyone except the client switching (ServerConnectedEvent -> ServerPostConnectEvent)
#22: show server switch messages if player was kicked and velocity has a fallback server
#23: crash plugin when configuration uses an unknown version

6 changes: 4 additions & 2 deletions src/main/java/me/confor/velocity/chat/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ private void loadFile() {

// make sure the config makes sense for the current plugin's version
long version = this.toml.getLong("config_version", 0L);
if (version != CONFIG_VERSION)
logger.warn("WARNING: config.toml uses an unknown version number (!= " + CONFIG_VERSION + ")");
if (version != CONFIG_VERSION) {
logger.error("ERROR: config.toml uses an unknown version number (!= " + CONFIG_VERSION + ")");
throw new RuntimeException("Can't use the existing configuration file: version mismatch (intended for another, older version?)");
}
}

public Boolean getBool(String key) {
Expand Down
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Jan 05 08:40:49 CLST 2022
BUILD=22
#Mon Jan 10 15:16:52 CLST 2022
BUILD=24

0 comments on commit b57f13f

Please sign in to comment.