Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.crankedpvp</groupId>
<artifactId>ProjectCranked</artifactId>
<version>1.0</version>
</parent>
<artifactId>WarzoneChests</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>StorageUtilsShaded</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
<exclusions>
<exclusion>
<groupId>com.golfing.wineSpigot</groupId>
<artifactId>WineSpigot</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
<exclusions>
<exclusion>
<groupId>com.golfing.wineSpigot</groupId>
<artifactId>WineSpigot</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>CombatLog</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>LootTable</artifactId>
<exclusions>
<exclusion>
<groupId>com.golfing.wineSpigot</groupId>
<artifactId>WineSpigot</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
</dependencies>
<build>
<finalName>CrankedWarzoneChests</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>com.github.ben-manes.caffeine:caffeine</include>
</includes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,40 @@
package net.crankedpvp.warzonechests;
import lombok.Getter;
import me.mattstudios.mf.base.CommandManager;
import net.crankedpvp.warzonechests.commands.AdminCommand;
import net.crankedpvp.warzonechests.listener.WarzoneChestListeners;
import net.crankedpvp.warzonechests.listener.WarzoneChestSummonerListeners;
import net.crankedpvp.warzonechests.struct.WarzoneChestManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class WarzoneChestsPlugin extends JavaPlugin {
private WarzoneChestManager warzoneChestManager;
private CommandManager commandManager;
@Override
public void onEnable() {
this.warzoneChestManager = new WarzoneChestManager(this);
this.warzoneChestManager.loadAll();
this.registerListeners();
this.commandManager = new CommandManager(this);
this.commandManager.register(new AdminCommand());
}
@Override
public void onDisable() {
this.warzoneChestManager.saveAll();
}
private void registerListeners() {
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new WarzoneChestListeners(this), this);
pm.registerEvents(new WarzoneChestSummonerListeners(this), this);
}
}
@@ -0,0 +1,40 @@
package net.crankedpvp.warzonechests.commands;
import me.mattstudios.mf.annotations.Command;
import me.mattstudios.mf.annotations.Default;
import me.mattstudios.mf.annotations.Optional;
import me.mattstudios.mf.annotations.SubCommand;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.warzonechests.struct.items.WarzoneChestPlacerItem;
import net.crankedpvp.warzonechests.struct.items.WarzoneChestSummoner;
import org.bukkit.entity.Player;
@Command("cwc")
public class AdminCommand extends CommandBase {
@Default
public void command(Player sender) {
sender.sendMessage(CC.translate("cwc item [player]"));
}
@SubCommand("item")
public void giveChest(Player sender, @Optional Player player) {
if (player != null) {
player.getInventory().addItem(WarzoneChestPlacerItem.getItem());
return;
}
sender.getInventory().addItem(WarzoneChestPlacerItem.getItem());
}
@SubCommand("summoner")
public void giveSummoner(Player sender, @Optional Player player) {
if (player != null) {
player.getInventory().addItem(WarzoneChestSummoner.getItem());
return;
}
sender.getInventory().addItem(WarzoneChestSummoner.getItem());
}
}
@@ -0,0 +1,40 @@
package net.crankedpvp.warzonechests.inventories;
import lombok.Getter;
import lombok.Setter;
import net.crankedpvp.loottable.LootTableAPI;
import net.crankedpvp.warzonechests.struct.WarzoneChest;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import java.util.concurrent.ThreadLocalRandom;
@Getter
public class LootGUI {
private final Inventory gui;
private final long timeOfCreation;
@Setter
private boolean firstOpen;
public LootGUI() {
this.gui = Bukkit.createInventory(null, 27, "Warzone Chest");
this.timeOfCreation = System.currentTimeMillis();
this.firstOpen = true;
this.populateGui();
}
private void populateGui() {
for (int i = 0; i < randomAmountOfItems(); i++) {
this.gui.setItem(randomSlot(), LootTableAPI.getRandomLootItem(WarzoneChest.getLOOT_TABLE_TYPE()));
}
}
private int randomAmountOfItems() {
return ThreadLocalRandom.current().nextInt(3, 5);
}
private int randomSlot() {
return ThreadLocalRandom.current().nextInt(3, 25);
}
}
@@ -0,0 +1,61 @@
package net.crankedpvp.warzonechests.listener;
import net.crankedpvp.combatlog.CombatTagAPI;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.warzonechests.WarzoneChestsPlugin;
import net.crankedpvp.warzonechests.struct.WarzoneChestManager;
import net.crankedpvp.warzonechests.struct.items.WarzoneChestPlacerItem;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class WarzoneChestListeners implements Listener {
private final WarzoneChestManager warzoneChestManager;
private final WarzoneChestsPlugin plugin;
public WarzoneChestListeners(WarzoneChestsPlugin plugin) {
this.warzoneChestManager = plugin.getWarzoneChestManager();
this.plugin = plugin;
}
@EventHandler
public void warzoneChestPlaceListener(BlockPlaceEvent event) {
if (!WarzoneChestPlacerItem.isWarzoneChestPlace(event.getItemInHand())) return;
this.warzoneChestManager.placeWarzoneChest(event.getBlockPlaced().getLocation());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void warzoneChestBreakListener(BlockBreakEvent event) {
if (event.isCancelled()) return;
if (event.getBlock().getType() != Material.CHEST) return;
if (!this.warzoneChestManager.containsKey(event.getBlock().getLocation())) return;
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
@EventHandler
public void warzoneChestInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getClickedBlock() == null || event.getClickedBlock().getType() == Material.AIR) return;
if (event.getClickedBlock().getType() != Material.CHEST) return;
if (!this.warzoneChestManager.containsKey(event.getClickedBlock().getLocation())) return;
if (CombatTagAPI.isInCombat(event.getPlayer())) {
event.getPlayer().sendMessage(CC.translate("&e&lWarzone Chests &8" + Arrow.arrow() + " &7You cannot loot a &ewarzone chest&7 while you are in &ecombat."));
return;
}
event.setCancelled(true);
this.warzoneChestManager.getFromCache(event.getClickedBlock().getLocation())
.openChest(event.getPlayer());
}
}
@@ -0,0 +1,28 @@
package net.crankedpvp.warzonechests.listener;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import net.crankedpvp.warzonechests.WarzoneChestsPlugin;
import net.crankedpvp.warzonechests.struct.WarzoneChestManager;
import net.crankedpvp.warzonechests.struct.items.WarzoneChestSummoner;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
public class WarzoneChestSummonerListeners implements Listener {
private final WarzoneChestManager warzoneChestManager;
public WarzoneChestSummonerListeners(WarzoneChestsPlugin plugin) {
this.warzoneChestManager = plugin.getWarzoneChestManager();
}
@EventHandler
public void onWarzoneChestSummonerInteract(PlayerInteractEvent event) {
if (!WarzoneChestSummoner.isWarzoneChestPlace(event.getItem())) return;
event.getPlayer().setItemInHand(ItemUtils.decreaseItemStackAmountByOne(event.getItem()));
this.warzoneChestManager.resetWarzoneChestsForPlayer(event.getPlayer());
event.getPlayer().sendMessage(CC.translate("&e&lWarzone Chests &8" + Arrow.arrow() + " &7All your Warzone Chests have been reset, you can now go loot them again"));
}
}
@@ -0,0 +1,86 @@
package net.crankedpvp.warzonechests.struct;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import lombok.Getter;
import lombok.Setter;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.TimeUtils;
import net.crankedpvp.loottable.struct.LootTableType;
import net.crankedpvp.storageutils.struct.NewKeyToSave;
import net.crankedpvp.warzonechests.inventories.LootGUI;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Getter
@Setter
public class WarzoneChest implements NewKeyToSave<Location> {
@Getter
private static final LootTableType LOOT_TABLE_TYPE = LootTableType.WARZONE_CHEST;
private static final long TIME_UNTIL_CHEST_REFILL_IN_SECONDS = 60 * 15;
private Location location;
private transient final LoadingCache<UUID, LootGUI> playerChestLoot;
public WarzoneChest(Location location) {
this.location = location;
this.playerChestLoot = this.initCache();
}
// do not use this constructor its so that gson initialises the cache when its load the class
private WarzoneChest() {
this.playerChestLoot = this.initCache();
}
public void openChest(Player player) {
LootGUI lootGUI = this.playerChestLoot.get(player.getUniqueId());
assert lootGUI != null;
String time = TimeUtils.formatSeconds((lootGUI.getTimeOfCreation() + TIME_UNTIL_CHEST_REFILL_IN_SECONDS * 1000 - System.currentTimeMillis()) / 1000);
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1F, 0.1F);
player.openInventory(lootGUI.getGui());
if (lootGUI.isFirstOpen()) {
player.playSound(this.location, Sound.FIREWORK_BLAST, 1F, 0.1F);
Firework firework = location.getWorld().spawn(location.clone().add(0.5D, 0.0D, 0.5D), Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.addEffect(FireworkEffect.builder().withColor(Color.YELLOW).withFade(Color.WHITE)
.with(FireworkEffect.Type.BALL_LARGE).flicker(true).withTrail().build());
firework.setFireworkMeta(fireworkMeta);
fireworkMeta.setPower(5);
lootGUI.setFirstOpen(false);
} else {
player.sendMessage(CC.translate("&e&lWarzone Chests &8" + Arrow.arrow() + " &7You have &e" + time + " left&7 until this chest resets."));
}
}
public void resetCache() {
this.playerChestLoot.invalidateAll();
}
@Override
public Location getKey() {
return this.location;
}
@Override
public void setKey(Location location) {
this.location = location;
}
private LoadingCache<UUID, LootGUI> initCache() {
return Caffeine.newBuilder()
.expireAfterWrite(TIME_UNTIL_CHEST_REFILL_IN_SECONDS, TimeUnit.SECONDS)
.build(key -> new LootGUI());
}
}
@@ -0,0 +1,41 @@
package net.crankedpvp.warzonechests.struct;
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
import net.crankedpvp.storageutils.StorageUtils;
import net.crankedpvp.storageutils.struct.NewSaveLoadManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class WarzoneChestManager extends NewSaveLoadManager<Location, WarzoneChest> {
public WarzoneChestManager(JavaPlugin plugin) {
super(plugin, StorageUtils.getInstance().getGson(), "chests/", WarzoneChest.class);
}
public void resetWarzoneChestsForPlayer(Player player) {
for (WarzoneChest warzoneChests : this.getCacheValues()) {
warzoneChests.getPlayerChestLoot().invalidate(player.getUniqueId());
}
}
public void resetWarzoneChests() {
for (WarzoneChest warzoneChest : this.getCacheValues()) {
warzoneChest.resetCache();
}
}
public void placeWarzoneChest(Location location) {
this.addToCache(new WarzoneChest(location));
}
@Override
public String serialize(Location location) {
return LocationSerializerDeserializer.serialize(location);
}
@Override
public Location deserialize(String s) {
return LocationSerializerDeserializer.deserialize(s);
}
}
@@ -0,0 +1,31 @@
package net.crankedpvp.warzonechests.struct.items;
import de.tr7zw.nbtapi.NBTItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class WarzoneChestPlacerItem {
private static final String WARZONE_CHEST_NBT = "warzoneChest";
public static ItemStack getItem() {
ItemStack warzoneChestPlacer = new ItemBuilder(Material.CHEST).setName("&4Warzone Chest Placer")
.build();
NBTItem nbtItem = new NBTItem(warzoneChestPlacer);
nbtItem.setString("crankedCustomItem", WARZONE_CHEST_NBT);
return nbtItem.getItem();
}
public static boolean isWarzoneChestPlace(ItemStack itemStack) {
if (ItemUtils.isAirOrNull(itemStack)) return false;
if (itemStack.getType() != Material.CHEST) return false;
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.hasKey("crankedCustomItem")) return false;
return nbtItem.getString("crankedCustomItem").equals(WARZONE_CHEST_NBT);
}
}
@@ -0,0 +1,39 @@
package net.crankedpvp.warzonechests.struct.items;
import de.tr7zw.nbtapi.NBTItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class WarzoneChestSummoner {
private static final Material WARZONE_CHEST_SUMMONER_MATERIAL = Material.REDSTONE_TORCH_ON;
private static final String WARZONE_CHEST_SUMMONER = "warzoneChestSummoner";
public static ItemStack getItem() {
ItemStack item = new ItemBuilder(WARZONE_CHEST_SUMMONER_MATERIAL)
.setName("&c&lWarzone Chest Summoner")
.setLore(
"&7Right-Click this summoner to",
"&7forcefully reset all your warzone chests"
)
.colorize()
.build();
NBTItem nbtItem = new NBTItem(item);
nbtItem.setString("crankedCustomItem", WARZONE_CHEST_SUMMONER);
return nbtItem.getItem();
}
public static boolean isWarzoneChestPlace(ItemStack itemStack) {
if (ItemUtils.isAirOrNull(itemStack)) return false;
if (itemStack.getType() != WARZONE_CHEST_SUMMONER_MATERIAL) return false;
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.hasKey("crankedCustomItem")) return false;
return nbtItem.getString("crankedCustomItem").equals(WARZONE_CHEST_SUMMONER);
}
}
@@ -0,0 +1,9 @@
name: CrankedWarzoneChests
main: net.crankedpvp.warzonechests.WarzoneChestsPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils
- CrankedLootTables
- StorageUtil