Skip to content

Commit

Permalink
Version 7.3
Browse files Browse the repository at this point in the history
- Added cooldown for bouncy balls
- Fixed a small particle bug
  • Loading branch information
HuskyDreaming committed Nov 18, 2024
1 parent ad9cdb1 commit 30e2de0
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.huskydreaming</groupId>
<artifactId>bouncyballs</artifactId>
<version>7.1-RELEASE</version>
<version>7.2-RELEASE</version>
<build>
<resources>
<resource>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.huskydreaming</groupId>
<artifactId>bouncyballs</artifactId>
<version>7.1-RELEASE</version>
<version>7.3-RELEASE</version>

<properties>
<minecraft.version>1.20.4-R0.1-SNAPSHOT</minecraft.version>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>com.huskydreaming</groupId>
<artifactId>huskycore</artifactId>
<version>1.7-SNAPSHOT</version>
<version>1.7.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.huskycore.commands.annotations.CommandAnnotation;
import com.huskydreaming.huskycore.commands.providers.PlayerCommandProvider;
import com.huskydreaming.huskycore.utilities.Util;
import com.huskydreaming.huskycore.utilities.NumberUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void onCommand(Player player, String[] strings) {
return;
}

if (!Util.isNumeric(strings[3])) {
if (!NumberUtil.isNumeric(strings[3])) {
player.sendMessage(Locale.INVALID_NUMBER.prefix(strings[1]));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import org.bukkit.Material;
import org.bukkit.block.Block;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public final class ProjectileData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static ProjectileData defaultData() {
defaultData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.0D);
defaultData.setPhysics(ProjectilePhysics.DAMPING, 0.75D);
defaultData.setPhysics(ProjectilePhysics.THRESHOLD, 0.8D);
defaultData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
defaultData.addSetting(ProjectileSetting.DROPS);
defaultData.addSetting(ProjectileSetting.REMOVES);
defaultData.addSetting(ProjectileSetting.RETURNS);
Expand All @@ -30,6 +31,7 @@ public static ProjectileData snowBallData() {
snowballData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.0D);
snowballData.setPhysics(ProjectilePhysics.THRESHOLD, 0.25D);
snowballData.setPhysics(ProjectilePhysics.DAMPING, 0.75D);
snowballData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
snowballData.addBlock(Material.GRASS_BLOCK);
snowballData.addBlock(Material.SAND);
snowballData.addBlock(Material.STONE);
Expand All @@ -45,6 +47,7 @@ public static ProjectileData turtleEggData() {
turtleEggData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.0D);
turtleEggData.setPhysics(ProjectilePhysics.THRESHOLD, 0.35D);
turtleEggData.setPhysics(ProjectilePhysics.DAMPING, 0.75D);
turtleEggData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
turtleEggData.addBlock(Material.GRASS_BLOCK);
turtleEggData.addBlock(Material.SAND);
turtleEggData.addBlock(Material.STONE);
Expand All @@ -61,6 +64,7 @@ public static ProjectileData hotPotatoData() {
hotPotatoData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 0.8D);
hotPotatoData.setPhysics(ProjectilePhysics.THRESHOLD, 0.20D);
hotPotatoData.setPhysics(ProjectilePhysics.DAMPING, 0.75D);
hotPotatoData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
hotPotatoData.addBlock(Material.GRASS_BLOCK);
hotPotatoData.addBlock(Material.SAND);
hotPotatoData.addBlock(Material.STONE);
Expand All @@ -77,6 +81,7 @@ public static ProjectileData newtonsAppleData() {
newtonsAppleData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.5D);
newtonsAppleData.setPhysics(ProjectilePhysics.THRESHOLD, 0.15D);
newtonsAppleData.setPhysics(ProjectilePhysics.DAMPING, 0.75D);
newtonsAppleData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
newtonsAppleData.addBlock(Material.GRASS_BLOCK);
newtonsAppleData.addBlock(Material.SAND);
newtonsAppleData.addBlock(Material.STONE);
Expand All @@ -94,6 +99,7 @@ public static ProjectileData groovyJukeBoxData() {
groovyJukeBoxData.setPhysics(ProjectilePhysics.LAUNCH_VELOCITY, 1.0D);
groovyJukeBoxData.setPhysics(ProjectilePhysics.THRESHOLD, 0.20D);
groovyJukeBoxData.setPhysics(ProjectilePhysics.DAMPING, 0.45D);
groovyJukeBoxData.setPhysics(ProjectilePhysics.COOLDOWN, 0.0D);
groovyJukeBoxData.addBlock(Material.GRASS_BLOCK);
groovyJukeBoxData.addBlock(Material.SAND);
groovyJukeBoxData.addBlock(Material.STONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.Material;

public enum ProjectilePhysics {
COOLDOWN("How often the projectile can be thrown", Material.WATER_BUCKET, 1.0D),
DAMPING("Velocity damped when it hits a surface", Material.FEATHER, 0.15D),
LAUNCH_VELOCITY("Initial velocity of the snowball when thrown", Material.BLAZE_POWDER, 0.1D),
THRESHOLD("The speed at which the projectile disintegrate", Material.GUNPOWDER, 0.1D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Locale implements Parseable {
BOUNCY_BALL_GIVE_AMOUNT("You have been given &ex<0> <1>&7 bouncy ball(s)."),
BOUNCY_BALL_SEND("You have given &a<0> &7a <1>&7 bouncy ball."),
BOUNCY_BALL_SEND_AMOUNT("You have given &a<0> &ex<1> <2>&7 bouncy ball(s)."),
COOLDOWN("You can throw a bouncy ball again in &b<0>&7."),
INVALID_NUMBER("You must provide a valid number"),
PLAYER_NULL("That player does not seem to exist."),
PLAYER_OFFLINE("You do not have permissions to run that command."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.huskydreaming.bouncyball.inventories.*;
import com.huskydreaming.bouncyball.repositories.interfaces.ProjectileRepository;
import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.huskycore.utilities.ChatUtil;
import com.huskydreaming.huskycore.utilities.Util;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
Expand Down Expand Up @@ -49,7 +50,7 @@ public SmartInventory getBouncyBallsInventory(HuskyPlugin plugin) {
@Override
public SmartInventory getEditInventory(HuskyPlugin plugin, String key) {
EditInventory mainInventory = new EditInventory(plugin, key);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("editInventory")
Expand All @@ -70,7 +71,7 @@ public SmartInventory getMaterialInventory(World world, HuskyPlugin plugin, Stri

int rows = (int) Math.ceil((double) supportedMaterials.length / 9);
MaterialInventory materialInventory = new MaterialInventory(plugin, key, rows, supportedMaterials, false);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("materialInventory")
Expand All @@ -91,7 +92,7 @@ public SmartInventory getBlockInventory(World world, HuskyPlugin plugin, String

int rows = (int) Math.ceil((double) supportedMaterials.length / 9);
MaterialInventory materialInventory = new MaterialInventory(plugin, key, rows, supportedMaterials, true);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("blockInventory")
Expand All @@ -107,7 +108,7 @@ public SmartInventory getParticleInventory(HuskyPlugin plugin, String key) {
int rows = (int) Math.ceil((double) particles.length / 9);

ParticleInventory particleInventory = new ParticleInventory(plugin, key, rows, particles);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("particleInventory")
Expand All @@ -123,7 +124,7 @@ public SmartInventory getSettingsInventory(HuskyPlugin plugin, String key) {
int rows = (int) Math.ceil((double) settings.length / 9);

SettingsInventory settingsInventory = new SettingsInventory(plugin, key, rows, settings);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("settingsInventory")
Expand All @@ -139,7 +140,7 @@ public SmartInventory getPhysicsInventory(HuskyPlugin plugin, String key) {
int rows = (int) Math.ceil((double) physics.length / 9);

PhysicsInventory physicsInventory = new PhysicsInventory(plugin, key, rows, physics);
String name = Util.capitalize(key.replace("_", " "));
String name = ChatUtil.capitalize(key.replace("_", " "));
return SmartInventory.builder()
.manager(inventoryManager)
.id("physicsInventory")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public void postInitialize(HuskyPlugin plugin) {
Map<Projectile, String> projectileMap = projectileHandler.getProjectileMap();

Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> projectileMap.forEach((projectile, s) -> {
if(projectile == null) return;

Location location = projectile.getLocation();
World world = location.getWorld();
if (world == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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.enumerations.Locale;
import com.huskydreaming.bouncyball.handlers.interfaces.ProjectileHandler;
import com.huskydreaming.bouncyball.repositories.interfaces.ProjectileRepository;
import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.huskycore.utilities.Util;
import com.huskydreaming.huskycore.utilities.ChatUtil;
import com.huskydreaming.huskycore.utilities.TimeUtil;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -21,6 +23,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class ProjectileHandlerImpl implements ProjectileHandler {
Expand All @@ -29,6 +32,7 @@ public class ProjectileHandlerImpl implements ProjectileHandler {

private ProjectileRepository projectileRepository;
private final Map<Projectile, String> projectileMap = new ConcurrentHashMap<>();
private final Map<UUID, Long> cooldownMap = new ConcurrentHashMap<>();

@Override
public void initialize(HuskyPlugin plugin) {
Expand All @@ -42,6 +46,17 @@ public void postInitialize(HuskyPlugin plugin) {

@Override
public void launchProjectile(Plugin plugin, Player player, ItemStack itemStack, String key) {
UUID uuid = player.getUniqueId();
if(cooldownMap.containsKey(uuid)) {
long difference = cooldownMap.get(uuid) - System.currentTimeMillis();
if((difference / 1000L) > 0) {
String formattedTime = TimeUtil.convertTimeStamp(difference);
player.sendMessage(Locale.COOLDOWN.prefix(formattedTime));
return;
} else {
cooldownMap.remove(uuid);
}
}
ProjectileData projectileData = projectileRepository.getProjectileData(key);

if (projectileData.getSettings().contains(ProjectileSetting.REMOVES)) {
Expand All @@ -50,9 +65,12 @@ public void launchProjectile(Plugin plugin, Player player, ItemStack itemStack,

Snowball projectile = player.launchProjectile(Snowball.class);
PersistentDataContainer persistentDataContainer = projectile.getPersistentDataContainer();

persistentDataContainer.set(projectileNameSpacedKey, PersistentDataType.STRING, key);

double launchVelocity = projectileData.getPhysics(ProjectilePhysics.LAUNCH_VELOCITY);
long cooldown = (long) projectileData.getPhysics(ProjectilePhysics.COOLDOWN);
if(cooldown != 0.0D) cooldownMap.put(uuid, (cooldown * 1000L) + System.currentTimeMillis());

projectile.setVelocity(player.getLocation().getDirection().multiply(launchVelocity));
projectile.setGlowing(projectileData.getSettings().contains(ProjectileSetting.GLOWS));
projectile.setItem(new ItemStack(projectileData.getMaterial()));
Expand Down Expand Up @@ -179,7 +197,7 @@ public ItemStack getItemStackFromKey(String key) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) return null;

itemMeta.setDisplayName(ChatColor.RESET + Util.capitalize(key.replace("_", " ")));
itemMeta.setDisplayName(ChatColor.RESET + ChatUtil.capitalize(key.replace("_", " ")));
PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();

persistentDataContainer.set(projectileNameSpacedKey, PersistentDataType.STRING, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public void deserialize(HuskyPlugin plugin) {
String materialName = configuration.getString(key + ".material");
if(materialName != null) projectileData.setMaterial(Material.valueOf(materialName));

double cooldown = configuration.getDouble(key + ".physics.cooldown");
projectileData.setPhysics(ProjectilePhysics.COOLDOWN, cooldown);

double damping = configuration.getDouble(key + ".physics.damping");
projectileData.setPhysics(ProjectilePhysics.DAMPING, damping);

Expand Down Expand Up @@ -87,6 +90,7 @@ public void serialize(HuskyPlugin plugin) {
configuration.set(key + ".settings", settings);
configuration.set(key + ".blocks", blockMaterials);
configuration.set(key + ".material", projectileData.getMaterial().name());
configuration.set(key + ".physics.cooldown", projectileData.getPhysics(ProjectilePhysics.COOLDOWN));
configuration.set(key + ".physics.damping", projectileData.getPhysics(ProjectilePhysics.DAMPING));
configuration.set(key + ".physics.launch-velocity", projectileData.getPhysics(ProjectilePhysics.LAUNCH_VELOCITY));
configuration.set(key + ".physics.threshold", projectileData.getPhysics(ProjectilePhysics.THRESHOLD));
Expand Down

0 comments on commit 30e2de0

Please sign in to comment.