Skip to content

Commit

Permalink
Version 7.2
Browse files Browse the repository at this point in the history
- Added Physics Inventory
- Added Settings Inventory
- Added Bounce on all blocks setting
- Updated Edit Inventory
- Updated Default Projectiles
- Updated Messages
- Fixed bug - is bounce-able block check
  • Loading branch information
HuskyDreaming committed Nov 17, 2024
1 parent 0b7415f commit ad9cdb1
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public final class ProjectileData {
private Material material;

public boolean isBouncyBlock(Block block) {
if (settings.contains(ProjectileSetting.ALL_BLOCKS)) return true;
if (!blocks.isEmpty() && block != null) return blocks.contains(block.getType());
return true;
return false;
}

public void addBlock(Material material) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static ProjectileData defaultData() {
defaultData.addSetting(ProjectileSetting.DROPS);
defaultData.addSetting(ProjectileSetting.REMOVES);
defaultData.addSetting(ProjectileSetting.RETURNS);
defaultData.addSetting(ProjectileSetting.ALL_BLOCKS);
defaultData.addBlock(Material.GRASS_BLOCK);
defaultData.addBlock(Material.SAND);
defaultData.addBlock(Material.STONE);
Expand All @@ -22,6 +23,7 @@ public static ProjectileData defaultData() {
public static ProjectileData snowBallData() {
ProjectileData snowballData = new ProjectileData();
snowballData.setMaterial(Material.SNOWBALL);
snowballData.addSetting(ProjectileSetting.ALL_BLOCKS);
snowballData.addSetting(ProjectileSetting.REMOVES);
snowballData.addSetting(ProjectileSetting.RETURNS);
snowballData.addSetting(ProjectileSetting.DROPS);
Expand All @@ -37,6 +39,7 @@ public static ProjectileData snowBallData() {
public static ProjectileData turtleEggData() {
ProjectileData turtleEggData = new ProjectileData();
turtleEggData.setMaterial(Material.TURTLE_EGG);
turtleEggData.addSetting(ProjectileSetting.ALL_BLOCKS);
turtleEggData.addSetting(ProjectileSetting.REMOVES);
turtleEggData.addSetting(ProjectileSetting.DROPS);
turtleEggData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.0D);
Expand All @@ -51,6 +54,7 @@ public static ProjectileData turtleEggData() {
public static ProjectileData hotPotatoData() {
ProjectileData hotPotatoData = new ProjectileData();
hotPotatoData.setMaterial(Material.BAKED_POTATO);
hotPotatoData.addSetting(ProjectileSetting.ALL_BLOCKS);
hotPotatoData.addSetting(ProjectileSetting.REMOVES);
hotPotatoData.addSetting(ProjectileSetting.RETURNS);
hotPotatoData.addSetting(ProjectileSetting.DROPS);
Expand All @@ -66,6 +70,7 @@ public static ProjectileData hotPotatoData() {
public static ProjectileData newtonsAppleData() {
ProjectileData newtonsAppleData = new ProjectileData();
newtonsAppleData.setMaterial(Material.APPLE);
newtonsAppleData.addSetting(ProjectileSetting.ALL_BLOCKS);
newtonsAppleData.addSetting(ProjectileSetting.REMOVES);
newtonsAppleData.addSetting(ProjectileSetting.RETURNS);
newtonsAppleData.addSetting(ProjectileSetting.DROPS);
Expand All @@ -81,6 +86,7 @@ public static ProjectileData newtonsAppleData() {
public static ProjectileData groovyJukeBoxData() {
ProjectileData groovyJukeBoxData = new ProjectileData();
groovyJukeBoxData.setMaterial(Material.JUKEBOX);
groovyJukeBoxData.addSetting(ProjectileSetting.ALL_BLOCKS);
groovyJukeBoxData.addSetting(ProjectileSetting.REMOVES);
groovyJukeBoxData.addSetting(ProjectileSetting.RETURNS);
groovyJukeBoxData.addSetting(ProjectileSetting.DROPS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum ProjectileSetting {
DROPS("Item drops when projectile stops moving"),
GLOWS("Makes the projectile glow"),
ITEM_NAME("Name above item when dropped"),
ALL_BLOCKS("Bounces on all blocks"),
REMOVES("Projectile is removed from inventory");

private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@ public enum Menu implements Parseable {
EDIT_AMOUNT_LORE(List.of("", "&7Left-Click to increase", "&7Right-Click to decrease")),
EDIT_BLOCK_TITLE("&eEdit Blocks"),
EDIT_BLOCK_LORE(List.of("&7Click to edit allowed blocks.")),
EDIT_BLOCK_DISABLED_TITLE("&cEdit Blocks"),
EDIT_BLOCK_DISABLED_LORE(List.of("&7Can already bounce on all blocks", "&7Available to change in settings")),
EDIT_COLOR_TITLE("<0><1>"),
EDIT_COLOR_LORE(List.of("&7Click to select color")),
EDIT_DELETE_TITLE("&cDelete"),
EDIT_DELETE_LORE(List.of("&7Click to delete bouncy ball")),
EDIT_MATERIAL_TITLE("&eEdit Materials"),
EDIT_MATERIAL_LORE(List.of("&7Click to edit material.")),
EDIT_PHYSICS_TITLE("&b<0>"),
EDIT_PHYSICS_LORE(List.of(
EDIT_PHYSIC_TITLE("&b<0>"),
EDIT_PHYSIC_LORE(List.of(
"&f<0>",
"",
"&7Amount: &f<1>",
"",
"&7Left-Click to increment",
"&7Right-Click to decrement")),
EDIT_PHYSICS_TITLE("&eEdit Physics"),
EDIT_PHYSICS_LORE(List.of("Click to edit material.")),
EDIT_PARTICLE_TITLE("&eEdit Particles"),
EDIT_PARTICLE_LORE(List.of("&7Click to edit particles.")),
EDIT_SET_BLOCK_TITLE("&e<0>"),
Expand All @@ -43,6 +47,8 @@ public enum Menu implements Parseable {
EDIT_SET_BLOCK_LORE(List.of("&7Click to set block as bounce-able.")),
EDIT_SET_MATERIAL_LORE(List.of("&7Click to set material.")),
EDIT_SET_PARTICLE_LORE(List.of("&7Click to set particle.")),
EDIT_SETTINGS_TITLE("&eEdit Settings"),
EDIT_SETTINGS_LORE(List.of("&7Click to edit settings.")),
EDIT_CURRENT_BLOCK_TITLE("&b<0>"),
EDIT_CURRENT_MATERIAL_TITLE("&b<0>"),
EDIT_CURRENT_PARTICLE_TITLE("&b<0>"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.huskydreaming.bouncyball.data.particles.ParticleColor;
import com.huskydreaming.bouncyball.data.projectiles.ProjectileData;
import com.huskydreaming.bouncyball.data.projectiles.ProjectilePhysics;
import com.huskydreaming.bouncyball.data.projectiles.ProjectileSetting;
import com.huskydreaming.bouncyball.handlers.interfaces.InventoryHandler;
import com.huskydreaming.bouncyball.inventories.*;
import com.huskydreaming.bouncyball.repositories.interfaces.ProjectileRepository;
Expand Down Expand Up @@ -51,7 +53,7 @@ public SmartInventory getEditInventory(HuskyPlugin plugin, String key) {
return SmartInventory.builder()
.manager(inventoryManager)
.id("editInventory")
.size(5, 9)
.size(3, 9)
.provider(mainInventory)
.title("Editing: " + name)
.build();
Expand Down Expand Up @@ -110,8 +112,40 @@ public SmartInventory getParticleInventory(HuskyPlugin plugin, String key) {
.manager(inventoryManager)
.id("particleInventory")
.size(Math.min(rows + 2, 5), 9)
.provider(particleInventory)
.title("Particles: " + name)
.provider(particleInventory)
.build();
}

@Override
public SmartInventory getSettingsInventory(HuskyPlugin plugin, String key) {
ProjectileSetting[] settings = ProjectileSetting.values();
int rows = (int) Math.ceil((double) settings.length / 9);

SettingsInventory settingsInventory = new SettingsInventory(plugin, key, rows, settings);
String name = Util.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("settingsInventory")
.title("Settings: " + name)
.size(Math.min(rows + 2, 5), 9)
.provider(settingsInventory)
.build();
}

@Override
public SmartInventory getPhysicsInventory(HuskyPlugin plugin, String key) {
ProjectilePhysics[] physics = ProjectilePhysics.values();
int rows = (int) Math.ceil((double) physics.length / 9);

PhysicsInventory physicsInventory = new PhysicsInventory(plugin, key, rows, physics);
String name = Util.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("physicsInventory")
.title("Physics: " + name)
.size(Math.min(rows + 2, 5), 9)
.provider(physicsInventory)
.build();
}

Expand All @@ -124,9 +158,9 @@ public SmartInventory getColorInventory(HuskyPlugin plugin, String key) {
return SmartInventory.builder()
.manager(inventoryManager)
.id("colorInventory")
.title("Select Color")
.size(Math.min(rows + 2, 5), 9)
.provider(colorInventory)
.title("Particle Color")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ public interface InventoryHandler extends Handler {

SmartInventory getParticleInventory(HuskyPlugin plugin, String key);

SmartInventory getSettingsInventory(HuskyPlugin plugin, String key);

SmartInventory getPhysicsInventory(HuskyPlugin plugin, String key);

SmartInventory getColorInventory(HuskyPlugin plugin, String key);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.huskydreaming.bouncyball.inventories;

import com.huskydreaming.bouncyball.data.projectiles.ProjectileData;
import com.huskydreaming.bouncyball.data.projectiles.ProjectilePhysics;
import com.huskydreaming.bouncyball.data.projectiles.ProjectileSetting;
import com.huskydreaming.bouncyball.handlers.interfaces.InventoryHandler;
import com.huskydreaming.bouncyball.enumerations.Menu;
import com.huskydreaming.bouncyball.repositories.interfaces.ProjectileRepository;
import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.huskycore.inventories.InventoryItem;
import com.huskydreaming.huskycore.storage.parseables.DefaultMenu;
import com.huskydreaming.huskycore.utilities.builders.ItemBuilder;
import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.content.InventoryContents;
Expand All @@ -17,8 +15,6 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand All @@ -43,20 +39,12 @@ public void init(Player player, InventoryContents contents) {

contents.set(0, 0, InventoryItem.back(player, inventoryHandler.getBouncyBallsInventory(plugin)));

contents.set(1, 2, editBlocks());
contents.set(1, 3, editMaterials());
contents.set(1, 4, editParticles());
contents.set(1, 5, deleteItem());

int index = 2;
for (ProjectilePhysics projectilePhysics : ProjectilePhysics.values()) {
contents.set(2, index++, physicsItem(projectilePhysics, contents));
}

index = 2;
for (ProjectileSetting projectileSetting : ProjectileSetting.values()) {
contents.set(3, index++, activeItem(projectileSetting, contents));
}
contents.set(1, 1, editBlocks());
contents.set(1, 2, editMaterials());
contents.set(1, 3, editParticles());
contents.set(1, 4, editSettings());
contents.set(1, 5, editPhysics());
contents.set(1, 7, deleteItem());
}

@Override
Expand All @@ -65,14 +53,23 @@ public void update(Player player, InventoryContents contents) {
}

private ClickableItem editBlocks() {
ProjectileData projectileData = projectileRepository.getProjectileData(key);
Set<ProjectileSetting> settings = projectileData.getSettings();

boolean allBlocks = settings.contains(ProjectileSetting.ALL_BLOCKS);

String title = allBlocks ? Menu.EDIT_BLOCK_DISABLED_TITLE.parse() : Menu.EDIT_BLOCK_TITLE.parse();
List<String> lore = allBlocks ? Menu.EDIT_BLOCK_DISABLED_LORE.parseList() : Menu.EDIT_BLOCK_LORE.parseList();
Material material = allBlocks ? Material.BEDROCK : Material.GRASS_BLOCK;

ItemStack itemStack = ItemBuilder.create()
.setDisplayName(Menu.EDIT_BLOCK_TITLE.parse())
.setLore(Menu.EDIT_BLOCK_LORE.parseList())
.setMaterial(Material.GRASS_BLOCK)
.setDisplayName(title)
.setLore(lore)
.setMaterial(material)
.build();

return ClickableItem.of(itemStack, e -> {
if (e.getWhoClicked() instanceof Player player) {
if (e.getWhoClicked() instanceof Player player && !allBlocks) {
inventoryHandler.getBlockInventory(player.getWorld(), plugin, key).open(player);
}
});
Expand All @@ -92,109 +89,65 @@ private ClickableItem editMaterials() {
});
}

private ClickableItem deleteItem() {
private ClickableItem editSettings() {
ItemStack itemStack = ItemBuilder.create()
.setDisplayName(Menu.EDIT_DELETE_TITLE.parse())
.setLore(Menu.EDIT_DELETE_LORE.parseList())
.setMaterial(Material.TNT_MINECART)
.setDisplayName(Menu.EDIT_SETTINGS_TITLE.parse())
.setLore(Menu.EDIT_SETTINGS_LORE.parseList())
.setMaterial(Material.COMPARATOR)
.build();

return ClickableItem.of(itemStack, e -> {
if (e.getWhoClicked() instanceof Player player) {
projectileRepository.removeProjectileData(key);

if (projectileRepository.getProjectileDataMap().isEmpty()) {
player.closeInventory();
} else {
inventoryHandler.getBouncyBallsInventory(plugin).open(player);
}

inventoryHandler.getSettingsInventory(plugin, key).open(player);
}
});
}

private ClickableItem editParticles() {
private ClickableItem editPhysics() {
ItemStack itemStack = ItemBuilder.create()
.setDisplayName(Menu.EDIT_PARTICLE_TITLE.parse())
.setLore(Menu.EDIT_PARTICLE_LORE.parseList())
.setMaterial(Material.NETHER_STAR)
.setDisplayName(Menu.EDIT_PHYSICS_TITLE.parse())
.setLore(Menu.EDIT_SETTINGS_LORE.parseList())
.setMaterial(Material.FEATHER)
.build();

return ClickableItem.of(itemStack, e -> {
if (e.getWhoClicked() instanceof Player player) {
inventoryHandler.getParticleInventory(plugin, key).open(player);
inventoryHandler.getPhysicsInventory(plugin, key).open(player);
}
});
}

private ClickableItem activeItem(ProjectileSetting projectileSetting, InventoryContents contents) {
String materialEnabled = DefaultMenu.ENABLE_MATERIAL.parse();
String materialDisabled = DefaultMenu.DISABLED_MATERIAL.parse();

String displayNameEnabled = DefaultMenu.ENABLE_TITLE.parameterize(projectileSetting.name());
String displayNameDisabled = DefaultMenu.DISABLED_TITLE.parameterize(projectileSetting.name());

ProjectileData projectileData = projectileRepository.getProjectileData(key);
Set<ProjectileSetting> settings = projectileData.getSettings();

boolean enabled = settings.contains(projectileSetting);

String displayName = enabled ? displayNameEnabled : displayNameDisabled;
Material material = Material.valueOf(enabled ? materialEnabled : materialDisabled);
String description = enabled ? DefaultMenu.DESCRIPTION_ENABLE.parse() : DefaultMenu.DESCRIPTION_DISABLE.parse();

List<String> strings = new ArrayList<>();
strings.add(DefaultMenu.DESCRIPTION_DEFAULT.parameterize(projectileSetting.getDescription()));
strings.add("");
strings.add(description);

private ClickableItem deleteItem() {
ItemStack itemStack = ItemBuilder.create()
.setDisplayName(displayName)
.setLore(strings)
.setMaterial(material)
.setDisplayName(Menu.EDIT_DELETE_TITLE.parse())
.setLore(Menu.EDIT_DELETE_LORE.parseList())
.setMaterial(Material.TNT_MINECART)
.build();

return ClickableItem.of(itemStack, e -> {
if (e.getWhoClicked() instanceof Player player) {
if (settings.contains(projectileSetting)) {
projectileData.removeSetting(projectileSetting);
projectileRepository.removeProjectileData(key);

if (projectileRepository.getProjectileDataMap().isEmpty()) {
player.closeInventory();
} else {
projectileData.addSetting(projectileSetting);
inventoryHandler.getBouncyBallsInventory(plugin).open(player);
}
contents.inventory().open(player);

}
});
}

private ClickableItem physicsItem(ProjectilePhysics projectilePhysics, InventoryContents contents) {
ProjectileData projectileData = projectileRepository.getProjectileData(key);
double amount = projectileData.getPhysics(projectilePhysics);

private ClickableItem editParticles() {
ItemStack itemStack = ItemBuilder.create()
.setDisplayName(Menu.EDIT_PHYSICS_TITLE.parameterize(projectilePhysics.name()))
.setLore(Menu.EDIT_PHYSICS_LORE.parameterizeList(projectilePhysics.getDescription(), amount))
.setMaterial(projectilePhysics.getMaterial())
.setDisplayName(Menu.EDIT_PARTICLE_TITLE.parse())
.setLore(Menu.EDIT_PARTICLE_LORE.parseList())
.setMaterial(Material.NETHER_STAR)
.build();

return ClickableItem.of(itemStack, e -> {
if (e.getWhoClicked() instanceof Player player) {
double increment = projectilePhysics.getIncrement();
DecimalFormat df = new DecimalFormat("0.00");
if (e.isLeftClick()) {
projectileData.setPhysics(projectilePhysics, Double.parseDouble(df.format(amount + increment)));
contents.inventory().open(player);
return;
}
if (e.isRightClick()) {
if (amount <= increment) {
// This is a safeguard in case the amount is offset
projectileData.setPhysics(projectilePhysics, increment);
contents.inventory().open(player);
return;
}
projectileData.setPhysics(projectilePhysics, Double.parseDouble(df.format(amount - increment)));
contents.inventory().open(player);
}
inventoryHandler.getParticleInventory(plugin, key).open(player);
}
});
}
Expand Down
Loading

0 comments on commit ad9cdb1

Please sign in to comment.