Updates to work with ScoreKeeper 0.2.2 buckets.

This commit is contained in:
2026-09-26 20:29:13 -07:00
parent ea18bb2f5c
commit 12099685bf
5 changed files with 79 additions and 10 deletions

View File

@@ -6,7 +6,7 @@ MobScores awards ScoreKeeper points for configured mob kills. Set a score for ea
- Paper 1.21.7 or a compatible newer server. - Paper 1.21.7 or a compatible newer server.
- Java 25 or newer at runtime and for building. - Java 25 or newer at runtime and for building.
- ScoreKeeper 0.2.2 or a compatible release. - ScoreKeeper 0.2.2 or newer.
Install ScoreKeeper and MobScores in the server's `plugins` directory. ScoreKeeper is a required dependency and must be enabled for MobScores to load. Install ScoreKeeper and MobScores in the server's `plugins` directory. ScoreKeeper is a required dependency and must be enabled for MobScores to load.
@@ -25,7 +25,7 @@ Set an entity's value to `0` to disable its points and hide it from the join-tim
## Scoring ## Scoring
MobScores records credit for configured entity types damaged directly by a player or by a projectile fired by a player. When a credited player remains online when the entity dies, its configured points are added to that player's active ScoreKeeper bucket. Other mob attribution is not currently handled. MobScores records credit for configured entity types damaged directly by a player or by a projectile fired by a player. When a credited player remains online when the entity dies, its configured points are added to the dedicated `mob-scores` ScoreKeeper bucket. Use `/score-bucket mob-scores` to view mob points with ScoreKeeper commands. Other mob attribution is not currently handled.
MobScores has no commands of its own. Players see the nonzero score table when they join. MobScores has no commands of its own. Players see the nonzero score table when they join.

View File

@@ -1,6 +1,6 @@
{ {
"name": "MobScores", "name": "Mob Scores",
"url": "https://modrinth.com/plugin/mobscores", "url": "https://modrinth.com/plugin/mob-scores",
"summary": "Award ScoreKeeper points for configured mob kills with a customizable per-entity score table.", "summary": "Award ScoreKeeper points for configured mob kills with a customizable per-entity score table.",
"visibility": "public", "visibility": "public",
"links": { "links": {

View File

@@ -6,7 +6,7 @@ MobScores awards ScoreKeeper points for configured mob kills. It is a Paper plug
- Paper 1.21.7 or a compatible newer server. - Paper 1.21.7 or a compatible newer server.
- Java 25 to build the plugin. - Java 25 to build the plugin.
- ScoreKeeper 0.2.2 or the version declared by `build.gradle`. - ScoreKeeper 0.2.2 or newer.
Install both plugin JARs in the server's `plugins` directory. MobScores declares ScoreKeeper as a hard dependency, so it will not enable without it. Install both plugin JARs in the server's `plugins` directory. MobScores declares ScoreKeeper as a hard dependency, so it will not enable without it.
@@ -23,7 +23,7 @@ ScoreTable:
Restart the server after editing the configuration. A configured value of `0` suppresses that entity from the score table shown to players when they join. Restart the server after editing the configuration. A configured value of `0` suppresses that entity from the score table shown to players when they join.
MobScores has no commands of its own. It records credit for configured entity types damaged directly by a player or by a projectile fired by a player. Other mob attribution is not currently handled. Points are awarded through ScoreKeeper's existing player API and follow the player's UUID-backed score. MobScores has no commands of its own. It records credit for configured entity types damaged directly by a player or by a projectile fired by a player. Other mob attribution is not currently handled. Points go into ScoreKeeper's dedicated `mob-scores` bucket and are tracked by player UUID. Use `/score-bucket mob-scores` before `/score-get` to view mob points; MobScores does not change the player's active bucket automatically.
## Build ## Build

View File

@@ -22,7 +22,7 @@ repositories {
} }
dependencies { dependencies {
compileOnly 'com.majinnaibu.minecraft.plugins:ScoreKeeper:0.2.2-SNAPSHOT' compileOnly 'com.majinnaibu.minecraft.plugins:ScoreKeeper:0.2.2'
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT'
testImplementation libs.junit.junit testImplementation libs.junit.junit

View File

@@ -36,6 +36,9 @@ import com.majinnaibu.minecraft.plugins.mobscores.listeners.PlayerConnectListene
import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin; import com.majinnaibu.minecraft.plugins.scorekeeper.ScoreKeeperPlugin;
public class MobScoresPlugin extends JavaPlugin { public class MobScoresPlugin extends JavaPlugin {
private static final String SCORE_BUCKET_ID = "mob-scores";
private static final String MIN_SCORE_KEEPER_VERSION = "0.2.2";
private Map<UUID, UUID> _claimedMobs = new HashMap<UUID, UUID>(); private Map<UUID, UUID> _claimedMobs = new HashMap<UUID, UUID>();
private Map<EntityType, Integer> _scoreTable = new HashMap<EntityType, Integer>(); private Map<EntityType, Integer> _scoreTable = new HashMap<EntityType, Integer>();
private ScoreKeeperPlugin _scoreKeeper = null; private ScoreKeeperPlugin _scoreKeeper = null;
@@ -66,11 +69,28 @@ public class MobScoresPlugin extends JavaPlugin {
} }
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
_scoreKeeper = (ScoreKeeperPlugin)pm.getPlugin("ScoreKeeper"); ScoreKeeperPlugin scoreKeeper = (ScoreKeeperPlugin)pm.getPlugin("ScoreKeeper");
if(_scoreKeeper == null){ if (scoreKeeper == null) {
logWarning("Unable to find ScoreKeeper plugin."); logWarning("Unable to find ScoreKeeper plugin.");
pm.disablePlugin(this); pm.disablePlugin(this);
return;
}
String scoreKeeperVersion = scoreKeeper.getPluginMeta().getVersion();
if (!isVersionAtLeast(scoreKeeperVersion, MIN_SCORE_KEEPER_VERSION)) {
logWarning(
"ScoreKeeper "
+ MIN_SCORE_KEEPER_VERSION
+ " or newer is required; found "
+ scoreKeeperVersion
+ ".");
pm.disablePlugin(this);
return;
}
_scoreKeeper = scoreKeeper;
if (_scoreKeeper.getBucket(SCORE_BUCKET_ID) == null) {
_scoreKeeper.createBucket(SCORE_BUCKET_ID, "mob point", "mob points", 0);
} }
pm.registerEvents(new MobDeathListener(this), this); pm.registerEvents(new MobDeathListener(this), this);
@@ -124,7 +144,7 @@ public class MobScoresPlugin extends JavaPlugin {
return; return;
} }
int score = _scoreTable.get(type); int score = _scoreTable.get(type);
_scoreKeeper.addScore(player, score); _scoreKeeper.addScore(player, SCORE_BUCKET_ID, score);
} else { } else {
logWarning("Unable to award score for {" + type.toString() + "}"); logWarning("Unable to award score for {" + type.toString() + "}");
} }
@@ -190,4 +210,53 @@ public class MobScoresPlugin extends JavaPlugin {
public void logWarning(String message) { public void logWarning(String message) {
getLogger().warning(_logPrefix + message); getLogger().warning(_logPrefix + message);
} }
private boolean isVersionAtLeast(String version, String minimumVersion) {
int[] actual = parseVersion(version);
int[] minimum = parseVersion(minimumVersion);
if (actual == null || minimum == null) {
return false;
}
for (int index = 0; index < actual.length; index++) {
if (actual[index] != minimum[index]) {
return actual[index] > minimum[index];
}
}
return !isPrerelease(version);
}
private int[] parseVersion(String version) {
if (version == null) {
return null;
}
String coreVersion = version.replaceFirst("^[vV]", "");
int metadataIndex = coreVersion.indexOf('+');
if (metadataIndex >= 0) {
coreVersion = coreVersion.substring(0, metadataIndex);
}
int prereleaseIndex = coreVersion.indexOf('-');
if (prereleaseIndex >= 0) {
coreVersion = coreVersion.substring(0, prereleaseIndex);
}
String[] parts = coreVersion.split("\\.");
if (parts.length < 3) {
return null;
}
try {
return new int[] {
Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])
};
} catch (NumberFormatException ex) {
return null;
}
}
private boolean isPrerelease(String version) {
String release = version.replaceFirst("^[vV]", "");
int metadataIndex = release.indexOf('+');
if (metadataIndex >= 0) {
release = release.substring(0, metadataIndex);
}
return release.indexOf('-') >= 0;
}
} }