Added custom structures for Boxed. Fixed missing texts and place bug

This commit is contained in:
tastybento 2023-05-03 21:31:25 -07:00
parent 306df8b5fb
commit 7047565dca
13 changed files with 83 additions and 27 deletions

View File

@ -199,6 +199,14 @@
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/structures</directory>
<targetPath>./structures</targetPath>
<filtering>false</filtering>
<includes>
<include>*.nbt</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/locales</directory>
<targetPath>./locales</targetPath>
@ -230,6 +238,7 @@
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>blu</nonFilteredFileExtension>
<nonFilteredFileExtension>nbt</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>

View File

@ -57,10 +57,10 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
@Override
public void setup() {
this.setPermission("boxed.admin.place");
this.setPermission("boxed.commands.boxadmin.place");
this.setOnlyPlayer(false);
this.setParametersHelp("boxed.admin.place.parameters");
this.setDescription("boxed.admin.place.description");
this.setParametersHelp("boxed.commands.boxadmin.place.parameters");
this.setDescription("boxed.commands.boxadmin.place.description");
}
@ -73,7 +73,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
// Check world
if (!((Boxed)getAddon()).inWorld(getWorld())) {
user.sendMessage("boxed.admin.place.wrong-world");
user.sendMessage("boxed.commands.boxadmin.place.wrong-world");
return false;
}
/*
@ -92,7 +92,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
// First arg must always be the structure name
List<String> options = Bukkit.getStructureManager().getStructures().keySet().stream().map(k -> k.getKey()).toList();
if (!options.contains(args.get(0).toLowerCase(Locale.ENGLISH))) {
user.sendMessage("boxed.admin.place.unknown-structure");
user.sendMessage("boxed.commands.boxadmin.place.unknown-structure");
return false;
}
// If that is all we have, we're done
@ -103,7 +103,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
if ((!args.get(1).equals("~") && !Util.isInteger(args.get(1), true))
|| (!args.get(2).equals("~") && !Util.isInteger(args.get(2), true))
|| (!args.get(3).equals("~") && !Util.isInteger(args.get(3), true))) {
user.sendMessage("boxed.admin.place.use-integers");
user.sendMessage("boxed.commands.boxadmin.place.use-integers");
return false;
}
// If that is all we have, we're done
@ -113,7 +113,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
// But there is more!
sr = Enums.getIfPresent(StructureRotation.class, args.get(4).toUpperCase(Locale.ENGLISH)).orNull();
if (sr == null) {
user.sendMessage("boxed.admin.place.unknown-rotation");
user.sendMessage("boxed.commands.boxadmin.place.unknown-rotation");
Arrays.stream(StructureRotation.values()).map(StructureRotation::name).forEach(user::sendRawMessage);
return false;
}
@ -123,7 +123,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
// But there is more!
mirror = Enums.getIfPresent(Mirror.class, args.get(5).toUpperCase(Locale.ENGLISH)).orNull();
if (mirror == null) {
user.sendMessage("boxed.admin.place.unknown-mirror");
user.sendMessage("boxed.commands.boxadmin.place.unknown-mirror");
Arrays.stream(Mirror.values()).map(Mirror::name).forEach(user::sendRawMessage);
return false;
}
@ -131,7 +131,7 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
if (args.get(6).toUpperCase(Locale.ENGLISH).equals("NO_MOBS")) {
noMobs = true;
} else {
user.sendMessage("boxed.admin.place.unknown", TextVariables.LABEL, args.get(6).toUpperCase(Locale.ENGLISH));
user.sendMessage("boxed.commands.boxadmin.place.unknown", TextVariables.LABEL, args.get(6).toUpperCase(Locale.ENGLISH));
return false;
}
}
@ -151,9 +151,9 @@ public class AdminPlaceStructureCommand extends CompositeCommand {
NewAreaListener.removeJigsaw(new Item(tag.getKey(), s, spot, sr, mirror, noMobs));
boolean result = saveStructure(spot, tag, user, sr, mirror);
if (result) {
user.sendMessage("boxed.admin.place.saved");
user.sendMessage("boxed.commands.boxadmin.place.saved");
} else {
user.sendMessage("boxed.admin.place.failed");
user.sendMessage("boxed.commands.boxadmin.place.failed");
}
return result;
}

View File

@ -1,13 +1,15 @@
package world.bentobox.boxed.listeners;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Random;
@ -65,6 +67,7 @@ import world.bentobox.boxed.objects.IslandStructures;
public class NewAreaListener implements Listener {
private static final List<BlockFace> CARDINALS = List.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
private static final List<String> JAR_STRUCTURES = List.of("bee", "pillager", "polar_bear", "axolotl", "allay", "parrot", "frog");
private static final List<String> STRUCTURES = List.of("ancient_city", "bastion_remnant", "bastion",
"buried_treasure", "desert_pyramid", "end_city",
"fortress", "igloo", "jungle_pyramid", "mansion", "mineshaft", "mineshaft_mesa",
@ -100,6 +103,19 @@ public class NewAreaListener implements Listener {
handler = new Database<>(addon, IslandStructures.class);
// Try to build something every second
Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> BuildItem(), 20, 20);
// Experiment: TODO: read all files in from the structure folder including the ones saved from the jar file
for (String js : JAR_STRUCTURES) {
addon.saveResource("structures/" + js + ".nbt", false);
File structureFile = new File(addon.getDataFolder(), "structures/" + js + ".nbt");
try {
Bukkit.getStructureManager().loadStructure(structureFile);
addon.log("Loaded " + js + ".nbt");
} catch (IOException e) {
addon.logError("Error trying to load " + structureFile.getAbsolutePath());
e.printStackTrace();
}
}
}
private void BuildItem() {
@ -123,9 +139,8 @@ public class NewAreaListener implements Listener {
YamlConfiguration loader = YamlConfiguration.loadConfiguration(templateFile);
List<String> list = loader.getStringList("templates");
for (String struct : list) {
Structure s = Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString(struct));
if (s == null) {
//addon.log("Now loading group from: " + struct);
if (!struct.endsWith("/")) {
Bukkit.getStructureManager().loadStructure(NamespacedKey.fromString(struct));
}
}
}
@ -379,6 +394,11 @@ public class NewAreaListener implements Listener {
case "minecraft:village/common/animals" -> BUTCHER_ANIMALS.get(rand.nextInt(3));
default -> null;
};
// Boxed
if (type == null && bjb.getPool().startsWith("minecraft:boxed/")) {
String entString = bjb.getPool().toUpperCase(Locale.ENGLISH).substring(16, bjb.getPool().length());
type = Enums.getIfPresent(EntityType.class, entString).orNull();
}
// Villagers
if (bjb.getPool().contains("zombie/villagers")) {
type = EntityType.ZOMBIE_VILLAGER;

View File

@ -23,18 +23,18 @@ boxed:
parameters: '[home number]'
sethome:
parameters: '[home number]'
admin:
place:
description: "Place an area structure"
parameters: "<x> <y> <z> <rotation> <mirror> <no mobs>"
use-integers: "&c Coordinated must be integers"
wrong-world: "&c This command can only be used in a Boxed world"
unknown-structure: "&c Cannot place: Unknown structure"
unknown-rotation: "&c Cannot place: Unknown rotation type"
unknown-mirror: "&c Cannot place: Unknown mirror type"
saved: "&a Placed and saved to structures.yml"
failed: "&c Could not be saved to structures.yml. Check console for error"
unknown: "&c Unknown parameter: [label]"
boxadmin:
place:
description: Place an area structure
parameters: <x> <y> <z> <rotation> <mirror> <no mobs>
use-integers: '&c Coordinated must be integers'
wrong-world: '&c This command can only be used in a Boxed world'
unknown-structure: '&c Cannot place: Unknown structure'
unknown-rotation: '&c Cannot place: Unknown rotation type'
unknown-mirror: '&c Cannot place: Unknown mirror type'
saved: '&a Placed and saved to structures.yml'
failed: '&c Could not be saved to structures.yml. Check console for error'
unknown: '&c Unknown parameter: [label]'
island:
go:
parameters: '[home number]'

View File

@ -46,6 +46,26 @@ normal:
67,78,52: village/common/animals/horses_3,NONE,NONE
57,70,-90: village/common/animals/horses_5,NONE,NONE
62,70,-88: village/common/animals/horses_5,NONE,NONE
-2,66,10: boxed/frog,NONE,NONE
87,85,120: boxed/pillager,NONE,NONE
85,85,122: boxed/pillager,NONE,NONE
87,85,118: boxed/pillager,NONE,NONE
87,85,123: boxed/pillager,NONE,NONE
89,81,122: boxed/pillager,NONE,NONE
87,77,120: boxed/pillager,NONE,NONE
94,71,111: boxed/pillager,NONE,NONE
90,71,111: boxed/pillager,NONE,NONE
100,72,110: pillager_outpost/feature_tent1,NONE,NONE
-20,63,-24: boxed/parrot,NONE,NONE
-21,65,-21: boxed/parrot,NONE,NONE
1,69,-12: boxed/frog,NONE,NONE
2,67,10: boxed/parrot,NONE,NONE
-58,64,13: boxed/polar_bear,NONE,NONE
-90,63,57: boxed/polar_bear,NONE,NONE
-87,63,63: boxed/polar_bear,NONE,NONE
-33,69,58: boxed/polar_bear,NONE,NONE
137,-8,11: boxed/axolotl,NONE,NONE
137,-8,9: boxed/axolotl,NONE,NONE
nether:
16,32,0: bastion/bridge/starting_pieces/entrance

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,11 @@
templates:
- boxed/frog
- boxed/allay
- boxed/bee
- boxed/axolotl
- boxed/pillager
- boxed/polar_bear
- boxed/parrot
- ancient_city/city/entrance/entrance_connector
- ancient_city/city/entrance/entrance_path_1
- ancient_city/city/entrance/entrance_path_2