Skip to content

Commit

Permalink
Added custom structures for Boxed. Fixed missing texts and place bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed May 4, 2023
1 parent 306df8b commit 7047565
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 27 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -230,6 +238,7 @@
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>blu</nonFilteredFileExtension>
<nonFilteredFileExtension>nbt</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public AdminPlaceStructureCommand(CompositeCommand parent) {

@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");


}
Expand All @@ -73,7 +73,7 @@ public boolean canExecute(User user, String label, List<String> args) {

// Check world
if (!((Boxed)getAddon()).inWorld(getWorld())) {
user.sendMessage("boxed.admin.place.wrong-world");
user.sendMessage("boxed.commands.boxadmin.place.wrong-world");
return false;
}
/*
Expand All @@ -92,7 +92,7 @@ public boolean canExecute(User user, String label, List<String> args) {
// 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
Expand All @@ -103,7 +103,7 @@ public boolean canExecute(User user, String label, List<String> args) {
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
Expand All @@ -113,7 +113,7 @@ public boolean canExecute(User user, String label, List<String> args) {
// 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;
}
Expand All @@ -123,15 +123,15 @@ public boolean canExecute(User user, String label, List<String> args) {
// 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;
}
if (args.size() == 7) {
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;
}
}
Expand All @@ -151,9 +151,9 @@ public boolean execute(User user, String label, List<String> args) {
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;
}
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/world/bentobox/boxed/listeners/NewAreaListener.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -65,6 +67,7 @@
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",
Expand Down Expand Up @@ -100,6 +103,19 @@ public NewAreaListener(Boxed addon) {
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() {
Expand All @@ -123,9 +139,8 @@ public void onBentoBoxReady(BentoBoxReadyEvent event) {
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));
}
}
}
Expand Down Expand Up @@ -379,6 +394,11 @@ private static void spawnMob(Block b, BoxedJigsawBlock bjb) {
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;
Expand Down
24 changes: 12 additions & 12 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/structures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added src/main/resources/structures/allay.nbt
Binary file not shown.
Binary file added src/main/resources/structures/axolotl.nbt
Binary file not shown.
Binary file added src/main/resources/structures/bee.nbt
Binary file not shown.
Binary file added src/main/resources/structures/frog.nbt
Binary file not shown.
Binary file added src/main/resources/structures/parrot.nbt
Binary file not shown.
Binary file added src/main/resources/structures/pillager.nbt
Binary file not shown.
Binary file added src/main/resources/structures/polar_bear.nbt
Binary file not shown.
7 changes: 7 additions & 0 deletions src/main/resources/templates.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7047565

Please sign in to comment.