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
+45
View File
@@ -0,0 +1,45 @@
<?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">
<parent>
<artifactId>ProjectCranked</artifactId>
<groupId>net.crankedpvp</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>DeadMansChest</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
</dependency>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>PvPTop</artifactId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Lootboxes</artifactId>
</dependency>
<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>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,116 @@
package net.crankedpvp.deadmanschest;
import com.massivecraft.factions.Factions;
import lombok.Getter;
import me.mattstudios.mf.base.CommandManager;
import net.crankedpvp.deadmanschest.commands.DeadmansChestCommand;
import net.crankedpvp.deadmanschest.inventory.DeadmansChestInventory;
import net.crankedpvp.deadmanschest.listeners.DestroyDeadmansChestListener;
import net.crankedpvp.deadmanschest.listeners.PlaceDeadmansChestItemListener;
import net.crankedpvp.deadmanschest.manager.DeadmansChestManager;
import net.crankedpvp.deadmanschest.tasks.UpdateNextDeadmansChestTimerTask;
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
public class DeadmansChestPlugin extends JavaPlugin {
public static String WORLD = "";
public final static String PREFIX = "&d&lDead Mans Chest &8➥ &7";
@Getter
private static DeadmansChestPlugin instance;
@Getter
private DeadmansChestManager deadmansChestManager;
@Getter
private DeadmansChestInventory deadmansChestInventory;
@Getter
private CommandManager commandManager;
@Override
public void onEnable() {
instance = this;
this.saveDefaultConfig();
this.commandManager = new CommandManager(this);
this.commandManager.register(new DeadmansChestCommand(this));
this.deadmansChestManager = new DeadmansChestManager(this);
this.deadmansChestInventory = new DeadmansChestInventory(this);
this.registerListeners();
new UpdateNextDeadmansChestTimerTask(this).runTaskTimer(this, 40L, 20L);
this.registerLocationsFromConfig();
WORLD = this.getConfig().getString("DEADMANS_CHEST_WORLD");
this.deadmansChestManager.setLastFactionWon((this.getConfig().getString("LAST_CAPTURED_ID").equals("0") || this.getConfig().getString("LAST_CAPTURED_ID") == null) ? null : Factions.getInstance().getFactionById(this.getConfig().getString("LAST_CAPTURED_ID")));
}
@Override
public void onDisable() {
this.deadmansChestManager.stop();
this.saveLocationsToConfig();
this.getConfig().set("LAST_CAPTURED_ID", this.getDeadmansChestManager().getLastFactionWon() == null ? "0" : this.getDeadmansChestManager().getLastFactionWon().getId());
this.saveConfig();
instance = null;
}
private void registerListeners() {
PluginManager pluginManager = this.getServer().getPluginManager();
pluginManager.registerEvents(new DestroyDeadmansChestListener(this), this);
pluginManager.registerEvents(new PlaceDeadmansChestItemListener(this), this);
//pluginManager.registerEvents(new PlayerListener(this), this);
}
public void saveLocationsToConfig() {
final FileConfiguration yamlConfiguration = this.getConfig();
final List<String> locations = new ArrayList<>();
for(Location location : this.deadmansChestManager.getLocationList()) {
locations.add(LocationSerializerDeserializer.serialize(location));
}
yamlConfiguration.set("Locations", locations);
this.saveConfig();
}
private void registerLocationsFromConfig() {
final FileConfiguration yamlConfiguration = this.getConfig();
if(yamlConfiguration.contains("Locations")) {
for(String string : yamlConfiguration.getStringList("Locations")) {
this.deadmansChestManager.getLocationList().add(LocationSerializerDeserializer.deserialize(string));
}
}
}
public long getTimeUntilNextChest() {
Calendar nextDeadMansChest = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));
nextDeadMansChest.set(Calendar.MINUTE, 0);
nextDeadMansChest.set(Calendar.SECOND, 0);
int currentHour = nextDeadMansChest.get(Calendar.HOUR_OF_DAY);
if (currentHour < 5) {
nextDeadMansChest.set(Calendar.HOUR_OF_DAY, 5);
return (nextDeadMansChest.getTimeInMillis() - System.currentTimeMillis()) - 1000;
} else if (currentHour < 17) {
nextDeadMansChest.set(Calendar.HOUR_OF_DAY, 17);
return (nextDeadMansChest.getTimeInMillis() - System.currentTimeMillis()) - 1000;
} else {
nextDeadMansChest.add(Calendar.DAY_OF_MONTH, 1);
nextDeadMansChest.set(Calendar.HOUR_OF_DAY, 5);
return (nextDeadMansChest.getTimeInMillis() - System.currentTimeMillis()) - 1000;
}
}
}
@@ -0,0 +1,72 @@
package net.crankedpvp.deadmanschest.commands;
import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
import net.crankedpvp.crankedutils.utils.InventoryUtils;
import net.crankedpvp.crankedutils.utils.SoundUtils;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Command("deadmanschest")
@Alias({"dmc", "deadman", "deadmans", "deadchest"})
public class DeadmansChestCommand extends CommandBase {
private final DeadmansChestPlugin plugin;
public DeadmansChestCommand(DeadmansChestPlugin plugin) {
this.plugin = plugin;
}
@Default
public void defaultCommand(final Player player) {
this.plugin.getDeadmansChestInventory().getUI().open(player);
}
@SubCommand("start")
@Permission("cranked.admin")
public void startCommand(final CommandSender commandSender) {
this.plugin.getDeadmansChestManager().start();
commandSender.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You have forcefully started a dead mans chest event"));
}
@SubCommand("edit")
@Alias("editor")
@Permission("cranked.admin")
public void editCommand(final Player player) {
if(InventoryUtils.hasAvailableSlot(player)) {
final ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST, "&d&lDead Mans Chest Location Setter",
"&7Place this chest down at the",
"&7locations that you want the",
"&7DMC events to spawn at");
final ItemStack itemStack = CustomItemUtils.setCrankedCustomItem(itemBuilder.colorize().build(), "deadmansChestLocationSetter");
player.getInventory().addItem(itemStack);
player.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "&7Received a dead mans chest location setter"));
SoundUtils.tryPlaySuccessSound(player);
}
}
@SubCommand("stop")
@Permission("cranked.admin")
public void stopCommand(final CommandSender commandSender) {
this.plugin.getDeadmansChestManager().stop();
commandSender.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You have forcefully stopped the ongoing dead mans chest event"));
}
@SubCommand("debug")
@Permission("cranked.admin")
public void debugCommand(final CommandSender commandSender) {
if(this.plugin.getDeadmansChestManager().isActive()) {
this.plugin.getDeadmansChestManager().stop();
commandSender.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You have forcefully stopped the ongoing dead mans chest event"));
}
this.plugin.getDeadmansChestManager().debugAndRemoveDeadMansChests();
commandSender.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You have debugged all dead mans chests"));
}
}
@@ -0,0 +1,105 @@
package net.crankedpvp.deadmanschest.inventory;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import lombok.Getter;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.crankedutils.utils.TimeUtils;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.pvptop.data.FactionData;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class DeadmansChestInventory {
@Getter
private ItemStack deadMansChestItemStack;
@Getter
private final DeadmansChestPlugin plugin;
private final Gui deadMansChestInventory;
public Gui getUI() {
return this.deadMansChestInventory;
}
public DeadmansChestInventory(DeadmansChestPlugin plugin) {
this.plugin = plugin;
this.deadMansChestInventory = new Gui(3, "Dead Mans Chest");
this.deadMansChestInventory.setDefaultClickAction(event -> event.setCancelled(true));
this.buildDeadmansChestItem();
ItemStack howToPlay = new ItemBuilder(Material.SIGN, "&b&lHow to Play?",
"&fThis is a competitive event which will",
"&fstart twice per day, where factions compete",
"&fto control, and destroy the chest",
"",
"&fThe objective is to destroy the chest,",
"&fhowever you can &c&lONLY &fbreak the",
"&fchest if your faction is the only faction",
"&finside of the capture zone which surrounds",
"&fthe dead mans chest.",
"",
"&fYour faction must work together to clear",
"&fenemy players from the capture zone before",
"&fyou can attempt to break the chest."
).colorize().build();
ItemStack viewAllEvents = new ItemBuilder(Material.ARROW, "&d&lAll Events",
"&fClick here to view all of the",
"&fevents currently active on Cranked"
).colorize().build();
this.deadMansChestInventory.setItem(2, 5, new GuiItem(this.getDeadMansChestItemStack()));
this.deadMansChestInventory.setItem(2, 3, new GuiItem(howToPlay));
this.deadMansChestInventory.setItem(2, 7, new GuiItem(viewAllEvents, event -> {
event.getWhoClicked().closeInventory();
if(event.getWhoClicked() instanceof Player) {
((Player)event.getWhoClicked()).performCommand("events");
}
}));
}
private String getNextChestTimeString() {
return this.plugin.getDeadmansChestManager().isActive() ? "Now" : TimeUtils.formatMillisecondsInFull(this.plugin.getTimeUntilNextChest());
}
private String getActiveString() {
return this.plugin.getDeadmansChestManager().isActive() ? "&a&lACTIVE" : "&c&lINACTIVE";
}
public void updateInformationItem() {
this.buildDeadmansChestItem();
this.deadMansChestInventory.updateItem(2, 5, new GuiItem(this.getDeadMansChestItemStack()));
}
public void buildDeadmansChestItem() {
this.deadMansChestItemStack = new ItemBuilder(Material.ENDER_CHEST, "&d&lDead Mans Chest &7(Information)",
"&fA competitive event on Cranked. Conquer",
"&fall enemies and destroy the chest",
"",
"&dInformation:",
" &f• Located at &d/warp nether",
" &f• Chest has &d150 &fHealth Points",
" &f• Chest health is &dunique &fper faction",
"",
"&dRewards &7(Upon capture)",
" &f• 3x Dead Mans Chest Lootbags",
" &f• Gain &d+" + FactionData.Points.DEADMANS_CHEST.getPoints() + " &fFaction Points",
"",
"&dDead Mans Chest:",
" &f• Event Status: " + this.getActiveString(),
" &f• Next Event: &a" + this.getNextChestTimeString(),
" &f• Captured Last: &d" + this.getLastFactionWon()
).colorize().build();
}
private String getLastFactionWon() {
return this.plugin.getDeadmansChestManager().getLastFactionWon() == null ? "None" : this.plugin.getDeadmansChestManager().getLastFactionWon().getTag();
}
}
@@ -0,0 +1,135 @@
package net.crankedpvp.deadmanschest.listeners;
import com.massivecraft.factions.Faction;
import net.crankedpvp.crankedutils.utils.*;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.deadmanschest.manager.DeadmansChestManager;
import net.crankedpvp.lootboxes.CrankedLootboxes;
import net.crankedpvp.pvptop.PvPTopAPI;
import net.crankedpvp.pvptop.data.FactionData;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.meta.FireworkMeta;
public class DestroyDeadmansChestListener implements Listener {
private final DeadmansChestPlugin plugin;
private final DeadmansChestManager manager;
public DestroyDeadmansChestListener(DeadmansChestPlugin plugin) {
this.plugin = plugin;
this.manager = plugin.getDeadmansChestManager();
}
@EventHandler
public void attemptToAttackChest(PlayerInteractEvent event) {
if(event.getPlayer() == null) return;
if(event.getClickedBlock() == null) return;
final Location location = event.getClickedBlock().getLocation();
if(this.manager.getCurrentLocation() == null) return;
if(!locationEquals(location, this.manager.getCurrentLocation())) return;
event.setCancelled(true);
Player player = event.getPlayer();
if(this.manager.getCooldownToHit().contains(player)) return;
if(!isPlayerInRequiredRegion(player)) return;
Faction faction = FactionUtils.getFaction(player);
if(!faction.isNormal()) {
player.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You must be in a faction to attack the dead mans chest"));
player.playSound(player.getLocation(), Sound.ANVIL_LAND, 1.0f, 1.0f);
return;
}
player.playSound(player.getLocation(), Sound.ZOMBIE_WOODBREAK, 4.0F, 2.0F);
for(Entity nearbyEntity : player.getNearbyEntities(20, 20, 20)) {
if(!(nearbyEntity instanceof Player)) continue;
Player nearbyPlayer = (Player) nearbyEntity;
if(!isPlayerInRequiredRegion(nearbyPlayer)) continue;
Faction nearbyPlayersFaction = FactionUtils.getFaction(nearbyPlayer);
if(nearbyPlayersFaction != faction) {
this.manager.getCooldownToHit().add(player);
player.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You cannot attack the chest while another faction is in the capture zone"));
player.playSound(player.getLocation(), Sound.FIZZ, 2.0f, 1.0f);
this.resetCooldownForPlayer(player);
return;
}
}
if(this.incrementHitsFor(faction)) {
PvPTopAPI.getFactionData(faction).addPoint(FactionData.Points.DEADMANS_CHEST);
this.giveRewards(player);
this.sendFirework();
this.sendMessage(faction, player);
this.manager.stop();
this.manager.getCooldownToHit().clear();
this.manager.setLastFactionWon(faction);
return;
}
int hitsForFaction = this.manager.getHitsPerFaction().get(faction);
for(Player onlinePlayer : faction.getOnlinePlayers()) {
onlinePlayer.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "&fYour faction member &d" + player.getName() + " &fis attacking the chest &d(&7" + hitsForFaction + "/" + DeadmansChestManager.HEALTH + "&d)"));
}
this.manager.getCooldownToHit().add(player);
this.resetCooldownForPlayer(player);
}
private void giveRewards(Player player) {
PlayerUtils.giveOrDropProtectedItem(player, CrankedLootboxes.getInstance().getLootboxRegister().getLootbox("DeadMansChestLootbox").createLootbox(3), 30);
}
private void resetCooldownForPlayer(Player player) {
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> this.manager.getCooldownToHit().remove(player), 20L);
}
private boolean isPlayerInRequiredRegion(Player player) {
return WorldGuardUtils.getRegionName(player.getLocation()).equals(this.plugin.getConfig().get("CAPTURE_ZONE"));
}
private void sendMessage(Faction faction, Player player) {
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
onlinePlayer.sendMessage("");
onlinePlayer.sendMessage(CC.translate("&d&lDead Mans Chest Captured"));
onlinePlayer.sendMessage(CC.translate(" &5• &dCapturing Faction: &f" + faction.getTag()));
onlinePlayer.sendMessage(CC.translate(" &5• &dCapturing Player: &f" + player.getName()));
onlinePlayer.sendMessage(CC.translate(" &5• &dRewards: &f3x Dead Mans Chest Lootbags"));
onlinePlayer.sendMessage(CC.translate(" &5• &dFaction Points: &f+" + FactionData.Points.DEADMANS_CHEST.getPoints() + " Gained"));
onlinePlayer.sendMessage(CC.translate(" &5• &dRuntime: &f" + TimeUtils.formatMilliseconds(System.currentTimeMillis() - this.manager.getStartTime())));
onlinePlayer.sendMessage("");
}
}
private boolean incrementHitsFor(Faction faction) {
if(this.manager.getHitsPerFaction().containsKey(faction)) {
int amount = this.manager.getHitsPerFaction().get(faction) + 1;
this.manager.getHitsPerFaction().put(faction, amount);
return amount >= DeadmansChestManager.HEALTH;
}
this.manager.getHitsPerFaction().put(faction, 1);
return false;
}
private void sendFirework() {
Location location = this.plugin.getDeadmansChestManager().getCurrentLocation();
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.ORANGE)
.with(FireworkEffect.Type.BURST).flicker(true).withTrail().build());
firework.setFireworkMeta(fireworkMeta);
fireworkMeta.setPower(6);
Bukkit.getScheduler().runTaskLater(this.plugin, firework::detonate, 25L);
}
private boolean locationEquals(Location location1, Location location2) {
if(location1.getWorld() != location2.getWorld()) return false;
if(location1.getX() != location2.getX()) return false;
if(location1.getY() != location2.getY()) return false;
return location1.getZ() == location2.getZ();
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.deadmanschest.listeners;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
import net.crankedpvp.crankedutils.utils.LocationUtils;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
public class PlaceDeadmansChestItemListener implements Listener {
private final DeadmansChestPlugin plugin;
public PlaceDeadmansChestItemListener(DeadmansChestPlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void placeBlockListener(BlockPlaceEvent event) {
if(event.getBlockPlaced() == null) return;
if(event.getItemInHand() == null) return;
final Player player = event.getPlayer();
final ItemStack itemStack = event.getItemInHand();
if(!CustomItemUtils.isCrankedCustomItem(itemStack)) return;
if(!CustomItemUtils.getCrankedCustomItem(itemStack).equals("deadmansChestLocationSetter")) return;
event.setCancelled(true);
final Location location = event.getBlockPlaced().getLocation();
player.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "&aSuccessfully placed a dead mans chest location at: " + LocationUtils.locationToFancy(location)));
this.plugin.getDeadmansChestManager().getLocationList().add(location);
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
}
}
@@ -0,0 +1,33 @@
package net.crankedpvp.deadmanschest.listeners;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.crankedutils.utils.CC;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileLaunchEvent;
public class PlayerListener implements Listener {
private final DeadmansChestPlugin plugin;
public PlayerListener(DeadmansChestPlugin plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onProjectileShoot(ProjectileLaunchEvent event) {
if(event.getEntity() == null) return;
if(event.getEntity().getShooter() == null || !(event.getEntity().getShooter() instanceof Player)) return;
if(!event.getEntity().getType().equals(EntityType.ENDER_PEARL)) return;
Player shooter = (Player) event.getEntity().getShooter();
if(shooter.getWorld().getName().equals(DeadmansChestPlugin.WORLD)) {
event.setCancelled(true);
shooter.playSound(shooter.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0f, 1.0f);
shooter.sendMessage(CC.translate(DeadmansChestPlugin.PREFIX + "You cannot use ender pearls at dead mans chest"));
}
}
}
@@ -0,0 +1,139 @@
package net.crankedpvp.deadmanschest.manager;
import com.massivecraft.factions.Faction;
import lombok.Getter;
import lombok.Setter;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.crankedutils.utils.CC;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.meta.FireworkMeta;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class DeadmansChestManager {
private final DeadmansChestPlugin plugin;
public DeadmansChestManager(DeadmansChestPlugin plugin) {
this.plugin = plugin;
this.locationList = new ArrayList<>();
this.hitsPerFaction = new HashMap<>();
this.cooldownToHit = new ArrayList<>();
}
public final static int HEALTH = 150;
@Getter
private final List<Player> cooldownToHit;
@Getter
private final List<Location> locationList;
@Getter
private final Map<Faction, Integer> hitsPerFaction;
@Getter @Setter
private Faction lastFactionWon;
@Getter @Setter
private Location currentLocation;
@Getter
private boolean active;
@Getter
private long startTime = 0L;
public void start() {
if(this.isActive()) return;
this.startTime = System.currentTimeMillis();
this.spawnDeadmansChest();
this.hitsPerFaction.clear();
this.cooldownToHit.clear();
this.active = true;
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
onlinePlayer.sendMessage("");
onlinePlayer.sendMessage(CC.translate("&d&lDead Mans Chest"));
onlinePlayer.sendMessage(CC.translate(" &f• Status: &a&lACTIVE"));
onlinePlayer.sendMessage(CC.translate(" &f• Located: &d/warp nether &7(West)"));
onlinePlayer.sendMessage(CC.translate(" &f• Information: &d/deadmanschest"));
onlinePlayer.sendMessage("");
}
}
private void spawnDeadmansChest() {
final List<Location> locationList = new ArrayList<>(this.locationList);
final Location location = locationList.get(ThreadLocalRandom.current().nextInt(locationList.size()));
if(location.getBlock().getType() == Material.AIR) {
this.plugin.getDeadmansChestManager().setCurrentLocation(location);
this.active = true;
location.getBlock().setType(Material.ENDER_CHEST);
this.spawnFirework(location);
this.addHologram(location);
} else {
System.out.println("[-] Theres a block in the way for the dead mans chest, buddy.");
}
}
private void addHologram(Location location) {
ArmorStand armorStand = (ArmorStand)location.getWorld().spawnEntity(location.clone().add(0.5D, 0.9D, 0.5D), EntityType.ARMOR_STAND);
armorStand.setCustomName(CC.translate("&d&lDead Mans Chest"));
armorStand.setCustomNameVisible(true);
armorStand.setGravity(false);
armorStand.setVisible(false);
armorStand.setSmall(true);
}
private void spawnFirework(Location location) {
Firework firework = location.getWorld().spawn(location.clone().add(0.5D, 0.0D, 0.5D), Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(0);
fireworkMeta.addEffect(FireworkEffect.builder().withColor(Color.AQUA).withFade(Color.PURPLE)
.with(FireworkEffect.Type.STAR).trail(true).flicker(true).build());
firework.setFireworkMeta(fireworkMeta);
}
public void stop() {
if(!this.isActive()) return;
this.hitsPerFaction.clear();
this.active = false;
this.cooldownToHit.clear();
Location location = this.getCurrentLocation();
Location hologramloc = location.clone();
hologramloc.setY(location.getY() + 0.9);
for (Entity entity : location.getWorld().getNearbyEntities(hologramloc, 0.3D, 0.6D, 0.3D)) {
if (!(entity instanceof ArmorStand))
continue;
entity.remove();
}
if(location.getBlock().getType() == Material.ENDER_CHEST)
location.getBlock().setType(Material.AIR);
this.setCurrentLocation(null);
}
public void debugAndRemoveDeadMansChests() {
for(Location location : this.getLocationList()) {
Location newLoc = location.clone();
newLoc.setY(newLoc.getY() + 0.9);
for (Entity entity : location.getWorld().getNearbyEntities(newLoc, 0.3D, 0.6D, 0.3D)) {
if (!(entity instanceof ArmorStand))
continue;
entity.remove();
}
if(location.getBlock().getType() == Material.ENDER_CHEST) {
location.getBlock().setType(Material.AIR);
}
}
}
}
@@ -0,0 +1,27 @@
package net.crankedpvp.deadmanschest.tasks;
import net.crankedpvp.deadmanschest.DeadmansChestPlugin;
import net.crankedpvp.deadmanschest.inventory.DeadmansChestInventory;
import org.bukkit.scheduler.BukkitRunnable;
public class UpdateNextDeadmansChestTimerTask extends BukkitRunnable {
private final DeadmansChestInventory deadmansChestInventory;
private final DeadmansChestPlugin plugin;
public UpdateNextDeadmansChestTimerTask(DeadmansChestPlugin plugin) {
this.plugin = plugin;
this.deadmansChestInventory = plugin.getDeadmansChestInventory();
}
@Override
public void run() {
if(this.plugin.getTimeUntilNextChest() <= 1000L)
if(this.plugin.getTimeUntilNextChest() <= 0L) {
this.plugin.getDeadmansChestManager().start();
}
deadmansChestInventory.updateInformationItem();
}
}
@@ -0,0 +1,5 @@
DEADMANS_CHEST_WORLD: world
CAPTURE_ZONE: deadmanschest_capture_zone
LAST_CAPTURED_ID: 0
Locations: []
@@ -0,0 +1,10 @@
name: CrankedDeadMansChest
main: net.crankedpvp.deadmanschest.DeadmansChestPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils
- WorldGuard
- CrankedPvPTop