Skip to content

Commit

Permalink
Merge pull request #20 from TheNextLvl-net/general-changes
Browse files Browse the repository at this point in the history
General changes
  • Loading branch information
NonSwag authored Jul 2, 2024
2 parents 015f98d + c2efe6b commit 13c6ed3
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public interface PlayerBrushSettings extends BrushSettings {
* Exports the brush settings visually onto the given ItemStack.
*
* @param itemStack The ItemStack to export the brush settings to.
* @return whether the settings could be exported to the item
*/
void exportSettings(ItemStack itemStack);
boolean exportSettings(ItemStack itemStack);

/**
* Imports the item brush settings.
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ paper {
main = "net.thenextlvl.gopaint.GoPaintPlugin"
authors = listOf("Arcaniax", "TheMeinerLP", "NonSwag")
apiVersion = "1.20"
foliaSupported = true

serverDependencies {
register("FastAsyncWorldEdit") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CraftBrushRegistry(GoPaintPlugin plugin) {
registerBrush(new SphereBrush(plugin));
registerBrush(new SprayBrush(plugin));
registerBrush(new SplatterBrush(plugin));
registerBrush(new DiscBrush(plugin));
registerBrush(new DiskBrush(plugin));
registerBrush(new BucketBrush(plugin));
registerBrush(new AngleBrush(plugin));
registerBrush(new OverlayBrush(plugin));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws W
}

private double getRate(BlockVector3 position) {
var size = (double) settings().getBrushSize();
var falloff = (100.0 - (double) settings().getFalloffStrength()) / 100.0;
var size = settings().getBrushSize() / 2;
var falloff = (100 - settings().getFalloffStrength()) / 100d;
return (position.distance(position()) - size * falloff) / (size - size * falloff);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record SprayPattern(

@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
if (settings.getRandom().nextInt(100) < settings.getChance()) return false;
if (settings.getRandom().nextInt(100) >= settings.getChance()) return false;
return set.setBlock(extent, getRandomBlockState());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,58 +234,59 @@ public PatternBrush getPreviousBrush(@Nullable PatternBrush brush) {
}

@Override
public void exportSettings(ItemStack itemStack) {
var lore = new ArrayList<Component>();
lore.add(Component.empty());
lore.add(plugin.bundle().component(player, "brush.exported.size",
Placeholder.parsed("size", String.valueOf(getBrushSize()))));
if (getBrush() instanceof SprayBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.chance",
Placeholder.parsed("chance", String.valueOf(getChance()))));
} else if (getBrush() instanceof OverlayBrush || getBrush() instanceof UnderlayBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.thickness",
Placeholder.parsed("thickness", String.valueOf(getThickness()))));
} else if (getBrush() instanceof DiscBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.axis",
Placeholder.parsed("axis", getAxis().name())));
} else if (getBrush() instanceof AngleBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.angle.distance",
Placeholder.parsed("distance", String.valueOf(getAngleDistance()))));
lore.add(plugin.bundle().component(player, "brush.exported.angle.height",
Placeholder.parsed("height", String.valueOf(getAngleHeightDifference()))));
} else if (getBrush() instanceof SplatterBrush || getBrush() instanceof PaintBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.falloff",
Placeholder.parsed("falloff", String.valueOf(getFalloffStrength()))));
} else if (getBrush() instanceof GradientBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.mixing",
Placeholder.parsed("mixing", String.valueOf(getMixingStrength()))));
lore.add(plugin.bundle().component(player, "brush.exported.falloff",
Placeholder.parsed("falloff", String.valueOf(getFalloffStrength()))));
} else if (getBrush() instanceof FractureBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.fracture",
Placeholder.parsed("fracture", String.valueOf(getFractureStrength()))));
}
if (!blocks.isEmpty()) {
var blocks = getBlocks().stream()
.map(Material::translationKey)
.map(Component::translatable)
.toList();
lore.add(plugin.bundle().component(player, "brush.exported.blocks",
Placeholder.component("blocks", Component.join(JoinConfiguration.commas(true), blocks))));
}

if (isMaskEnabled()) {
lore.add(plugin.bundle().component(player, "brush.exported.mask",
Placeholder.component("mask", Component.translatable(getMask().translationKey()))));
}

if (!getSurfaceMode().equals(SurfaceMode.DISABLED)) {
var mode = plugin.bundle().component(player, getSurfaceMode().translationKey());
lore.add(plugin.bundle().component(player, "brush.exported.surface-mode",
Placeholder.component("mode", mode)));
}

itemStack.editMeta(itemMeta -> {
public boolean exportSettings(ItemStack itemStack) {
if (itemStack.getType().equals(plugin.config().brushConfig().defaultBrushType())) return false;
return !itemStack.getType().isBlock() && itemStack.editMeta(itemMeta -> {
var lore = new ArrayList<Component>();
lore.add(Component.empty());
lore.add(plugin.bundle().component(player, "brush.exported.size",
Placeholder.parsed("size", String.valueOf(getBrushSize()))));
if (getBrush() instanceof SprayBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.chance",
Placeholder.parsed("chance", String.valueOf(getChance()))));
} else if (getBrush() instanceof OverlayBrush || getBrush() instanceof UnderlayBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.thickness",
Placeholder.parsed("thickness", String.valueOf(getThickness()))));
} else if (getBrush() instanceof DiskBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.axis",
Placeholder.parsed("axis", getAxis().name())));
} else if (getBrush() instanceof AngleBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.angle.distance",
Placeholder.parsed("distance", String.valueOf(getAngleDistance()))));
lore.add(plugin.bundle().component(player, "brush.exported.angle.height",
Placeholder.parsed("height", String.valueOf(getAngleHeightDifference()))));
} else if (getBrush() instanceof SplatterBrush || getBrush() instanceof PaintBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.falloff",
Placeholder.parsed("falloff", String.valueOf(getFalloffStrength()))));
} else if (getBrush() instanceof GradientBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.mixing",
Placeholder.parsed("mixing", String.valueOf(getMixingStrength()))));
lore.add(plugin.bundle().component(player, "brush.exported.falloff",
Placeholder.parsed("falloff", String.valueOf(getFalloffStrength()))));
} else if (getBrush() instanceof FractureBrush) {
lore.add(plugin.bundle().component(player, "brush.exported.fracture",
Placeholder.parsed("fracture", String.valueOf(getFractureStrength()))));
}
if (!blocks.isEmpty()) {
var blocks = getBlocks().stream()
.map(Material::translationKey)
.map(Component::translatable)
.toList();
lore.add(plugin.bundle().component(player, "brush.exported.blocks",
Placeholder.component("blocks", Component.join(JoinConfiguration.commas(true), blocks))));
}

if (isMaskEnabled()) {
lore.add(plugin.bundle().component(player, "brush.exported.mask",
Placeholder.component("mask", Component.translatable(getMask().translationKey()))));
}

if (!getSurfaceMode().equals(SurfaceMode.DISABLED)) {
var mode = plugin.bundle().component(player, getSurfaceMode().translationKey());
lore.add(plugin.bundle().component(player, "brush.exported.surface-mode",
Placeholder.component("mode", mode)));
}

itemMeta.itemName(plugin.bundle().component(player, "brush.exported.name",
Placeholder.component("brush", getBrush().getName(player))));
itemMeta.lore(lore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@
import net.thenextlvl.gopaint.brush.pattern.ShufflePattern;
import org.bukkit.NamespacedKey;

public class DiscBrush extends PatternBrush {
public class DiskBrush extends PatternBrush {
private final GoPaintProvider provider;

public DiscBrush(GoPaintProvider provider) {
public DiskBrush(GoPaintProvider provider) {
super(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjFmMjgyNTBkMWU0MjBhNjUxMWIwMzk2NDg2OGZjYTJmNTYzN2UzYWJhNzlmNGExNjNmNGE4ZDYxM2JlIn19fQ==",
new NamespacedKey("gopaint", "disc_brush")
new NamespacedKey("gopaint", "disk_brush")
);
this.provider = provider;
}

@Override
public Component getName(Audience audience) {
return provider.bundle().component(audience, "brush.name.disc");
return provider.bundle().component(audience, "brush.name.disk");
}

@Override
public Component[] getDescription(Audience audience) {
return provider.bundle().components(audience, "brush.description.disc");
return provider.bundle().components(audience, "brush.description.disk");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UnderlayBrush extends SpherePatternBrush {

public UnderlayBrush(GoPaintProvider provider) {
super(
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzIzNDQ2OTkwZjU4YjY1M2FiNWYwZTdhZjNmZGM3NTYwOTEyNzVmNGMzYzJkZDQxYzdkODYyZGQzZjkyZTg0YSJ9fX0=",
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzFlNTY1YzFlMDVhODIzZDgxNjMwMjY4N2E5OGQ1ZmUyZDA2NmFhMTkxNDMzNjg4NDRhMGM0MzAyNzYyNDljMyJ9fX0=",
new NamespacedKey("gopaint", "underlay_brush")
);
this.provider = provider;
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/net/thenextlvl/gopaint/command/GoPaintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import core.paper.item.ItemBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
Expand Down Expand Up @@ -44,6 +45,15 @@ public void register() {
})
.requires(stack -> stack.getSender() instanceof Player)
.executes(this::brush)))
.then(Commands.literal("wand")
.requires(stack -> stack.getSender() instanceof Player)
.executes(this::wand))
.then(Commands.literal("export")
.requires(stack -> stack.getSender() instanceof Player)
.executes(this::exportSettings))
.then(Commands.literal("import")
.requires(stack -> stack.getSender() instanceof Player)
.executes(this::importSettings))
.then(Commands.literal("toggle")
.requires(stack -> stack.getSender() instanceof Player)
.executes(this::toggle))
Expand All @@ -55,6 +65,33 @@ public void register() {
event.registrar().register(command, List.of("gp"))));
}

private int exportSettings(CommandContext<CommandSourceStack> context) {
var player = (Player) context.getSource().getSender();

var mainHand = player.getInventory().getItemInMainHand();
var settings = plugin.brushController().getBrushSettings(player);

plugin.bundle().sendMessage(player, settings.exportSettings(mainHand) ?
"command.gopaint.export.success" : "command.gopaint.export.failed");

return Command.SINGLE_SUCCESS;
}

private int importSettings(CommandContext<CommandSourceStack> context) {
var player = (Player) context.getSource().getSender();

var mainHand = player.getInventory().getItemInMainHand();
var settings = plugin.brushController().getBrushSettings(player);
var parsed = plugin.brushController().parseBrushSettings(mainHand);

parsed.ifPresent(settings::importSettings);

plugin.bundle().sendMessage(player, parsed.isPresent() ?
"command.gopaint.import.success" : "command.gopaint.import.failed");

return Command.SINGLE_SUCCESS;
}

private int brush(CommandContext<CommandSourceStack> context) {
var player = (Player) context.getSource().getSender();
var settings = plugin.brushController().getBrushSettings(player);
Expand Down Expand Up @@ -100,4 +137,47 @@ private int reload(CommandContext<CommandSourceStack> context) {
plugin.bundle().sendMessage(sender, "command.gopaint.reloaded");
return Command.SINGLE_SUCCESS;
}

private int wand(CommandContext<CommandSourceStack> context) {
var player = (Player) context.getSource().getSender();
plugin.bundle().sendMessage(player, giveWand(player)
? "command.gopaint.wand.success"
: "command.gopaint.wand.failed");
return Command.SINGLE_SUCCESS;
}

private boolean giveWand(Player player) {
var type = plugin.config().brushConfig().defaultBrushType();

var inventory = player.getInventory();
var first = inventory.first(type);

if (first != -1) {
if (inventory.getHeldItemSlot() == first) return true;

if (first >= 0 && first <= 8) {
inventory.setHeldItemSlot(first);
return true;
}

var item = inventory.getItem(first);

inventory.setItem(first, inventory.getItemInMainHand());
inventory.setItemInMainHand(item);

return true;
}

if (inventory.getItemInMainHand().isEmpty()) {
inventory.setItemInMainHand(new ItemBuilder(type));
return true;
}

var empty = inventory.firstEmpty();
if (empty == -1) return false;

inventory.setItem(empty, inventory.getItemInMainHand());
inventory.setItemInMainHand(new ItemBuilder(type));
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public void menuClick(InventoryClickEvent event) {


plugin.brushController().parseBrushSettings(event.getCursor())
.ifPresentOrElse(settings::importSettings, () -> {
if (itemType.equals(plugin.config().brushConfig().defaultBrushType())) return;
if (!itemType.isBlock()) settings.exportSettings(event.getCursor());
});
.ifPresentOrElse(settings::importSettings, () -> settings.exportSettings(event.getCursor()));

} else if (event.getRawSlot() == 11 || event.getRawSlot() == 2 || event.getRawSlot() == 20) {
if (event.getClick().equals(ClickType.LEFT)) {
Expand Down Expand Up @@ -112,7 +109,7 @@ public void menuClick(InventoryClickEvent event) {
} else if (event.getClick().isRightClick()) {
settings.setFalloffStrength(settings.getFalloffStrength() - 10);
}
} else if (brush instanceof DiscBrush) {
} else if (brush instanceof DiskBrush) {
settings.setAxis(switch (settings.getAxis()) {
case X -> Axis.Y;
case Y -> Axis.Z;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/thenextlvl/gopaint/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void updateThickness() {
}

public void updateAxis() {
if (!(settings.getBrush() instanceof DiscBrush)) return;
if (!(settings.getBrush() instanceof DiskBrush)) return;

inventory.setItem(12, new ItemBuilder(Material.COMPASS)
.itemName(plugin.bundle().component(owner, "brush.axis",
Expand Down
12 changes: 9 additions & 3 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ 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
command.gopaint.reloaded=<prefix> <green>Reloaded the configuration.
command.gopaint.wand.success=<prefix> <white>Left click: open menu; Right click: use brush
command.gopaint.wand.failed=<prefix> <red>Your inventory is full.
command.gopaint.export.success=<prefix> <white>Exported current brush to your item.
command.gopaint.export.failed=<prefix> <red>Failed to export current brush to your item.
command.gopaint.import.success=<prefix> <white>Imported settings from your current item.
command.gopaint.import.failed=<prefix> <red>Found no brush settings on your current item.
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.
Expand Down Expand Up @@ -112,8 +118,8 @@ brush.description.bucket=<newline>\
<newline>\
<!i><dark_gray>Paints connected blocks<newline>\
<!i><dark_gray>with the same block type
brush.name.disc=Disc Brush
brush.description.disc=<newline>\
brush.name.disk=Disk Brush
brush.description.disk=<newline>\
<!i><gray>Click to select<newline>\
<newline>\
<!i><dark_gray>Paints blocks in the<newline>\
Expand Down
Loading

0 comments on commit 13c6ed3

Please sign in to comment.