Skip to content

Commit 1bac459

Browse files
add an option to add markers instantly on banner place
closes #5 typos
1 parent 1905eff commit 1bac459

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/main/java/dev/nincodedo/bluemapbanners/BlueMapBanners.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public void onInitialize() {
6565
}
6666

6767
private ActionResult useBlock(PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) {
68-
if (player.isSpectator() || player.getMainHandStack().isEmpty() && player.getOffHandStack().isEmpty()) {
68+
if (player.isSpectator() ||
69+
(player.getMainHandStack().isEmpty() && player.getOffHandStack().isEmpty()) ||
70+
ConfigManager.getInstance().getBoolConfig("markerAddInstantOnBannerPlace")) {
6971
return ActionResult.PASS;
7072
}
7173
if (player.getMainHandStack().isOf(Items.MAP) || player.getOffHandStack().isOf(Items.MAP) || player.getMainHandStack().isOf(Items.FILLED_MAP) || player.getOffHandStack().isOf(Items.FILLED_MAP)) {

src/main/java/dev/nincodedo/bluemapbanners/ConfigManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ public ConfigManager()
2828
{
2929
this.configFilePath = FabricLoader.getInstance().getConfigDir().resolve( "bluemap-banners/bluemap-banners.properties" ).toString();
3030

31-
// Initialize hashtable with default values
31+
// Initialize the hashtable with default values
3232
defaultConfig.put("notifyPlayerOnBannerPlace", "true");
3333
defaultConfig.put("notifyPlayerOnMarkerAdd", "true");
3434
defaultConfig.put("notifyPlayerOnMarkerRemove", "true");
3535
defaultConfig.put("notifyGlobalOnMarkerRemove", "false");
36+
defaultConfig.put("markerAddInstantOnBannerPlace", "false");
3637
defaultConfig.put("markerMaxViewDistance", "10000000");
3738
defaultConfig.put("bluemapUrl", "https://your-url-to-bluemap.com/");
3839

@@ -70,7 +71,7 @@ private void readConfigFile() {
7071

7172
public void updateConfigFile() {
7273
try {
73-
// read current file and save found configs
74+
// read the current file and save found configs
7475
String line;
7576
StringBuilder stringBuilder = new StringBuilder();
7677
BufferedReader fileIn = new BufferedReader(new FileReader(this.configFilePath));
@@ -106,7 +107,7 @@ public void updateConfigFile() {
106107
}
107108

108109
public void initialConfigFile() {
109-
// Create config folder if not exist
110+
// Create the config folder if not exist
110111
try {
111112
Files.createDirectories(FabricLoader.getInstance().getConfigDir());
112113
} catch (IOException e) {

src/main/java/dev/nincodedo/bluemapbanners/mixin/BlockItemMixin.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package dev.nincodedo.bluemapbanners.mixin;
22

33
import dev.nincodedo.bluemapbanners.ConfigManager;
4+
import dev.nincodedo.bluemapbanners.MarkerManager;
45
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.entity.BannerBlockEntity;
57
import net.minecraft.entity.player.PlayerEntity;
68
import net.minecraft.item.BlockItem;
79
import net.minecraft.item.ItemStack;
@@ -23,8 +25,26 @@ public class BlockItemMixin {
2325
@Inject(at = @At("HEAD"), method = "postPlacement")
2426
public void onPlaceInject(BlockPos pos, World world, PlayerEntity player, ItemStack stack, BlockState state, CallbackInfoReturnable<Boolean> cir) {
2527
if (state.isIn(BlockTags.BANNERS)) {
26-
if (ConfigManager.getInstance().getBoolConfig("notifyPlayerOnBannerPlace")) {
27-
player.sendMessage(Text.literal("[BlueMap Banners] Use a map item on the banner to add a marker on the ").append(Text.literal("web map").setStyle(Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(ConfigManager.getInstance().getConfig("bluemapUrl")))).withUnderline(true))).append(Text.of(".")), false);
28+
MarkerManager markerManager = MarkerManager.getInstance();
29+
ConfigManager configManager = ConfigManager.getInstance();
30+
if (configManager.getBoolConfig("markerAddInstantOnBannerPlace")) {
31+
BannerBlockEntity bannerBlockEntity = (BannerBlockEntity) world.getBlockEntity(pos);
32+
if (bannerBlockEntity != null && !markerManager.doesMarkerExist(bannerBlockEntity)) {
33+
String name;
34+
if (bannerBlockEntity.getCustomName() != null) {
35+
name = bannerBlockEntity.getCustomName().getString();
36+
} else {
37+
String blockTranslationKey = state.getBlock().getTranslationKey();
38+
name = Text.translatable(blockTranslationKey).getString();
39+
}
40+
markerManager.addMarker(bannerBlockEntity, name);
41+
if (configManager.getBoolConfig("notifyPlayerOnMarkerAdd"))
42+
player.sendMessage(Text.literal("[BlueMap Banners] You added a marker to the ").append(Text.literal("web map").setStyle(Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(ConfigManager.getInstance().getConfig("bluemapUrl")))).withUnderline(true))).append(Text.of(".")), false);
43+
}
44+
} else {
45+
if (configManager.getBoolConfig("notifyPlayerOnBannerPlace")) {
46+
player.sendMessage(Text.literal("[BlueMap Banners] Use a map item on the banner to add a marker on the ").append(Text.literal("web map").setStyle(Style.EMPTY.withClickEvent(new ClickEvent.OpenUrl(URI.create(ConfigManager.getInstance().getConfig("bluemapUrl")))).withUnderline(true))).append(Text.of(".")), false);
47+
}
2848
}
2949
}
3050
}

0 commit comments

Comments
 (0)