Adds auto scoring for advancements

Gives higher scores thus enabling bigger boxes.
This commit is contained in:
tastybento 2023-03-25 17:14:05 -07:00
parent b8778bcf3a
commit 5c3d40a3ad
8 changed files with 1260 additions and 955 deletions

View File

@ -146,6 +146,11 @@
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>plugin-annotations</artifactId>
<version>1.2.3-SNAPSHOT</version>
</dependency>
<!-- Mockito (Unit testing) -->
<dependency>
<groupId>org.mockito</groupId>

View File

@ -7,6 +7,8 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.advancement.Advancement;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@ -63,7 +65,18 @@ public class AdvancementsManager {
addon.logError("advancements.yml cannot be found! " + e.getLocalizedMessage());
}
}
/*
// DEBUG - lists all advancements to console
int scoreTotal = 0;
Iterator<Advancement> ad = Bukkit.getServer().advancementIterator();
while (ad.hasNext()) {
Advancement a = ad.next();
int score = getScore(a);
BentoBox.getInstance().logDebug(" 'minecraft:" + a.getKey().getKey() + "': " + score);
scoreTotal += score;
}
BentoBox.getInstance().logDebug("Sum total = " + scoreTotal);
*/
}
/**
@ -176,7 +189,7 @@ public class AdvancementsManager {
// Wrong world
return 0;
}
int score = getScore(advancement.getKey().toString());
int score = getScore(advancement);
if (score == 0) {
return 0;
}
@ -215,24 +228,45 @@ public class AdvancementsManager {
}
/**
* Get the score for this advancement
* @param string - advancement key as stored in the config file
* @return score of advancement, or default values if the key is not in the file
* Get the score for this advancement namespace key
* @param key advancement namespace key
* @return score or 0 if this key is unknown.
*/
public int getScore(String string) {
String adv = "advancements." + string;
// Check score of advancement
if (advConfig.contains(adv)) {
return advConfig.getInt(adv, this.unknownAdvChange);
}
public int getScore(String key) {
Advancement a = Bukkit.getAdvancement(NamespacedKey.fromString(key));
return a == null ? 0 : getScore(a);
}
/**
* Get the score for this advancement
* @param a - advancement
* @return score of advancement, or 0 if cannot be worked out
*/
public int getScore(Advancement a) {
String adv = "advancements." + a.getKey().getKey();
// Unknowns
if (adv.endsWith("/root")) {
return advConfig.getInt("settings.default-root-increase");
}
if (adv.contains("minecraft:recipes")) {
if (adv.contains("recipes")) {
return this.unknownRecipeChange;
}
return this.unknownAdvChange;
if (advConfig.getBoolean("settings.automatic-scoring")) {
if (!a.getKey().getKey().contains("recipes") && a.getDisplay() != null) {
float x = a.getDisplay().getX();
float y = a.getDisplay().getY();
int score = (int) Math.round(Math.sqrt(x * x + y * y));
return score;
} else {
return 0;
}
} else {
if (advConfig.contains(adv)) {
return advConfig.getInt(adv, this.unknownAdvChange);
}
return this.unknownAdvChange;
}
}
}

View File

@ -1,8 +1,13 @@
package world.bentobox.boxed;
import org.bukkit.plugin.java.annotation.plugin.ApiVersion;
import org.bukkit.plugin.java.annotation.plugin.Plugin;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.Pladdon;
@Plugin(name="Boxed", version="1.0")
@ApiVersion(ApiVersion.Target.v1_17)
public class BoxedPladdon extends Pladdon {
@Override

View File

@ -51,6 +51,10 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
@Override
public boolean canExecute(User user, String label, List<String> args) {
// Initialize
sr = StructureRotation.NONE;
mirror = Mirror.NONE;
// Check world
if (!((Boxed)getAddon()).inWorld(getWorld())) {
user.sendMessage("boxed.admin.place.wrong-world");
@ -119,7 +123,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
int z = args.size() == 1 || args.get(3).equals("~") ? user.getLocation().getBlockZ() : Integer.valueOf(args.get(3).trim());
Location spot = new Location(user.getWorld(), x, y, z);
s.place(spot, true, sr, mirror, -1, 1, new Random());
NewAreaListener.removeJigsaw(spot, s, sr);
NewAreaListener.removeJigsaw(spot, s, sr, tag.getKey());
saveStructure(spot, tag, user, sr, mirror);
return true;
}

View File

@ -179,23 +179,23 @@ public class NewAreaListener implements Listener {
}
}
private void LoadChunksAsync(Item item) {
pasting = true;
item.structure().place(item.location(), true, item.rot(), item.mirror(), -1, 1, new Random());
addon.log(item.name() + " placed at " + item.location().getWorld().getName() + " " + Util.xyz(item.location().toVector()));
// Find it
removeJigsaw(item.location(), item.structure(), item.rot());
removeJigsaw(item.location(), item.structure(), item.rot(), item.name());
pasting = false;
}
/**
* Removes Jigsaw blocks from a placed structure
* Removes Jigsaw blocks from a placed structure. Fills underwater ruins with water.
* @param loc - location where the structure was placed
* @param structure - structure that was placed
* @param structureRotation - rotation of structure
* @param key
*/
public static void removeJigsaw(Location loc, Structure structure, StructureRotation structureRotation) {
public static void removeJigsaw(Location loc, Structure structure, StructureRotation structureRotation, String key) {
Location otherCorner = switch (structureRotation) {
case CLOCKWISE_180 -> loc.clone().add(new Vector(-structure.getSize().getX(), structure.getSize().getY(), -structure.getSize().getZ()));
@ -219,6 +219,10 @@ public class NewAreaListener implements Listener {
} else if (b.getType().equals(Material.STRUCTURE_BLOCK)) {
processStructureBlock(b);
}
// Set water blocks for underwater ruins
if (key.contains("underwater_ruin") && b.getType().equals(Material.AIR)) {
b.setType(Material.WATER);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
name: Pladdon
main: world.bentobox.boxed.BoxedPladdon
version: ${version}
api-version: 1.17
description: Minecraft in a box
author: tastybento
depend:
- BentoBox

View File

@ -5,7 +5,8 @@ normal:
-17,56,0: shipwreck/rightsideup_full_degraded,CLOCKWISE_180
16,67,13: village/plains/houses/plains_cartographer_1
-66,63,17: igloo/top
-34,52,-35: underwater_ruin/warm_1
-34,52,-35: underwater_ruin/warm_2
-25,46,-61: underwater_ruin/big_warm_4,COUNTERCLOCKWISE_90,NONE
33,69,-34: village/savanna/town_centers/savanna_meeting_point_1
26,70,-41: village/savanna/houses/savanna_medium_house_2,NONE,NONE
42,69,-21: village/savanna/houses/savanna_large_farm_2,NONE,NONE
@ -28,6 +29,11 @@ normal:
-26,70,33: village/snowy/houses/snowy_library_1,CLOCKWISE_180,NONE
-31,71,30: village/plains/villagers/unemployed,CLOCKWISE_180,NONE
-3,65,84: village/plains/villagers/unemployed,CLOCKWISE_180,NONE
-50,71,50: village/snowy/houses/snowy_medium_house_2,COUNTERCLOCKWISE_90,NONE
-52,72,33: village/snowy/houses/snowy_farm_1,COUNTERCLOCKWISE_90,NONE
-28,63,47: village/snowy/snowy_lamp_post_01,COUNTERCLOCKWISE_90,NONE
-6,64,52: village/snowy/houses/snowy_small_house_3,COUNTERCLOCKWISE_90,NONE
40,73,-3: village/savanna/houses/savanna_small_house_1,CLOCKWISE_180
nether:
16,32,0: bastion/bridge/starting_pieces/entrance