Skip to content

Commit 81152e3

Browse files
author
david
committed
adapted changes
1 parent eb40efa commit 81152e3

File tree

10 files changed

+60
-82
lines changed

10 files changed

+60
-82
lines changed

src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import net.thenextlvl.gopaint.api.brush.BrushController;
1717
import net.thenextlvl.gopaint.api.brush.BrushRegistry;
1818
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
19-
import net.thenextlvl.gopaint.api.model.MaskMode;
2019
import net.thenextlvl.gopaint.api.model.PluginConfig;
2120
import net.thenextlvl.gopaint.api.model.SurfaceMode;
2221
import net.thenextlvl.gopaint.brush.CraftBrushController;
@@ -57,7 +56,7 @@ public class GoPaintPlugin extends JavaPlugin implements GoPaintProvider {
5756

5857
private final FileIO<PluginConfig> configFile = new GsonFile<>(IO.of(getDataFolder(), "config.json"), new PluginConfig(
5958
new PluginConfig.BrushConfig(Material.FEATHER, new NamespacedKey("gopaint", "sphere_brush"), 100, 10, 50,
60-
Axis.Y, 50, 50, Set.of("disabled"), true, Material.SPONGE, MaskMode.INTERFACE, SurfaceMode.DIRECT,
59+
Axis.Y, 50, 50, Set.of("disabled"), true, Material.SPONGE, true, SurfaceMode.EXPOSED,
6160
List.of(Material.STONE)),
6261
new PluginConfig.ThicknessConfig(1, 5),
6362
new PluginConfig.AngleConfig(2, 5, 10, 40, 85),

src/main/java/net/thenextlvl/gopaint/brush/CraftBrushController.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import net.thenextlvl.gopaint.api.brush.BrushController;
2525
import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings;
2626
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
27-
import net.thenextlvl.gopaint.api.model.MaskMode;
2827
import net.thenextlvl.gopaint.api.model.SurfaceMode;
2928
import net.thenextlvl.gopaint.brush.setting.CraftItemBrushSettings;
3029
import net.thenextlvl.gopaint.brush.setting.CraftPlayerBrushSettings;
@@ -61,10 +60,7 @@ public Optional<ItemBrushSettings> parseBrushSettings(ItemMeta itemMeta) {
6160
var container = itemMeta.getPersistentDataContainer();
6261

6362
var brushSize = container.get(new NamespacedKey("gopaint", "size"), PersistentDataType.INTEGER);
64-
65-
var maskMode = Optional.ofNullable(container.get(new NamespacedKey("gopaint", "mask_mode"), PersistentDataType.STRING))
66-
.map(MaskMode::valueOf)
67-
.orElse(null);
63+
var maskEnabled = container.get(new NamespacedKey("gopaint", "mask_enabled"), PersistentDataType.BOOLEAN);
6864

6965
var surfaceMode = Optional.ofNullable(container.get(new NamespacedKey("gopaint", "surface_mode"), PersistentDataType.STRING))
7066
.map(SurfaceMode::valueOf)
@@ -75,7 +71,7 @@ public Optional<ItemBrushSettings> parseBrushSettings(ItemMeta itemMeta) {
7571
.flatMap(plugin.brushRegistry()::getBrush)
7672
.orElse(null);
7773

78-
if (brushSize == null || maskMode == null || surfaceMode == null || brush == null)
74+
if (brushSize == null || maskEnabled == null || surfaceMode == null || brush == null)
7975
return Optional.empty();
8076

8177
var chance = container.getOrDefault(new NamespacedKey("gopaint", "chance"), PersistentDataType.INTEGER, 0);
@@ -92,7 +88,7 @@ public Optional<ItemBrushSettings> parseBrushSettings(ItemMeta itemMeta) {
9288
.orElse(Axis.Y);
9389
var mask = Optional.ofNullable(container.get(new NamespacedKey("gopaint", "mask"), PersistentDataType.STRING))
9490
.map(Material::matchMaterial)
95-
.orElse(null);
91+
.orElseThrow();
9692
var blocks = Optional.ofNullable(container.get(new NamespacedKey("gopaint", "blocks"), PersistentDataType.STRING))
9793
.map(string -> string.split(","))
9894
.stream()
@@ -103,7 +99,7 @@ public Optional<ItemBrushSettings> parseBrushSettings(ItemMeta itemMeta) {
10399

104100
return Optional.of(CraftItemBrushSettings.builder()
105101
.brushSize(brushSize)
106-
.maskMode(maskMode)
102+
.maskEnabled(maskEnabled)
107103
.surfaceMode(surfaceMode)
108104
.brush(brush)
109105
.chance(chance)

src/main/java/net/thenextlvl/gopaint/brush/CraftBrushRegistry.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.google.common.base.Preconditions;
44
import net.kyori.adventure.key.Key;
55
import net.thenextlvl.gopaint.GoPaintPlugin;
6-
import net.thenextlvl.gopaint.api.brush.Brush;
6+
import net.thenextlvl.gopaint.api.brush.PatternBrush;
77
import net.thenextlvl.gopaint.api.brush.BrushRegistry;
88
import net.thenextlvl.gopaint.brush.standard.*;
99

@@ -13,7 +13,7 @@
1313
import java.util.stream.Stream;
1414

1515
public class CraftBrushRegistry implements BrushRegistry {
16-
private final List<Brush> brushes = new LinkedList<>();
16+
private final List<PatternBrush> brushes = new LinkedList<>();
1717

1818
public CraftBrushRegistry(GoPaintPlugin plugin) {
1919
registerBrush(new SphereBrush(plugin));
@@ -30,28 +30,28 @@ public CraftBrushRegistry(GoPaintPlugin plugin) {
3030
}
3131

3232
@Override
33-
public Stream<Brush> getBrushes() {
33+
public Stream<PatternBrush> getBrushes() {
3434
return brushes.stream().sorted();
3535
}
3636

3737
@Override
38-
public boolean isRegistered(Brush brush) {
38+
public boolean isRegistered(PatternBrush brush) {
3939
return brushes.contains(brush);
4040
}
4141

4242
@Override
43-
public void registerBrush(Brush brush) throws IllegalStateException {
43+
public void registerBrush(PatternBrush brush) throws IllegalStateException {
4444
Preconditions.checkState(!isRegistered(brush), "Brush already registered");
4545
brushes.add(brush);
4646
}
4747

4848
@Override
49-
public void unregisterBrush(Brush brush) throws IllegalStateException {
49+
public void unregisterBrush(PatternBrush brush) throws IllegalStateException {
5050
if (!brushes.remove(brush)) throw new IllegalStateException("Brush not registered");
5151
}
5252

5353
@Override
54-
public Optional<Brush> getBrush(Key key) {
54+
public Optional<PatternBrush> getBrush(Key key) {
5555
return brushes.stream()
5656
.filter(brush -> brush.key().equals(key))
5757
.findAny();

src/main/java/net/thenextlvl/gopaint/brush/setting/CraftPlayerBrushSettings.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import net.kyori.adventure.text.JoinConfiguration;
2626
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
2727
import net.thenextlvl.gopaint.GoPaintPlugin;
28-
import net.thenextlvl.gopaint.api.brush.Brush;
28+
import net.thenextlvl.gopaint.api.brush.PatternBrush;
2929
import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings;
3030
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
3131
import net.thenextlvl.gopaint.api.model.SurfaceMode;
@@ -66,7 +66,7 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings {
6666
private boolean maskEnabled;
6767
private SurfaceMode surfaceMode;
6868

69-
private Brush brush;
69+
private PatternBrush brush;
7070
private Material mask;
7171
private final List<Material> blocks = new ArrayList<>();
7272

@@ -130,7 +130,7 @@ public void removeBlock(int slot) {
130130
}
131131

132132
@Override
133-
public void setBrush(Brush brush) {
133+
public void setBrush(PatternBrush brush) {
134134
this.brush = brush;
135135
mainMenu.updateBrush();
136136
}
@@ -216,7 +216,7 @@ public void setFractureStrength(@Range(from = 1, to = Integer.MAX_VALUE) int fra
216216
}
217217

218218
@Override
219-
public Brush getNextBrush(@Nullable Brush brush) {
219+
public PatternBrush getNextBrush(@Nullable PatternBrush brush) {
220220
var brushes = plugin.brushRegistry().getBrushes().toList();
221221
if (brush == null) return brushes.getFirst();
222222
int next = brushes.indexOf(brush) + 1;
@@ -225,7 +225,7 @@ public Brush getNextBrush(@Nullable Brush brush) {
225225
}
226226

227227
@Override
228-
public Brush getPreviousBrush(@Nullable Brush brush) {
228+
public PatternBrush getPreviousBrush(@Nullable PatternBrush brush) {
229229
var brushes = plugin.brushRegistry().getBrushes().toList();
230230
if (brush == null) return brushes.getFirst();
231231
int back = brushes.indexOf(brush) - 1;

src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import net.kyori.adventure.key.Key;
1212
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1313
import net.thenextlvl.gopaint.GoPaintPlugin;
14-
import net.thenextlvl.gopaint.api.brush.Brush;
14+
import net.thenextlvl.gopaint.api.brush.PatternBrush;
1515
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
1616
import org.bukkit.entity.Player;
1717

@@ -36,7 +36,7 @@ public void register() {
3636
.then(Commands.argument("brush", ArgumentTypes.key())
3737
.suggests((context, builder) -> {
3838
plugin.brushRegistry().getBrushes()
39-
.map(Brush::key)
39+
.map(PatternBrush::key)
4040
.map(Key::asString)
4141
.filter(key -> key.contains(builder.getRemaining()))
4242
.forEach(builder::suggest);

src/main/java/net/thenextlvl/gopaint/listener/InventoryListener.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import lombok.RequiredArgsConstructor;
2222
import net.thenextlvl.gopaint.GoPaintPlugin;
23-
import net.thenextlvl.gopaint.api.model.MaskMode;
2423
import net.thenextlvl.gopaint.api.model.SurfaceMode;
2524
import net.thenextlvl.gopaint.brush.standard.*;
2625
import net.thenextlvl.gopaint.menu.MainMenu;
@@ -150,16 +149,12 @@ public void menuClick(InventoryClickEvent event) {
150149
settings.setBrushSize(settings.getBrushSize() - 10);
151150
}
152151
} else if (event.getRawSlot() == 15 || event.getRawSlot() == 6 || event.getRawSlot() == 24) {
153-
settings.setMaskMode(switch (settings.getMaskMode()) {
154-
case INTERFACE -> MaskMode.WORLDEDIT;
155-
case WORLDEDIT -> MaskMode.DISABLED;
156-
case DISABLED -> MaskMode.INTERFACE;
157-
});
152+
settings.setMaskEnabled(!settings.isMaskEnabled());
158153
} else if (event.getRawSlot() == 16 || event.getRawSlot() == 7 || event.getRawSlot() == 25) {
159154
settings.setSurfaceMode(switch (settings.getSurfaceMode()) {
160-
case DIRECT -> SurfaceMode.RELATIVE;
161-
case RELATIVE -> SurfaceMode.DISABLED;
162-
case DISABLED -> SurfaceMode.DIRECT;
155+
case EXPOSED -> SurfaceMode.VISIBLE;
156+
case VISIBLE -> SurfaceMode.DISABLED;
157+
case DISABLED -> SurfaceMode.EXPOSED;
163158
});
164159
} else if ((event.getRawSlot() >= 37 && event.getRawSlot() <= 41)
165160
|| (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) {

src/main/java/net/thenextlvl/gopaint/menu/BrushesMenu.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import lombok.Getter;
77
import net.kyori.adventure.text.Component;
88
import net.kyori.adventure.text.format.NamedTextColor;
9-
import net.thenextlvl.gopaint.api.brush.Brush;
9+
import net.thenextlvl.gopaint.api.brush.PatternBrush;
1010
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
1111
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
1212
import org.bukkit.Material;
@@ -15,7 +15,7 @@
1515
import java.util.Collection;
1616
import java.util.stream.IntStream;
1717

18-
public class BrushesMenu extends PagedGUI<GoPaintProvider, Brush> {
18+
public class BrushesMenu extends PagedGUI<GoPaintProvider, PatternBrush> {
1919
private final @Getter Options options = new Options(
2020
IntStream.range(0, getSize() - 9).toArray(),
2121
getSize() - 6,
@@ -36,7 +36,7 @@ public void formatDefault() {
3636
}
3737

3838
@Override
39-
public ActionItem constructItem(Brush brush) {
39+
public ActionItem constructItem(PatternBrush brush) {
4040
return new ItemBuilder(Material.PLAYER_HEAD)
4141
.headValue(brush.getHeadValue())
4242
.itemName(brush.getName(owner).color(NamedTextColor.GOLD))
@@ -54,7 +54,7 @@ public Component getPageFormat(int page) {
5454
}
5555

5656
@Override
57-
public Collection<Brush> getElements() {
57+
public Collection<PatternBrush> getElements() {
5858
return plugin.brushRegistry().getBrushes().toList();
5959
}
6060
}

src/main/java/net/thenextlvl/gopaint/menu/MainMenu.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public MainMenu(GoPaintPlugin plugin, PlayerBrushSettings settings, Player owner
3737
updateToggle();
3838
updateBrush();
3939
updateSize();
40-
updateMaskMode();
40+
updateMaskToggle();
4141
updateSurfaceMode();
4242
updateBlockPalette();
4343
updateMask();
@@ -235,48 +235,37 @@ public void updateToggle() {
235235
inventory.setItem(19, placeholder);
236236
}
237237

238-
public void updateMaskMode() {
239-
var icon = switch (settings.getMaskMode()) {
240-
case DISABLED -> Material.CARVED_PUMPKIN;
241-
case INTERFACE -> Material.JACK_O_LANTERN;
242-
case WORLDEDIT -> Material.WOODEN_AXE;
243-
};
238+
public void updateMaskToggle() {
239+
var icon = settings.isMaskEnabled() ? Material.JACK_O_LANTERN : Material.CARVED_PUMPKIN;
244240

245-
var mode = plugin.bundle().component(owner, settings.getMaskMode().translationKey())
246-
.color(switch (settings.getMaskMode()) {
247-
case DISABLED -> NamedTextColor.RED;
248-
case INTERFACE -> NamedTextColor.GREEN;
249-
case WORLDEDIT -> NamedTextColor.GOLD;
250-
});
241+
var state = plugin.bundle().component(owner, settings.isMaskEnabled() ? "mask.enabled" : "mask.disabled")
242+
.color(settings.isMaskEnabled() ? NamedTextColor.GREEN : NamedTextColor.RED);
251243

252244
inventory.setItem(15, new ItemBuilder(icon)
253-
.itemName(plugin.bundle().component(owner, "mask.mode"))
254-
.lore(plugin.bundle().components(owner, "mask.mode.description",
255-
Placeholder.component("mode", mode)))
245+
.itemName(plugin.bundle().component(owner, "mask.state"))
246+
.lore(plugin.bundle().components(owner, "mask.state.description",
247+
Placeholder.component("state", state)))
256248
.itemFlags(ItemFlag.HIDE_ATTRIBUTES));
257249

258-
var placeholder = new ItemBuilder(switch (settings.getMaskMode()) {
259-
case DISABLED -> Material.RED_STAINED_GLASS_PANE;
260-
case INTERFACE -> Material.LIME_STAINED_GLASS_PANE;
261-
case WORLDEDIT -> Material.ORANGE_STAINED_GLASS_PANE;
262-
}).hideTooltip(true);
250+
var pane = settings.isMaskEnabled() ? Material.LIME_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE;
251+
var placeholder = new ItemBuilder(pane).hideTooltip(true);
263252

264253
inventory.setItem(6, placeholder);
265254
inventory.setItem(24, placeholder);
266255
}
267256

268257
public void updateSurfaceMode() {
269258
var icon = switch (settings.getSurfaceMode()) {
270-
case DIRECT -> Material.LIGHT_WEIGHTED_PRESSURE_PLATE;
259+
case EXPOSED -> Material.LIGHT_WEIGHTED_PRESSURE_PLATE;
271260
case DISABLED -> Material.POLISHED_BLACKSTONE_PRESSURE_PLATE;
272-
case RELATIVE -> Material.HEAVY_WEIGHTED_PRESSURE_PLATE;
261+
case VISIBLE -> Material.HEAVY_WEIGHTED_PRESSURE_PLATE;
273262
};
274263

275264
var mode = plugin.bundle().component(owner, settings.getSurfaceMode().translationKey())
276265
.color(switch (settings.getSurfaceMode()) {
277-
case DIRECT -> NamedTextColor.GREEN;
266+
case EXPOSED -> NamedTextColor.GREEN;
278267
case DISABLED -> NamedTextColor.RED;
279-
case RELATIVE -> NamedTextColor.GOLD;
268+
case VISIBLE -> NamedTextColor.GOLD;
280269
});
281270

282271
inventory.setItem(16, new ItemBuilder(icon)
@@ -286,9 +275,9 @@ public void updateSurfaceMode() {
286275
.itemFlags(ItemFlag.HIDE_ATTRIBUTES));
287276

288277
var placeholder = new ItemBuilder(switch (settings.getSurfaceMode()) {
289-
case DIRECT -> Material.LIME_STAINED_GLASS_PANE;
278+
case EXPOSED -> Material.LIME_STAINED_GLASS_PANE;
290279
case DISABLED -> Material.RED_STAINED_GLASS_PANE;
291-
case RELATIVE -> Material.ORANGE_STAINED_GLASS_PANE;
280+
case VISIBLE -> Material.ORANGE_STAINED_GLASS_PANE;
292281
}).hideTooltip(true);
293282

294283
inventory.setItem(7, placeholder);

src/main/resources/messages.properties

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
prefix=<aqua>goPaint><reset>
1+
prefix=<aqua>goPaint ><reset>
22
command.gopaint.brush.disabled=<prefix> <red>Disabled brush
33
command.gopaint.brush.enabled=<prefix> <green>Enabled brush
44
command.gopaint.brush.size=<prefix> <gold>Brush size set to: <yellow><size>
55
command.gopaint.reloaded=<prefix> <green>Reloaded
6+
brush.block.sight=<prefix> <red>There is no block in sight.
67
brush.disabled=<prefix> <red>Your brush is disabled, left click to enable the brush or type <white>/gp toggle<red>.
78
brush.paint.point.set=<prefix> <white>Paint brush point #<point> set.
89
brush.state.enabled=<green>Enabled
@@ -14,15 +15,14 @@ brush.toggle.description=<!i><b><state><newline><newline>\
1415
<!i><gray>Click without an item to toggle
1516
menu.main.title=<dark_blue>goPaint Menu
1617
menu.brushes.title=<dark_blue>goPaint Brushes
17-
mask.mode.disabled=Disabled
18-
mask.mode.interface=Interface
19-
mask.mode.worldedit=WorldEdit
20-
mask.mode=<gold>Mask Mode
21-
mask.mode.description=<!i><b><mode><newline><newline>\
18+
mask.enabled=Enabled
19+
mask.disabled=Disabled
20+
mask.state=<gold>Mask
21+
mask.state.description=<!i><b><state><newline><newline>\
2222
<!i><gray>Click to cycle
23-
surface.mode.direct=Direct
2423
surface.mode.disabled=Disabled
25-
surface.mode.relative=Relative
24+
surface.mode.exposed=Exposed
25+
surface.mode.visible=Visible
2626
surface.mode=<gold>Surface Mode
2727
surface.mode.description=<!i><b><mode><newline><newline>\
2828
<!i><gray>Click to cycle
@@ -67,7 +67,8 @@ slot.set.description=<newline>\
6767
<!i><gray>Right click to clear
6868
mask.block=<gold>Current Mask
6969
mask.block.description=<newline>\
70-
<!i><gray>Click with a block to change
70+
<!i><gray>Click with a block to change<newline>\
71+
<!i><gray>Right click to clear
7172
brush.size=<gold>Brush Size: <yellow><size>
7273
brush.size.description=<newline>\
7374
<!i><gray>Left click to increase<newline>\
@@ -155,6 +156,5 @@ brush.exported.falloff=<!i><dark_gray>Falloff strength: <falloff>
155156
brush.exported.mixing=<!i><dark_gray>Mixing strength: <mixing>
156157
brush.exported.fracture=<!i><dark_gray>Fracture strength: <fracture>
157158
brush.exported.blocks=<!i><dark_gray>Blocks: <blocks>
158-
brush.exported.mask-mode=<!i><dark_gray>Mask mode: <mode>
159159
brush.exported.surface-mode=<!i><dark_gray>Surface mode: <mode>
160160
brush.exported.mask=<!i><dark_gray>Mask: <mask>

0 commit comments

Comments
 (0)