Skip to content

Commit

Permalink
Added new features
Browse files Browse the repository at this point in the history
Added snowball personalization and added /coralwinter addsnow command.
Also, some issues got fixed.
  • Loading branch information
itzCrih committed Dec 21, 2024
1 parent a222909 commit f0b51e6
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>it.itzcrih</groupId>
<artifactId>CoralWinter</artifactId>
<version>1.7-SNAPSHOT</version>
<version>1.8-SNAPSHOT-DEV3</version>
<packaging>jar</packaging>

<name>CoralWinter</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import it.itzcrih.coralwinter.CoralWinter;
import it.itzcrih.coralwinter.config.ConfigLoader;
import it.itzcrih.coralwinter.utils.SantaShovel;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -57,6 +55,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
handleSnowfallCommand(player, args);
break;

case "addsnow":
handleAddSnowCommand(player);
break;

default:
player.sendMessage(ChatColor.RED + "Unknown command. Use /coralwinter for help.");
break;
Expand Down Expand Up @@ -94,6 +96,39 @@ private void handleSantaShovelCommand(Player player) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getMessages().getString("commands.shovel_received")));
}

private void handleAddSnowCommand(Player player) {
if (!player.hasPermission("coralwinter.command.addsnow")) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getMessages().getString("errors.no_perm")));
return;
}

World world = player.getWorld();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getMessages().getString("commands.adding_snow")));

new BukkitRunnable() {
@Override
public void run() {
int radius = 50;

for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
int worldX = player.getLocation().getBlockX() + x;
int worldZ = player.getLocation().getBlockZ() + z;
int worldY = world.getHighestBlockYAt(worldX, worldZ);

Material blockAbove = world.getBlockAt(worldX, worldY, worldZ).getType();
Material blockBelow = world.getBlockAt(worldX, worldY - 1, worldZ).getType();

if (blockAbove == Material.AIR && blockBelow.isSolid() && blockBelow != Material.LEAVES) {
Bukkit.getScheduler().runTask(CoralWinter.getInstance(), () -> world.getBlockAt(worldX, worldY, worldZ).setType(Material.SNOW));
}
}
}
Bukkit.getScheduler().runTask(CoralWinter.getInstance(), () -> player.sendMessage(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getMessages().getString("commands.successfully_added_snow"))));
}
}.runTaskAsynchronously(CoralWinter.getInstance());
}

private final Map<UUID, Long> snowfallCooldowns = new HashMap<>();

private void handleSnowfallCommand(Player player, String[] args) {
Expand Down Expand Up @@ -167,6 +202,7 @@ private void sendHelpMessages(Player player) {
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3/coralwinter reload &7- Reload all configurations"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3/coralwinter santashovel &7- Get your own shovel"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3/coralwinter snow <player> &7- Generate snow particles near a player"));
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3/coralwinter addsnow &7- Add snow in the lobby"));
player.sendMessage("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public void onPlayerDamage(EntityDamageByEntityEvent event) {
damaged.getWorld().spigot().playEffect(damaged.getLocation(), Effect.SNOW_SHOVEL, 26, 0, 0.2F, 0.5F, 0.2F, 0.2F, 12, 387);
damaged.getWorld().spigot().playEffect(damaged.getLocation(), Effect.FLAME, 26, 0, 0.2F, 0.5F, 0.2F, 0.2F, 12, 387);

if (CoralWinter.getConfigLoader().getConfig().getBoolean("santashovel.snowball_knockback.enabled")) {
double knockbackMultiplier = CoralWinter.getConfigLoader().getConfig().getDouble("santashovel.snowball_knockback.horizontal");
double verticalBoost = CoralWinter.getConfigLoader().getConfig().getDouble("santashovel.snowball_knockback.vertical");
if (CoralWinter.getConfigLoader().getConfig().getBoolean("snowball.snowball_knockback.enabled")) {
double knockbackMultiplier = CoralWinter.getConfigLoader().getConfig().getDouble("snowball.snowball_knockback.horizontal");
double verticalBoost = CoralWinter.getConfigLoader().getConfig().getDouble("snowball.snowball_knockback.vertical");

Vector knockback = damager.getLocation().getDirection().multiply(knockbackMultiplier);
knockback.setY(knockback.getY() + verticalBoost);
Expand All @@ -127,7 +127,7 @@ public void onItemHeld(PlayerItemHeldEvent event) {
ItemStack newItem = player.getInventory().getItem(event.getNewSlot());

if (CoralWinter.getConfigLoader().getConfig().getBoolean("santashovel.when_holding_enable_effects")) {
if (newItem != null && newItem.hasItemMeta() && newItem.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&' ,CoralWinter.getConfigLoader().getConfig().getString("santashovel.display-name")))) {
if (newItem != null && newItem.hasItemMeta() && newItem.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&' ,CoralWinter.getConfigLoader().getConfig().getString("santashovel.display_name")))) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2, false, false));
player.setAllowFlight(true);
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1);
Expand All @@ -149,7 +149,7 @@ public void onRightClick(PlayerInteractEvent event) {
ItemStack item = player.getInventory().getItemInHand();

if (CoralWinter.getConfigLoader().getConfig().getBoolean("santashovel.right_click_ability_enabled")) {
if (item != null && item.hasItemMeta() && item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getConfig().getString("santashovel.display-name")))) {
if (item != null && item.hasItemMeta() && item.getItemMeta().getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', CoralWinter.getConfigLoader().getConfig().getString("santashovel.display_name")))) {
if (event.getAction().toString().contains("RIGHT_CLICK")) {
UUID uuid = player.getUniqueId();
long currentTime = System.currentTimeMillis();
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/it/itzcrih/coralwinter/utils/ChatUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.itzcrih.coralwinter.utils;

import org.bukkit.ChatColor;

import java.util.List;

public class ChatUtils {

public static String colorize(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

public static List<String> colorize(List<String> messages) {
messages.replaceAll(ChatUtils::colorize);
return messages;
}
}
17 changes: 3 additions & 14 deletions src/main/java/it/itzcrih/coralwinter/utils/SantaShovel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.itzcrih.coralwinter.utils;

import it.itzcrih.coralwinter.CoralWinter;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -35,12 +34,12 @@ public ItemStack createSantaShovel() {
ItemStack santaShovel = new ItemStack(spadeType, 1);
ItemMeta meta = santaShovel.getItemMeta();

String displayName = CoralWinter.getConfigLoader().getConfig().getString("santashovel.display-name");
String displayName = CoralWinter.getConfigLoader().getConfig().getString("santashovel.display_name");
List<String> lore = CoralWinter.getConfigLoader().getConfig().getStringList("santashovel.lore");

meta.setDisplayName(displayName != null ? colorize(displayName) : "Santa's Shovel");
meta.setDisplayName(displayName != null ? ChatUtils.colorize(displayName) : "Santa's Shovel");
if (lore != null && !lore.isEmpty()) {
meta.setLore(colorize(lore));
meta.setLore(ChatUtils.colorize(lore));
}

if (CoralWinter.getConfigLoader().getConfig().getBoolean("santashovel.enable_glow")) {
Expand All @@ -51,14 +50,4 @@ public ItemStack createSantaShovel() {
santaShovel.setItemMeta(meta);
return santaShovel;
}


public String colorize(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}

public List<String> colorize(List<String> messages) {
messages.replaceAll(this::colorize);
return messages;
}
}
27 changes: 25 additions & 2 deletions src/main/java/it/itzcrih/coralwinter/utils/SnowUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.List;

/**
* This code is made by
Expand All @@ -28,9 +32,28 @@ public static boolean canBreakSnowBlock(Player player, Block block) {

public static void giveSnowball(Player player) {
player.playSound(player.getLocation(), Sound.DIG_SNOW, 1.0f, 1.0f);
player.playSound(player.getLocation(), Sound.valueOf(CoralWinter.getConfigLoader().getConfig().getString("santashovel.sound_when_breaking")), 1.0f, 2.0f);
player.playSound(player.getLocation(),
Sound.valueOf(CoralWinter.getConfigLoader().getConfig().getString("santashovel.sound_when_breaking")),
1.0f, 2.0f);
player.getWorld().spigot().playEffect(player.getLocation(), Effect.SNOWBALL_BREAK, 26, 0, 0.2F, 0.5F, 0.2F, 0.2F, 12, 387);
player.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 1));

ItemStack snowball = new ItemStack(Material.SNOW_BALL, 1);
ItemMeta meta = snowball.getItemMeta();
if (meta != null) {
String displayName = CoralWinter.getConfigLoader().getConfig().getString("snowball.display_name");
List<String> lore = CoralWinter.getConfigLoader().getConfig().getStringList("snowball.lore");

meta.setDisplayName(displayName != null ? ChatUtils.colorize(displayName) : "Snowball");
if (lore != null && !lore.isEmpty()) {
meta.setLore(ChatUtils.colorize(lore));
}
if (CoralWinter.getConfigLoader().getConfig().getBoolean("snowball.enable_glow")) {
meta.addEnchant(Enchantment.DURABILITY, 1, true);
}
}

snowball.setItemMeta(meta);
player.getInventory().addItem(snowball);
}

// todo: Add 24/12 (xmas) event
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ commands:
shovel_received: "&7You have received the &bSanta Shovel&7!"
cooldown: "&cYou must wait %time_remaining% seconds before using this command again."
snow_start: "&7Magical snow starts falling around &b%target%&7!"
snow_end: "&7The magical snow has stopped."
snow_end: "&7The magical snow has stopped."
adding_snow: "&7Adding snow in progress... may take a while."
successfully_added_snow: "&7Snow has been added &bsuccessfully&7!"
16 changes: 15 additions & 1 deletion src/main/resources/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ santashovel:
# Should we enable santashovel command?
enable_command: true
# Display name of the shovel
display-name: "&c&lChristmas shovel"
display_name: "&c&lChristmas shovel"
# Description of the shovel
lore:
- "&7Damn, the whole lobby is full of snow."
- "&7I would definitely be happy if you clean it!"
- "&7 "
- "&7(Hold &bLeft-click &7to clean the snow)"
- "&7(Click &bRight-click &7to use special ability)"
# Should we enchant the shovel for a glow effect?
enable_glow: true
# Should we give Speed III and ability to fly when you hold your shovel?
Expand All @@ -32,6 +33,19 @@ santashovel:
right_click_ability_enabled: true
# What sound should we play whenever you break snow with your shovel?
sound_when_breaking: NOTE_PIANO

# Snowball settings
snowball:
# Display name of the snowball
display_name: "&3&lSnowball"
# Description of the snowball
lore:
- "&7This is Santa's best weapon."
- "&7Use it &cwisely&7! ;)"
- ""
- "&7(Click &bRight-click &7to throw it)"
# Should we enchant the snowball for a glow effect?
enable_glow: true
# Whenever you get hit by a snowball knockback values
snowball_knockback:
enabled: true
Expand Down

0 comments on commit f0b51e6

Please sign in to comment.