Skip to content

Commit

Permalink
Merge branch 'Crazy-Crew:main' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Feb 15, 2024
2 parents 40b0f4c + b36e311 commit 57ca45f
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 63 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ Crate:
* Note: We only have 3 rows, so you obviously can only have 1 tier per row. This is not likely to change for this Crate Type...

## Enhancements:
* Added a check if the crate type is invalid, It will notify you in console and show you valid crate types.
* Updated slot checks for menu items to rely on PersistentDataContainer.
* Re-organized the default /crate gui
* Check uuids for quad crate sessions over player objects.
Expand All @@ -146,4 +145,4 @@ Crate:

## Other:
* [Feature Requests](https://github.com/Crazy-Crew/CrazyCrates/issues)
* [Bug Reports](https://github.com/Crazy-Crew/CrazyCrates/issues)
* [Bug Reports](https://github.com/Crazy-Crew/CrazyCrates/issues)
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,19 @@
</details>

### Resource Page
<a href="https://modrinth.com/plugin/crazycrates">![Modrinth](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/compact/available/modrinth_46h.png)</a>
[![Hangar](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/compact/available/hangar_46h.png)](https://hangar.papermc.io/CrazyCrew/CrazyCrates)
[![Modrinth](https://raw.githubusercontent.com/intergrav/devins-badges/v3/assets/compact/available/modrinth_46h.png)](https://modrinth.com/user/plugin/crazycrates)

## Getting Started

How to get started with contributing / maintaining your own version of CrazyCrates!

### Prerequisites

A list of things necessary to make sure you can build CrazyCrates properly.
* Intellij IDEA
* > https://www.jetbrains.com/idea/download/
* Gradle

### Installation

1. Clone the repo
```sh
git clone https://github.com/Crazy-Crew/CrazyCrates.git
Expand All @@ -74,19 +72,16 @@ A list of things necessary to make sure you can build CrazyCrates properly.
```

## Roadmap

Check our public [trello board](https://trello.com/b/bzQ5TwXo) for our current plans, any bugs and general tracking of the project progress.

## Contributing

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/yourfeature`)
3. Commit your Changes (`git commit -m 'your amazing feature.'`)
4. Push to the Branch (`git push`)
5. Open a Pull Request to the `main` branch to add your feature/fix.

## License

Distributed under the MIT License. See [`LICENSE`](/LICENSE) for more information.

[discord-shield]: https://img.shields.io/discord/182615261403283459.svg?style=flat&logo=appveyor
Expand Down
5 changes: 3 additions & 2 deletions buildSrc/src/main/kotlin/paper-plugin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ repositories {
}

val mcVersion = rootProject.properties["minecraftVersion"] as String
val paperVersion = rootProject.properties["paperVersion"] as String

project.version = if (System.getenv("BUILD_NUMBER") != null) "$paperVersion-${System.getenv("BUILD_NUMBER")}" else paperVersion
project.version = if (System.getenv("BUILD_NUMBER") != null) "${rootProject.version}-${System.getenv("BUILD_NUMBER")}" else rootProject.version

dependencies {
paperweight.paperDevBundle("$mcVersion-R0.1-SNAPSHOT")
Expand All @@ -47,6 +46,8 @@ tasks {
runServer {
jvmArgs("-Dnet.kyori.ansi.colorLevel=truecolor")

defaultCharacterEncoding = Charsets.UTF_8.name()

minecraftVersion(mcVersion)
}

Expand Down
5 changes: 0 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ issues = https://github.com/Crazy-Crew/CrazyCrates/issues
group = com.badbones69.crazycrates
description = Add unlimited crates to your server with 10 different crate types to choose from!
version = 1.21

paperVersion = 1.21
fabricVersion = 1.21
forgeVersion = 1.21

apiVersion = 1.20

minecraftVersion = 1.20.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.badbones69.crazycrates.listeners.menus.CrateMenuListener;
import com.badbones69.crazycrates.listeners.menus.CratePreviewListener;
import com.badbones69.crazycrates.listeners.menus.CrateTierListener;
import com.badbones69.crazycrates.listeners.other.EntityDamageListener;
import com.badbones69.crazycrates.tasks.BukkitUserManager;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.badbones69.crazycrates.tasks.crates.other.quadcrates.SessionManager;
Expand Down Expand Up @@ -77,6 +78,7 @@ public void onEnable() {
pluginManager.registerEvents(new BrokeLocationsListener(), this);

pluginManager.registerEvents(new CrateControlListener(), this);
pluginManager.registerEvents(new EntityDamageListener(), this);
pluginManager.registerEvents(new MobileCrateListener(), this);
pluginManager.registerEvents(new CosmicCrateListener(), this);
pluginManager.registerEvents(new QuadCrateListener(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ public void cancel() {
* @return the display item of the picked prize.
*/
public ItemStack getDisplayItem() {
return getCrate().pickPrize(getPlayer()).getDisplayItem();
return getCrate().pickPrize(getPlayer()).getDisplayItem(getPlayer());
}

/**
* @return the display item of the picked prize with a tier.
*/
public ItemStack getDisplayItem(Tier tier) {
return getCrate().pickPrize(getPlayer(), tier).getDisplayItem();
return getCrate().pickPrize(getPlayer(), tier).getDisplayItem(getPlayer());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void setDefaultItems(Inventory inventory) {
}

private List<ItemStack> getPageItems(int page) {
List<ItemStack> list = !this.isTier ? getCrate().getPreviewItems() : getCrate().getPreviewItems(this.tier);
List<ItemStack> list = !this.isTier ? getCrate().getPreviewItems(getPlayer()) : getCrate().getPreviewItems(this.tier, getPlayer());
List<ItemStack> items = new ArrayList<>();

if (page <= 0) page = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,19 +748,34 @@ public List<ItemStack> getPreviewItems() {

return items;
}

/**
* Loads all the preview items and puts them into a list.
*
* @return a list of all the preview items that were created.
*/
public List<ItemStack> getPreviewItems(Player player) {
List<ItemStack> items = new ArrayList<>();

for (Prize prize : getPrizes()) {
items.add(prize.getDisplayItem(player));
}

return items;
}

/**
* Get prizes for tier specific preview gui's
*
* @param tier The tier to check
* @return list of prizes
*/
public List<ItemStack> getPreviewItems(Tier tier) {
public List<ItemStack> getPreviewItems(Tier tier, Player player) {
List<ItemStack> prizes = new ArrayList<>();

for (Prize prize : getPrizes()) {
if (prize.getTiers().contains(tier)) {
prizes.add(prize.getDisplayItem());
prizes.add(prize.getDisplayItem(player));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import com.badbones69.crazycrates.api.objects.other.ItemBuilder;
import com.badbones69.crazycrates.api.utils.MiscUtils;
import com.badbones69.crazycrates.support.libraries.PluginSupport;
import me.clip.placeholderapi.PlaceholderAPI;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -132,6 +134,61 @@ public ItemStack getDisplayItem() {
return this.itemStack.clone();
}

/**
* @return the display item that is shown for the preview and the winning prize.
*/
public ItemStack getDisplayItem(Player player) {
if (this.itemStack == null) {
ItemBuilder builder = this.displayItem;

if (PluginSupport.PLACEHOLDERAPI.isPluginEnabled()) {
String name = PlaceholderAPI.setPlaceholders(player, builder.getName());
builder.setName(name);

List<String> newLore = new ArrayList<>();

List<String> lore = builder.getLore();

if (lore != null) {
lore.forEach(line -> newLore.add(PlaceholderAPI.setPlaceholders(player, line)));
builder.setLore(newLore);
}
}

this.itemStack = builder.build();

ItemMeta itemMeta = this.itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();

container.set(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, this.prizeName);

this.itemStack.setItemMeta(itemMeta);

return this.itemStack.clone();
}

ItemStack item = this.itemStack.clone();

if (PluginSupport.PLACEHOLDERAPI.isPluginEnabled()) {
ItemMeta itemMeta = item.getItemMeta();

String name = PlaceholderAPI.setPlaceholders(player, itemMeta.getDisplayName());
itemMeta.setDisplayName(name);

List<String> lore = itemMeta.getLore();

if (lore != null) {
List<String> newLore = new ArrayList<>();
lore.forEach(line -> newLore.add(PlaceholderAPI.setPlaceholders(player, line)));
itemMeta.setLore(newLore);
}

item.setItemMeta(itemMeta);
}

return item;
}

/**
* @return the ItemBuilder of the display item.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.CrazyCrates;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
Expand Down Expand Up @@ -60,23 +61,15 @@ public static void spawnFirework(Location location, Color color) {

firework.setFireworkMeta(fireworkMeta);

setEntityData(firework, PersistentKeys.no_firework_damage);
PersistentDataContainer fireworkData = firework.getPersistentDataContainer();

fireworkData.set(PersistentKeys.no_firework_damage.getNamespacedKey(), PersistentDataType.BOOLEAN, true);

Server server = plugin.getServer();

server.getScheduler().scheduleSyncDelayedTask(plugin, firework::detonate, 3);
}

/**
* Add a persistent tag to an entity.
*/
@SuppressWarnings("unchecked")
public static void setEntityData(Entity entity, PersistentKeys key) {
PersistentDataContainer entityData = entity.getPersistentDataContainer();

entityData.set(key.getNamespacedKey(), key.getType(), true);
}

/**
* Checks if the player's inventory is empty by checking if the first empty slot is -1.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.badbones69.crazycrates.listeners;

import com.badbones69.crazycrates.tasks.InventoryManager;
import org.bukkit.entity.Firework;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerAttemptPickupItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.persistence.PersistentDataContainer;
import com.badbones69.crazycrates.CrazyCrates;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import com.badbones69.crazycrates.tasks.crates.CrateManager;
import com.badbones69.crazycrates.api.enums.PersistentKeys;
import us.crazycrew.crazycrates.api.enums.types.CrateType;

public class MiscListener implements Listener {
Expand Down Expand Up @@ -79,15 +75,6 @@ public void onPlayerQuit(PlayerQuitEvent event) {
this.crateManager.removePlayerKeyType(player);
}

@EventHandler(ignoreCancelled = true)
public void onFireworkDamage(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Firework firework) {
PersistentDataContainer container = firework.getPersistentDataContainer();

if (container.has(PersistentKeys.no_firework_damage.getNamespacedKey())) event.setCancelled(true);
}
}

@EventHandler
public void onItemPickUp(InventoryPickupItemEvent event) {
if (this.crateManager.isDisplayReward(event.getItem())) event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onInventoryClickPrize(InventoryClickEvent event) {

this.plugin.getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, crate.getName(), prize));

event.setCurrentItem(prize.getDisplayItem());
event.setCurrentItem(prize.getDisplayItem(player));

cosmic.getCrate().playSound(player, player.getLocation(), "click-sound","UI_BUTTON_CLICK", SoundCategory.PLAYERS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onChestClick(PlayerInteractEvent event) {
PrizeManager.givePrize(player, prize, crate);

// Get the display item.
ItemStack display = prize.getDisplayItem();
ItemStack display = prize.getDisplayItem(player);

// Get the item meta.
ItemMeta itemMeta = display.getItemMeta();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void onChestClick(PlayerInteractEvent event) {
// Set data
reward.setMetadata("betterdrops_ignore", new FixedMetadataValue(plugin, true));
reward.setVelocity(new Vector(0, .2, 0));
reward.setCustomName(prize.getDisplayItem().getItemMeta().getDisplayName());
reward.setCustomName(prize.getDisplayItem(player).getItemMeta().getDisplayName());
reward.setCustomNameVisible(true);
reward.setPickupDelay(Integer.MAX_VALUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onInventoryClick(InventoryClickEvent event) {
if (item != null && item.getType().toString().contains(Material.GLASS_PANE.toString())) {
int slot = event.getRawSlot();
Prize prize = crate.pickPrize(player);
inventory.setItem(slot, prize.getDisplayItem());
inventory.setItem(slot, prize.getDisplayItem(player));

if (this.crateManager.hasCrateTask(player)) this.crateManager.endCrate(player);

Expand All @@ -69,7 +69,7 @@ public void onInventoryClick(InventoryClickEvent event) {
@Override
public void run() {
for (int i = 0; i < 9; i++) {
if (i != slot) inventory.setItem(i, crate.pickPrize(player).getDisplayItem());
if (i != slot) inventory.setItem(i, crate.pickPrize(player).getDisplayItem(player));
}

if (crateManager.hasCrateTask(player)) crateManager.endCrate(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.badbones69.crazycrates.listeners.other;

import com.badbones69.crazycrates.api.enums.PersistentKeys;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.persistence.PersistentDataContainer;

public class EntityDamageListener implements Listener {

@EventHandler(ignoreCancelled = true)
public void onFireworkDamage(EntityDamageEvent event) {
Entity directEntity = event.getDamageSource().getDirectEntity();

if (directEntity instanceof Firework firework) {
PersistentDataContainer container = firework.getPersistentDataContainer();

if (container.has(PersistentKeys.no_firework_damage.getNamespacedKey())) {
event.setCancelled(true);
}
}
}
}
Loading

0 comments on commit 57ca45f

Please sign in to comment.