Skip to content

Commit

Permalink
adapted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Jun 30, 2024
1 parent eb40efa commit 81152e3
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 82 deletions.
3 changes: 1 addition & 2 deletions src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.thenextlvl.gopaint.api.brush.BrushController;
import net.thenextlvl.gopaint.api.brush.BrushRegistry;
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
import net.thenextlvl.gopaint.api.model.MaskMode;
import net.thenextlvl.gopaint.api.model.PluginConfig;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import net.thenextlvl.gopaint.brush.CraftBrushController;
Expand Down Expand Up @@ -57,7 +56,7 @@ public class GoPaintPlugin extends JavaPlugin implements GoPaintProvider {

private final FileIO<PluginConfig> configFile = new GsonFile<>(IO.of(getDataFolder(), "config.json"), new PluginConfig(
new PluginConfig.BrushConfig(Material.FEATHER, new NamespacedKey("gopaint", "sphere_brush"), 100, 10, 50,
Axis.Y, 50, 50, Set.of("disabled"), true, Material.SPONGE, MaskMode.INTERFACE, SurfaceMode.DIRECT,
Axis.Y, 50, 50, Set.of("disabled"), true, Material.SPONGE, true, SurfaceMode.EXPOSED,
List.of(Material.STONE)),
new PluginConfig.ThicknessConfig(1, 5),
new PluginConfig.AngleConfig(2, 5, 10, 40, 85),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import net.thenextlvl.gopaint.api.brush.BrushController;
import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings;
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
import net.thenextlvl.gopaint.api.model.MaskMode;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import net.thenextlvl.gopaint.brush.setting.CraftItemBrushSettings;
import net.thenextlvl.gopaint.brush.setting.CraftPlayerBrushSettings;
Expand Down Expand Up @@ -61,10 +60,7 @@ public Optional<ItemBrushSettings> parseBrushSettings(ItemMeta itemMeta) {
var container = itemMeta.getPersistentDataContainer();

var brushSize = container.get(new NamespacedKey("gopaint", "size"), PersistentDataType.INTEGER);

var maskMode = Optional.ofNullable(container.get(new NamespacedKey("gopaint", "mask_mode"), PersistentDataType.STRING))
.map(MaskMode::valueOf)
.orElse(null);
var maskEnabled = container.get(new NamespacedKey("gopaint", "mask_enabled"), PersistentDataType.BOOLEAN);

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

if (brushSize == null || maskMode == null || surfaceMode == null || brush == null)
if (brushSize == null || maskEnabled == null || surfaceMode == null || brush == null)
return Optional.empty();

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

return Optional.of(CraftItemBrushSettings.builder()
.brushSize(brushSize)
.maskMode(maskMode)
.maskEnabled(maskEnabled)
.surfaceMode(surfaceMode)
.brush(brush)
.chance(chance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.base.Preconditions;
import net.kyori.adventure.key.Key;
import net.thenextlvl.gopaint.GoPaintPlugin;
import net.thenextlvl.gopaint.api.brush.Brush;
import net.thenextlvl.gopaint.api.brush.PatternBrush;
import net.thenextlvl.gopaint.api.brush.BrushRegistry;
import net.thenextlvl.gopaint.brush.standard.*;

Expand All @@ -13,7 +13,7 @@
import java.util.stream.Stream;

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

public CraftBrushRegistry(GoPaintPlugin plugin) {
registerBrush(new SphereBrush(plugin));
Expand All @@ -30,28 +30,28 @@ public CraftBrushRegistry(GoPaintPlugin plugin) {
}

@Override
public Stream<Brush> getBrushes() {
public Stream<PatternBrush> getBrushes() {
return brushes.stream().sorted();
}

@Override
public boolean isRegistered(Brush brush) {
public boolean isRegistered(PatternBrush brush) {
return brushes.contains(brush);
}

@Override
public void registerBrush(Brush brush) throws IllegalStateException {
public void registerBrush(PatternBrush brush) throws IllegalStateException {
Preconditions.checkState(!isRegistered(brush), "Brush already registered");
brushes.add(brush);
}

@Override
public void unregisterBrush(Brush brush) throws IllegalStateException {
public void unregisterBrush(PatternBrush brush) throws IllegalStateException {
if (!brushes.remove(brush)) throw new IllegalStateException("Brush not registered");
}

@Override
public Optional<Brush> getBrush(Key key) {
public Optional<PatternBrush> getBrush(Key key) {
return brushes.stream()
.filter(brush -> brush.key().equals(key))
.findAny();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.thenextlvl.gopaint.GoPaintPlugin;
import net.thenextlvl.gopaint.api.brush.Brush;
import net.thenextlvl.gopaint.api.brush.PatternBrush;
import net.thenextlvl.gopaint.api.brush.setting.ItemBrushSettings;
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
Expand Down Expand Up @@ -66,7 +66,7 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings {
private boolean maskEnabled;
private SurfaceMode surfaceMode;

private Brush brush;
private PatternBrush brush;
private Material mask;
private final List<Material> blocks = new ArrayList<>();

Expand Down Expand Up @@ -130,7 +130,7 @@ public void removeBlock(int slot) {
}

@Override
public void setBrush(Brush brush) {
public void setBrush(PatternBrush brush) {
this.brush = brush;
mainMenu.updateBrush();
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public void setFractureStrength(@Range(from = 1, to = Integer.MAX_VALUE) int fra
}

@Override
public Brush getNextBrush(@Nullable Brush brush) {
public PatternBrush getNextBrush(@Nullable PatternBrush brush) {
var brushes = plugin.brushRegistry().getBrushes().toList();
if (brush == null) return brushes.getFirst();
int next = brushes.indexOf(brush) + 1;
Expand All @@ -225,7 +225,7 @@ public Brush getNextBrush(@Nullable Brush brush) {
}

@Override
public Brush getPreviousBrush(@Nullable Brush brush) {
public PatternBrush getPreviousBrush(@Nullable PatternBrush brush) {
var brushes = plugin.brushRegistry().getBrushes().toList();
if (brush == null) return brushes.getFirst();
int back = brushes.indexOf(brush) - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.thenextlvl.gopaint.GoPaintPlugin;
import net.thenextlvl.gopaint.api.brush.Brush;
import net.thenextlvl.gopaint.api.brush.PatternBrush;
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
import org.bukkit.entity.Player;

Expand All @@ -36,7 +36,7 @@ public void register() {
.then(Commands.argument("brush", ArgumentTypes.key())
.suggests((context, builder) -> {
plugin.brushRegistry().getBrushes()
.map(Brush::key)
.map(PatternBrush::key)
.map(Key::asString)
.filter(key -> key.contains(builder.getRemaining()))
.forEach(builder::suggest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import lombok.RequiredArgsConstructor;
import net.thenextlvl.gopaint.GoPaintPlugin;
import net.thenextlvl.gopaint.api.model.MaskMode;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import net.thenextlvl.gopaint.brush.standard.*;
import net.thenextlvl.gopaint.menu.MainMenu;
Expand Down Expand Up @@ -150,16 +149,12 @@ public void menuClick(InventoryClickEvent event) {
settings.setBrushSize(settings.getBrushSize() - 10);
}
} else if (event.getRawSlot() == 15 || event.getRawSlot() == 6 || event.getRawSlot() == 24) {
settings.setMaskMode(switch (settings.getMaskMode()) {
case INTERFACE -> MaskMode.WORLDEDIT;
case WORLDEDIT -> MaskMode.DISABLED;
case DISABLED -> MaskMode.INTERFACE;
});
settings.setMaskEnabled(!settings.isMaskEnabled());
} else if (event.getRawSlot() == 16 || event.getRawSlot() == 7 || event.getRawSlot() == 25) {
settings.setSurfaceMode(switch (settings.getSurfaceMode()) {
case DIRECT -> SurfaceMode.RELATIVE;
case RELATIVE -> SurfaceMode.DISABLED;
case DISABLED -> SurfaceMode.DIRECT;
case EXPOSED -> SurfaceMode.VISIBLE;
case VISIBLE -> SurfaceMode.DISABLED;
case DISABLED -> SurfaceMode.EXPOSED;
});
} else if ((event.getRawSlot() >= 37 && event.getRawSlot() <= 41)
|| (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/thenextlvl/gopaint/menu/BrushesMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.thenextlvl.gopaint.api.brush.Brush;
import net.thenextlvl.gopaint.api.brush.PatternBrush;
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
import org.bukkit.Material;
Expand All @@ -15,7 +15,7 @@
import java.util.Collection;
import java.util.stream.IntStream;

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

@Override
public ActionItem constructItem(Brush brush) {
public ActionItem constructItem(PatternBrush brush) {
return new ItemBuilder(Material.PLAYER_HEAD)
.headValue(brush.getHeadValue())
.itemName(brush.getName(owner).color(NamedTextColor.GOLD))
Expand All @@ -54,7 +54,7 @@ public Component getPageFormat(int page) {
}

@Override
public Collection<Brush> getElements() {
public Collection<PatternBrush> getElements() {
return plugin.brushRegistry().getBrushes().toList();
}
}
43 changes: 16 additions & 27 deletions src/main/java/net/thenextlvl/gopaint/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MainMenu(GoPaintPlugin plugin, PlayerBrushSettings settings, Player owner
updateToggle();
updateBrush();
updateSize();
updateMaskMode();
updateMaskToggle();
updateSurfaceMode();
updateBlockPalette();
updateMask();
Expand Down Expand Up @@ -235,48 +235,37 @@ public void updateToggle() {
inventory.setItem(19, placeholder);
}

public void updateMaskMode() {
var icon = switch (settings.getMaskMode()) {
case DISABLED -> Material.CARVED_PUMPKIN;
case INTERFACE -> Material.JACK_O_LANTERN;
case WORLDEDIT -> Material.WOODEN_AXE;
};
public void updateMaskToggle() {
var icon = settings.isMaskEnabled() ? Material.JACK_O_LANTERN : Material.CARVED_PUMPKIN;

var mode = plugin.bundle().component(owner, settings.getMaskMode().translationKey())
.color(switch (settings.getMaskMode()) {
case DISABLED -> NamedTextColor.RED;
case INTERFACE -> NamedTextColor.GREEN;
case WORLDEDIT -> NamedTextColor.GOLD;
});
var state = plugin.bundle().component(owner, settings.isMaskEnabled() ? "mask.enabled" : "mask.disabled")
.color(settings.isMaskEnabled() ? NamedTextColor.GREEN : NamedTextColor.RED);

inventory.setItem(15, new ItemBuilder(icon)
.itemName(plugin.bundle().component(owner, "mask.mode"))
.lore(plugin.bundle().components(owner, "mask.mode.description",
Placeholder.component("mode", mode)))
.itemName(plugin.bundle().component(owner, "mask.state"))
.lore(plugin.bundle().components(owner, "mask.state.description",
Placeholder.component("state", state)))
.itemFlags(ItemFlag.HIDE_ATTRIBUTES));

var placeholder = new ItemBuilder(switch (settings.getMaskMode()) {
case DISABLED -> Material.RED_STAINED_GLASS_PANE;
case INTERFACE -> Material.LIME_STAINED_GLASS_PANE;
case WORLDEDIT -> Material.ORANGE_STAINED_GLASS_PANE;
}).hideTooltip(true);
var pane = settings.isMaskEnabled() ? Material.LIME_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE;
var placeholder = new ItemBuilder(pane).hideTooltip(true);

inventory.setItem(6, placeholder);
inventory.setItem(24, placeholder);
}

public void updateSurfaceMode() {
var icon = switch (settings.getSurfaceMode()) {
case DIRECT -> Material.LIGHT_WEIGHTED_PRESSURE_PLATE;
case EXPOSED -> Material.LIGHT_WEIGHTED_PRESSURE_PLATE;
case DISABLED -> Material.POLISHED_BLACKSTONE_PRESSURE_PLATE;
case RELATIVE -> Material.HEAVY_WEIGHTED_PRESSURE_PLATE;
case VISIBLE -> Material.HEAVY_WEIGHTED_PRESSURE_PLATE;
};

var mode = plugin.bundle().component(owner, settings.getSurfaceMode().translationKey())
.color(switch (settings.getSurfaceMode()) {
case DIRECT -> NamedTextColor.GREEN;
case EXPOSED -> NamedTextColor.GREEN;
case DISABLED -> NamedTextColor.RED;
case RELATIVE -> NamedTextColor.GOLD;
case VISIBLE -> NamedTextColor.GOLD;
});

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

var placeholder = new ItemBuilder(switch (settings.getSurfaceMode()) {
case DIRECT -> Material.LIME_STAINED_GLASS_PANE;
case EXPOSED -> Material.LIME_STAINED_GLASS_PANE;
case DISABLED -> Material.RED_STAINED_GLASS_PANE;
case RELATIVE -> Material.ORANGE_STAINED_GLASS_PANE;
case VISIBLE -> Material.ORANGE_STAINED_GLASS_PANE;
}).hideTooltip(true);

inventory.setItem(7, placeholder);
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
prefix=<aqua>goPaint><reset>
prefix=<aqua>goPaint ><reset>
command.gopaint.brush.disabled=<prefix> <red>Disabled brush
command.gopaint.brush.enabled=<prefix> <green>Enabled brush
command.gopaint.brush.size=<prefix> <gold>Brush size set to: <yellow><size>
command.gopaint.reloaded=<prefix> <green>Reloaded
brush.block.sight=<prefix> <red>There is no block in sight.
brush.disabled=<prefix> <red>Your brush is disabled, left click to enable the brush or type <white>/gp toggle<red>.
brush.paint.point.set=<prefix> <white>Paint brush point #<point> set.
brush.state.enabled=<green>Enabled
Expand All @@ -14,15 +15,14 @@ brush.toggle.description=<!i><b><state><newline><newline>\
<!i><gray>Click without an item to toggle
menu.main.title=<dark_blue>goPaint Menu
menu.brushes.title=<dark_blue>goPaint Brushes
mask.mode.disabled=Disabled
mask.mode.interface=Interface
mask.mode.worldedit=WorldEdit
mask.mode=<gold>Mask Mode
mask.mode.description=<!i><b><mode><newline><newline>\
mask.enabled=Enabled
mask.disabled=Disabled
mask.state=<gold>Mask
mask.state.description=<!i><b><state><newline><newline>\
<!i><gray>Click to cycle
surface.mode.direct=Direct
surface.mode.disabled=Disabled
surface.mode.relative=Relative
surface.mode.exposed=Exposed
surface.mode.visible=Visible
surface.mode=<gold>Surface Mode
surface.mode.description=<!i><b><mode><newline><newline>\
<!i><gray>Click to cycle
Expand Down Expand Up @@ -67,7 +67,8 @@ slot.set.description=<newline>\
<!i><gray>Right click to clear
mask.block=<gold>Current Mask
mask.block.description=<newline>\
<!i><gray>Click with a block to change
<!i><gray>Click with a block to change<newline>\
<!i><gray>Right click to clear
brush.size=<gold>Brush Size: <yellow><size>
brush.size.description=<newline>\
<!i><gray>Left click to increase<newline>\
Expand Down Expand Up @@ -155,6 +156,5 @@ brush.exported.falloff=<!i><dark_gray>Falloff strength: <falloff>
brush.exported.mixing=<!i><dark_gray>Mixing strength: <mixing>
brush.exported.fracture=<!i><dark_gray>Fracture strength: <fracture>
brush.exported.blocks=<!i><dark_gray>Blocks: <blocks>
brush.exported.mask-mode=<!i><dark_gray>Mask mode: <mode>
brush.exported.surface-mode=<!i><dark_gray>Surface mode: <mode>
brush.exported.mask=<!i><dark_gray>Mask: <mask>
Loading

0 comments on commit 81152e3

Please sign in to comment.