Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Jun 20, 2024
1 parent 0f16f9b commit 2bcdb5b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ public void onClick(PlayerInteractEvent event) {
? plugin.brushController().parseBrushSettings(item).orElse(null)
: plugin.brushController().getBrushSettings(player);

event.setCancelled(true);

if (settings == null || settings.getBlocks().isEmpty()) return;

if (!(settings instanceof PlayerBrushSettings playerSettings) || playerSettings.isEnabled()) {
BukkitAdapter.adapt(player).runAction(
() -> settings.getBrush().paint(location, player, settings), false, true
);
} else plugin.bundle().sendMessage(player, "brush.disabled");

event.setCancelled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public void menuClick(InventoryClickEvent event) {
}
return;
}
event.setCancelled(true);
var playerBrush = plugin.brushController().getBrushSettings(player);
if (event.getRawSlot() == 10 || event.getRawSlot() == 1 || event.getRawSlot() == 19) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
if (!event.getCursor().getType().isBlock()) {
if (!event.getCursor().getType().equals(plugin.config().generic().defaultBrush())) {
playerBrush.export(event.getCursor());
}
}
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.toggle();
}
event.setCancelled(true);
} else if (event.getRawSlot() == 11 || event.getRawSlot() == 2 || event.getRawSlot() == 20) {
if (event.getClick().equals(ClickType.LEFT)) {
playerBrush.cycleBrushForward();
Expand All @@ -71,44 +71,42 @@ public void menuClick(InventoryClickEvent event) {
} else if (event.getClick().isShiftClick()) {
player.openInventory(GUI.generateBrushes());
}
event.setCancelled(true);
} else if (event.getRawSlot() == 12 || event.getRawSlot() == 3 || event.getRawSlot() == 21) {
var brush = playerBrush.getBrush();
if (brush instanceof SprayBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseChance();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseChance();
}
} else if (brush instanceof OverlayBrush || brush instanceof UnderlayBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseThickness();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseThickness();
}
} else if (brush instanceof FractureBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseFractureDistance();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseFractureDistance();
}
} else if (brush instanceof AngleBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseAngleDistance();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseAngleDistance();
}
} else if (brush instanceof GradientBrush || brush instanceof PaintBrush
|| brush instanceof SplatterBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseFalloffStrength();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseFalloffStrength();
}
} else if (brush instanceof DiscBrush) {
playerBrush.cycleAxis();
}
event.setCancelled(true);
} else if (event.getRawSlot() == 13 || event.getRawSlot() == 4 || event.getRawSlot() == 22) {
var brush = playerBrush.getBrush();
if (brush instanceof AngleBrush) {
Expand All @@ -122,13 +120,12 @@ public void menuClick(InventoryClickEvent event) {
playerBrush.decreaseAngleHeightDifference(15);
}
} else if (brush instanceof GradientBrush) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
playerBrush.increaseMixingStrength();
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.decreaseMixingStrength();
}
}
event.setCancelled(true);
} else if (event.getRawSlot() == 14 || event.getRawSlot() == 5 || event.getRawSlot() == 23) {
if (event.getClick().equals(ClickType.LEFT)) {
playerBrush.increaseBrushSize(1);
Expand All @@ -139,37 +136,31 @@ public void menuClick(InventoryClickEvent event) {
} else if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
playerBrush.decreaseBrushSize(10);
}
event.setCancelled(true);
} else if (event.getRawSlot() == 15 || event.getRawSlot() == 6 || event.getRawSlot() == 24) {
event.setCancelled(true);
playerBrush.cycleMaskMode();
} else if (event.getRawSlot() == 16 || event.getRawSlot() == 7 || event.getRawSlot() == 25) {
playerBrush.cycleSurfaceMode();
event.setCancelled(true);
} else if ((event.getRawSlot() >= 37 && event.getRawSlot() <= 41)
|| (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) {
|| (event.getRawSlot() >= 46 && event.getRawSlot() <= 50)) {
int slot;
if (event.getRawSlot() >= 37 && event.getRawSlot() <= 41) {
slot = event.getRawSlot() - 36;
} else {
slot = event.getRawSlot() - 45;
}
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
if (event.getCursor().getType().isBlock() && event.getCursor().getType().isSolid()) {
playerBrush.addBlock(event.getCursor().getType(), slot);
}
} else if (event.getClick().equals(ClickType.RIGHT)) {
} else if (event.getClick().isRightClick()) {
playerBrush.removeBlock(slot);
}
event.setCancelled(true);
} else if (event.getRawSlot() == 43 || event.getRawSlot() == 52) {
if (event.getClick().equals(ClickType.LEFT)) {
if (event.getClick().isLeftClick()) {
if (event.getCursor().getType().isBlock() && event.getCursor().getType().isSolid()) {
playerBrush.setMask(event.getCursor().getType());
}
}
event.setCancelled(true);
} else {
event.setCancelled(true);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/net/thenextlvl/gopaint/util/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
public final class Items {

public static ItemStack create(Material material, int amount, String name, String lore) {
ItemStack itemStack = new ItemStack(material);
itemStack.setAmount(amount);
var itemStack = new ItemStack(material, amount);
itemStack.editMeta(itemMeta -> {
if (!lore.isEmpty()) {
String[] loreListArray = lore.split("\n");
Expand All @@ -50,8 +49,14 @@ public static ItemStack create(Material material, int amount, String name, Strin
return itemStack;
}

public static ItemStack create(Material material) {
var itemStack = new ItemStack(material);
itemStack.editMeta(itemMeta -> itemMeta.setHideTooltip(true));
return itemStack;
}

public static ItemStack createHead(String texture, int amount, String name, String lore) {
ItemStack head = create(Material.PLAYER_HEAD, amount, name, lore);
var head = create(Material.PLAYER_HEAD, amount, name, lore);
head.editMeta(SkullMeta.class, skullMeta -> {
var profile = Bukkit.createProfile(UUID.randomUUID());
profile.setProperty(new ProfileProperty("textures", texture));
Expand Down

0 comments on commit 2bcdb5b

Please sign in to comment.