Skip to content

Commit

Permalink
other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Jun 20, 2024
1 parent a739c53 commit 4da7d0a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.thenextlvl.gopaint.api.model;

import core.i18n.file.ComponentBundle;
import net.thenextlvl.gopaint.api.brush.BrushController;
import net.thenextlvl.gopaint.api.brush.BrushRegistry;
import org.bukkit.plugin.Plugin;

public interface GoPaintProvider extends Plugin {
String USE_PERMISSION = "gopaint.use";
String ADMIN_PERMISSION = "gopaint.admin";
String WORLD_BYPASS_PERMISSION = "gopaint.world.bypass";

ComponentBundle bundle();

BrushRegistry brushRegistry();

BrushController brushController();

PluginConfig config();
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package net.thenextlvl.gopaint.model;
package net.thenextlvl.gopaint.api.model;

import com.google.gson.annotations.SerializedName;
import net.thenextlvl.gopaint.api.model.MaskMode;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import net.thenextlvl.gopaint.api.brush.Brush;
import org.bukkit.Axis;
import org.bukkit.Material;

import java.util.List;

public record PluginConfig(
@SerializedName("generic") Generic generic,
@SerializedName("thickness") Thickness thickness,
@SerializedName("angle") Angle angle,
@SerializedName("fracture") Fracture fracture
@SerializedName("brush") BrushConfig brushConfig,
@SerializedName("thickness") ThicknessConfig thicknessConfig,
@SerializedName("angle") AngleConfig angleConfig,
@SerializedName("fracture") FractureConfig fractureConfig
) {

public record Generic(
@SerializedName("default-brush") Material defaultBrush,
public record BrushConfig(
@SerializedName("default-brush-type") Material defaultBrushType,
@SerializedName("default-brush") Brush defaultBrush,
@SerializedName("max-size") int maxSize,
@SerializedName("default-size") int defaultSize,
@SerializedName("default-chance") int defaultChance,
Expand All @@ -31,13 +31,13 @@ public record Generic(
) {
}

public record Thickness(
public record ThicknessConfig(
@SerializedName("default-thickness") int defaultThickness,
@SerializedName("max-thickness") int maxThickness
) {
}

public record Angle(
public record AngleConfig(
@SerializedName("default-angle-distance") int defaultAngleDistance,
@SerializedName("max-angle-distance") int maxAngleDistance,
@SerializedName("min-angle-height-difference") double minAngleHeightDifference,
Expand All @@ -46,7 +46,7 @@ public record Angle(
) {
}

public record Fracture(
public record FractureConfig(
@SerializedName("default-fracture-distance") int defaultFractureDistance,
@SerializedName("max-fracture-distance") int maxFractureDistance
) {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/net/thenextlvl/gopaint/GoPaintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.thenextlvl.gopaint.adapter.BrushAdapter;
import net.thenextlvl.gopaint.api.brush.Brush;
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;
import net.thenextlvl.gopaint.brush.CraftBrushRegistry;
import net.thenextlvl.gopaint.brush.standard.SphereBrush;
import net.thenextlvl.gopaint.command.GoPaintCommand;
import net.thenextlvl.gopaint.model.PluginConfig;
import net.thenextlvl.gopaint.listener.ConnectListener;
import net.thenextlvl.gopaint.listener.InteractListener;
import net.thenextlvl.gopaint.listener.InventoryListener;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import org.bstats.bukkit.Metrics;
import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -36,10 +39,7 @@
import java.util.Locale;

@Accessors(fluent = true)
public class GoPaintPlugin extends JavaPlugin implements Listener {
public static final String USE_PERMISSION = "gopaint.use";
public static final String ADMIN_PERMISSION = "gopaint.admin";
public static final String WORLD_BYPASS_PERMISSION = "gopaint.world.bypass";
public class GoPaintPlugin extends JavaPlugin implements GoPaintProvider {

private final File translations = new File(getDataFolder(), "translations");
private final @Getter ComponentBundle bundle = new ComponentBundle(translations, audience ->
Expand All @@ -51,20 +51,22 @@ public class GoPaintPlugin extends JavaPlugin implements Listener {
Placeholder.component("prefix", bundle.component(Locale.US, "prefix"))
)).build());

private final @Getter BrushController brushController = new CraftBrushController(this);
private final @Getter BrushRegistry brushRegistry = new CraftBrushRegistry(this);

private final FileIO<PluginConfig> configFile = new GsonFile<>(IO.of(getDataFolder(), "config.json"), new PluginConfig(
new PluginConfig.Generic(Material.FEATHER, 100, 10, 50, Axis.Y, 50, 50, new ArrayList<>(), true, Material.SPONGE, MaskMode.INTERFACE, SurfaceMode.DIRECT),
new PluginConfig.Thickness(1, 5),
new PluginConfig.Angle(2, 5, 10, 40, 85),
new PluginConfig.Fracture(2, 5)
new PluginConfig.BrushConfig(Material.FEATHER, SphereBrush.INSTANCE, 100, 10, 50, Axis.Y, 50, 50,
new ArrayList<>(), true, Material.SPONGE, MaskMode.INTERFACE, SurfaceMode.DIRECT),
new PluginConfig.ThicknessConfig(1, 5),
new PluginConfig.AngleConfig(2, 5, 10, 40, 85),
new PluginConfig.FractureConfig(2, 5)
), new GsonBuilder()
.registerTypeAdapter(Material.class, MaterialAdapter.NotNull.INSTANCE)
.registerTypeAdapter(Brush.class, new BrushAdapter(this))
.setPrettyPrinting()
.create()
).validate().save();

private final @Getter BrushController brushController = new CraftBrushController(this);
private final @Getter BrushRegistry brushRegistry = new CraftBrushRegistry(this);

private final Metrics metrics = new Metrics(this, 22279);

public GoPaintPlugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class CraftBrushController implements BrushController {

@Override
public PlayerBrushSettings getBrushSettings(Player player) {
return playerBrushes.computeIfAbsent(player.getUniqueId(), ignored -> new CraftPlayerBrushSettings(plugin));
return playerBrushes.computeIfAbsent(player.getUniqueId(), ignored ->
new CraftPlayerBrushSettings(plugin, player));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package net.thenextlvl.gopaint.brush.setting;

import core.paper.gui.AbstractGUI;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
Expand All @@ -30,13 +30,12 @@
import net.thenextlvl.gopaint.api.model.MaskMode;
import net.thenextlvl.gopaint.api.model.SurfaceMode;
import net.thenextlvl.gopaint.brush.standard.*;
import net.thenextlvl.gopaint.util.GUI;
import net.thenextlvl.gopaint.menu.BrushesMenu;
import net.thenextlvl.gopaint.menu.MainMenu;
import org.bukkit.Axis;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

Expand All @@ -50,9 +49,10 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings {
private static final Random random = new Random();

private final GoPaintPlugin plugin;
private final Player player;

private boolean enabled;
private int size;
private int brushSize;
private int chance;
private int thickness;
private int fractureDistance;
Expand All @@ -64,31 +64,33 @@ public final class CraftPlayerBrushSettings implements PlayerBrushSettings {
private MaskMode maskMode;
private SurfaceMode surfaceMode;

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

private final Inventory inventory;
private final MainMenu mainMenu;

public CraftPlayerBrushSettings(GoPaintPlugin plugin) {
public CraftPlayerBrushSettings(GoPaintPlugin plugin, Player player) {
this.plugin = plugin;

surfaceMode = plugin.config().generic().surfaceMode();
maskMode = plugin.config().generic().maskMode();
enabled = plugin.config().generic().enabledByDefault();
chance = plugin.config().generic().defaultChance();
thickness = plugin.config().thickness().defaultThickness();
fractureDistance = plugin.config().fracture().defaultFractureDistance();
angleDistance = plugin.config().angle().defaultAngleDistance();
angleHeightDifference = plugin.config().angle().defaultAngleHeightDifference();
falloffStrength = plugin.config().generic().defaultFalloffStrength();
mixingStrength = plugin.config().generic().defaultMixingStrength();
axis = plugin.config().generic().defaultAxis();
size = plugin.config().generic().defaultSize();
mask = plugin.config().generic().defaultMask();
brush = cycleForward(null);
this.player = player;

surfaceMode = plugin.config().brushConfig().surfaceMode();
maskMode = plugin.config().brushConfig().maskMode();
enabled = plugin.config().brushConfig().enabledByDefault();
chance = plugin.config().brushConfig().defaultChance();
thickness = plugin.config().thicknessConfig().defaultThickness();
fractureDistance = plugin.config().fractureConfig().defaultFractureDistance();
angleDistance = plugin.config().angleConfig().defaultAngleDistance();
angleHeightDifference = plugin.config().angleConfig().defaultAngleHeightDifference();
falloffStrength = plugin.config().brushConfig().defaultFalloffStrength();
mixingStrength = plugin.config().brushConfig().defaultMixingStrength();
axis = plugin.config().brushConfig().defaultAxis();
brushSize = plugin.config().brushConfig().defaultSize();
mask = plugin.config().brushConfig().defaultMask();
brush = plugin.config().brushConfig().defaultBrush();
blocks.add(Material.STONE);
inventory = GUI.create(this);

mainMenu = new MainMenu(plugin, this, player);
}

@Override
Expand Down Expand Up @@ -315,7 +317,7 @@ public Brush cycleBackward(@Nullable Brush brush) {
public void export(ItemStack itemStack) {
List<String> lore = new ArrayList<>();
lore.add("");
lore.add("Size: " + size);
lore.add("Size: " + brushSize);
if (getBrush() instanceof SprayBrush) {
lore.add("Chance: " + getChance() + "%");
} else if (getBrush() instanceof OverlayBrush || getBrush() instanceof UnderlayBrush) {
Expand Down Expand Up @@ -355,8 +357,7 @@ public void export(ItemStack itemStack) {
itemMeta.lore(lore.stream().map(string -> Component.text(string).style(Style
.style(TextDecoration.ITALIC.withState(false))
.color(NamedTextColor.DARK_GRAY))).toList());
itemMeta.addEnchant(Enchantment.INFINITY, 1, false);
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.setEnchantmentGlintOverride(true);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.RequiredArgsConstructor;
import net.thenextlvl.gopaint.GoPaintPlugin;
import net.thenextlvl.gopaint.api.brush.setting.PlayerBrushSettings;
import net.thenextlvl.gopaint.api.model.GoPaintProvider;
import org.bukkit.FluidCollisionMode;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand All @@ -39,12 +40,12 @@ public final class InteractListener implements Listener {
public void onClick(PlayerInteractEvent event) {
var player = event.getPlayer();

if (!player.hasPermission(GoPaintPlugin.USE_PERMISSION)) return;
if (!player.hasPermission(GoPaintProvider.USE_PERMISSION)) return;

var item = event.getItem();
if (item == null) return;

if (event.getAction().isLeftClick() && item.getType().equals(plugin.config().generic().defaultBrush())) {
if (event.getAction().isLeftClick() && item.getType().equals(plugin.config().brushConfig().defaultBrushType())) {
var brush = plugin.brushController().getBrushSettings(player);
brush.getMainMenu().open();
event.setCancelled(true);
Expand All @@ -64,12 +65,12 @@ public void onClick(PlayerInteractEvent event) {
return;
}

if (!player.hasPermission(GoPaintPlugin.WORLD_BYPASS_PERMISSION)
&& plugin.config().generic().disabledWorlds().contains(location.getWorld().getName())) {
if (!player.hasPermission(GoPaintProvider.WORLD_BYPASS_PERMISSION)
&& plugin.config().brushConfig().disabledWorlds().contains(location.getWorld().getName())) {
return;
}

var settings = !item.getType().equals(plugin.config().generic().defaultBrush())
var settings = !item.getType().equals(plugin.config().brushConfig().defaultBrushType())
? plugin.brushController().parseBrushSettings(item).orElse(null)
: plugin.brushController().getBrushSettings(player);

Expand Down
Loading

0 comments on commit 4da7d0a

Please sign in to comment.