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
@@ -0,0 +1,79 @@
package net.crankedpvp.dtc;
import lombok.Getter;
import me.mattstudios.mf.base.CommandManager;
import net.crankedpvp.crankedutils.utils.serializer.location.LocationSerializerDeserializer;
import net.crankedpvp.dtc.commands.DTCCommand;
import net.crankedpvp.dtc.inventory.DTCInventory;
import net.crankedpvp.dtc.listeners.DTCSummonerListener;
import net.crankedpvp.dtc.listeners.DestroyCoreListener;
import net.crankedpvp.dtc.listeners.PlaceLocationSetter;
import net.crankedpvp.dtc.struct.DTCManager;
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.List;
public class DTCPlugin extends JavaPlugin {
@Getter
private DTCManager dtcManager;
private CommandManager commandManager;
@Getter
private DTCInventory dtcInventory;
@Override
public void onEnable() {
this.saveDefaultConfig();
this.dtcManager = new DTCManager(this);
this.registerLocationsFromConfig();
this.commandManager = new CommandManager(this);
this.commandManager.register(new DTCCommand(this));
this.registerListeners(this.getServer().getPluginManager());
this.dtcInventory = new DTCInventory();
}
@Override
public void onDisable() {
saveLocationsToConfig();
this.dtcManager.removeAllCores();
}
private void registerListeners(PluginManager pluginManager) {
pluginManager.registerEvents(new PlaceLocationSetter(this), this);
pluginManager.registerEvents(new DTCSummonerListener(this), this);
pluginManager.registerEvents(new DestroyCoreListener(this), this);
}
public void saveLocationsToConfig() {
final FileConfiguration yamlConfiguration = this.getConfig();
final List<String> locations = new ArrayList<>();
for(Location location : this.dtcManager.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.dtcManager.getLocationList().add(LocationSerializerDeserializer.deserialize(string));
}
}
}
}
@@ -0,0 +1,95 @@
package net.crankedpvp.dtc.commands;
import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.crankedutils.utils.*;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.dtc.DTCPlugin;
import net.crankedpvp.dtc.struct.DTCManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Command("destroythecore")
@Alias("dtc")
public class DTCCommand extends CommandBase {
private DTCPlugin plugin;
public DTCCommand(DTCPlugin plugin) {
this.plugin = plugin;
}
@Default
public void defaultCommand(final Player player) {
this.plugin.getDtcInventory().getUI().open(player);
}
@SubCommand("save")
@Permission("cranked.admin")
public void saveCommand(final CommandSender commandSender) {
final long current = System.currentTimeMillis();
this.plugin.saveLocationsToConfig();
commandSender.sendMessage(CC.translate(DTCManager.prefix + "&7Saved DTC location data in &n" + (System.currentTimeMillis() - current) + "ms"));
SoundUtils.tryPlaySuccessSound(commandSender);
}
@SubCommand("edit")
@Alias("editor")
@Permission("cranked.admin")
public void editCommand(final CommandSender commandSender) {
if(!(commandSender instanceof Player)) {
commandSender.sendMessage(CC.translate("&cOnly players can execute this command"));
return;
}
Player player = ((Player)commandSender);
if(InventoryUtils.hasAvailableSlot(player)) {
final ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST, "&b&lDTC &8- &fLocation Setter",
"&7Place this chest down at the",
"&7locations that you want the",
"&7dtc events to spawn at");
final ItemStack itemStack = CustomItemUtils.setCrankedCustomItem(itemBuilder.colorize().build(), "dtcLocationSetter");
player.getInventory().addItem(itemStack);
player.sendMessage(CC.translate(DTCManager.prefix + "&7Received a destroy the core location setter"));
SoundUtils.tryPlaySuccessSound(player);
}
}
@SubCommand("start")
@Alias({"forcestart", "begin"})
@Permission("cranked.admin")
public void startCommand(final CommandSender commandSender) {
Location location = this.plugin.getDtcManager().startEvent();
if(location == null) return;
commandSender.sendMessage(CC.translate(DTCManager.prefix + "&7Successfully started a DTC event at: " + LocationUtils.locationToFancy(location)));
SoundUtils.tryPlaySuccessSound(commandSender);
}
@SubCommand("end")
@Alias("forceend")
@Permission("cranked.admin")
public void endCommand(final CommandSender commandSender) {
this.plugin.getDtcManager().endEvent();
commandSender.sendMessage(CC.translate(DTCManager.prefix + "&7Successfully ended the current DTC event"));
SoundUtils.tryPlaySuccessSound(commandSender);
}
@SubCommand("summoner")
@Permission("cranked.admin")
public void summonerCommand(final CommandSender commandSender, @Optional @Completion("#players") Player player) {
if(player == null) player = (Player)commandSender;
ItemBuilder itemBuilder = new ItemBuilder(Material.TORCH, "&f&ki&r&e✦&f&ki&r &6&lCore Summoner &f&ki&e✦&f&ki&r",
"&7Right-Click this summoner to",
"&7forcefully begin a dtc event",
"",
"&7The event will not start if",
"&7another dtc event is ongoing");
itemBuilder.setGlowing();
PlayerUtils.giveOrDropProtectedItem(player, CustomItemUtils.setCrankedCustomItem(itemBuilder.colorize().build(), "dtcSummoner"), 15);
}
}
@@ -0,0 +1,36 @@
package net.crankedpvp.dtc.inventory;
import dev.triumphteam.gui.components.GuiType;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class DTCInventory {
private final Gui dtcInventory;
public Gui getUI() {
return this.dtcInventory;
}
public DTCInventory() {
this.dtcInventory = new Gui(GuiType.HOPPER, "Destroy The Core");
this.dtcInventory.setDefaultClickAction(event -> event.setCancelled(true));
ItemStack info = new ItemBuilder(Material.BOOK_AND_QUILL, "&6Destroy The Core Info",
"&7The &eDestroy The Core &7event (DTC) is",
"&7a small scale event whereby players",
"&7attack a &fbeacon &7spawned randomly",
"&7within the &4warzone&7.",
"",
"&7Once the beacon has been &ffully",
"&7destroyed, it's &fcontents &7will",
"&7spill onto the ground for &fanyone",
"&7to loot, so be &aquick!").colorize().build();
this.dtcInventory.setItem(1, new GuiItem(info));
ItemStack rewards = new ItemBuilder(Material.CHEST, "&d&lLoot Table", "&7Click to view all potential rewards", "&7from the destroy the core event").colorize().build();
this.dtcInventory.setItem(3, new GuiItem(rewards));
}
}
@@ -0,0 +1,39 @@
package net.crankedpvp.dtc.listeners;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import net.crankedpvp.dtc.DTCPlugin;
import net.crankedpvp.dtc.struct.DTCManager;
import org.bukkit.Sound;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class DTCSummonerListener implements Listener {
private final DTCPlugin plugin;
public DTCSummonerListener(DTCPlugin envoyPlugin) {
this.plugin = envoyPlugin;
}
@EventHandler
public void useItem(PlayerInteractEvent event) {
if(event.getPlayer() == null) return;
if(event.getPlayer().getItemInHand() == null) return;
ItemStack itemStack = event.getPlayer().getItemInHand();
if(!CustomItemUtils.isCrankedCustomItem(itemStack)) return;
if(!CustomItemUtils.getCrankedCustomItem(itemStack).equals("dtcSummoner")) return;
if(this.plugin.getDtcManager().isActive()) {
event.setCancelled(true);
event.getPlayer().sendMessage(CC.translate(DTCManager.prefix + "&cThere is already an active destroy the core event"));
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ANVIL_LAND, 2.0F, 2.0F);
return;
}
event.getPlayer().setItemInHand(ItemUtils.decreaseItemStackAmountByOne(itemStack));
this.plugin.getDtcManager().startEvent();
}
}
@@ -0,0 +1,108 @@
package net.crankedpvp.dtc.listeners;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.LocationUtils;
import net.crankedpvp.dtc.DTCPlugin;
import net.crankedpvp.dtc.struct.DTCManager;
import net.crankedpvp.leaderboards.LeaderboardsAPI;
import net.crankedpvp.loottable.LootTableAPI;
import net.crankedpvp.loottable.struct.LootTableType;
import org.bukkit.*;
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;
import java.util.concurrent.ThreadLocalRandom;
public class DestroyCoreListener implements Listener {
private final DTCPlugin plugin;
private final DTCManager manager;
public DestroyCoreListener(DTCPlugin plugin) {
this.plugin = plugin;
this.manager = plugin.getDtcManager();
}
@EventHandler
public void destroyCore(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;
this.manager.getCooldownToHit().add(player);
this.manager.setHealth(this.manager.getHealth() - 1);
player.playSound(player.getLocation(), Sound.GLASS, 4.0F, 2.0F);
if(this.manager.getHealth() <= 0) {
LeaderboardsAPI.getPlayerStats(player.getUniqueId()).incrementCoresBroken();
this.sendFirework();
this.manager.endEvent();
int max = ThreadLocalRandom.current().nextInt(3, 14);
Bukkit.broadcastMessage("");
Bukkit.broadcastMessage(CC.translate("&6&lCore Destroyed: &f" + LocationUtils.locationToFancySav(location)));
Bukkit.broadcastMessage(CC.translate(" &6• &eBroken By: &f" + player.getDisplayName()));
Bukkit.broadcastMessage(CC.translate(" &6• &eRewards: &f" + max + " Items"));
Bukkit.broadcastMessage("");
int current = 0;
while (current != max) {
if(current >= max-2) {
location.getWorld().dropItem(getUppedLocation(location), LootTableAPI.getRandomLootItem(LootTableType.SEASON_KEY));
} else if(current >= max-6) {
location.getWorld().dropItem(getUppedLocation(location), LootTableAPI.getRandomLootItem(LootTableType.ABYSS_KEY));
} else {
location.getWorld().dropItem(getUppedLocation(location), LootTableAPI.getRandomLootItem(LootTableType.MYTHIC_KEY));
}
current++;
}
this.manager.getCooldownToHit().remove(player);
return;
}
player.sendMessage(CC.translate("&6&lCore &8➥ &eYou are destroying the core &8- &cHealth&8: " + getHealth(this.manager.getHealth())));
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
this.manager.getCooldownToHit().remove(player);
}, 20L);
}
private void sendFirework() {
Location location = this.plugin.getDtcManager().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 Location getUppedLocation(Location location) {
Location newLocation = location.clone();
newLocation.setY(location.getY() + 1.5);
return newLocation;
}
private String getHealth(int health) {
return
health > 55 ? ("&a" + health + " ❤") :
health > 40 ? ("&e" + health + " ❤") :
health > 25 ? ("&6" + health + " ❤") :
health > 9 ? ("&c" + health + " ❤") :
("&4" + health + " ❤");
}
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,39 @@
package net.crankedpvp.dtc.listeners;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.CustomItemUtils;
import net.crankedpvp.crankedutils.utils.LocationUtils;
import net.crankedpvp.dtc.DTCPlugin;
import net.crankedpvp.dtc.struct.DTCManager;
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 PlaceLocationSetter implements Listener {
private final DTCPlugin plugin;
public PlaceLocationSetter(DTCPlugin 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("dtcLocationSetter")) return;
event.setCancelled(true);
final Location location = event.getBlockPlaced().getLocation();
player.sendMessage(CC.translate(DTCManager.prefix + "&aSuccessfully placed a core location at: " + LocationUtils.locationToFancy(location)));
this.plugin.getDtcManager().getLocationList().add(location);
player.playSound(player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0F, 2.0F);
}
}
@@ -0,0 +1,108 @@
package net.crankedpvp.dtc.struct;
import lombok.Getter;
import lombok.Setter;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.LocationUtils;
import net.crankedpvp.dtc.DTCPlugin;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.inventory.meta.FireworkMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class DTCManager {
private DTCPlugin plugin;
public DTCManager(DTCPlugin plugin) {
this.plugin = plugin;
this.locationList = new ArrayList<>();
this.cooldownToHit = new ArrayList<>();
}
public static String prefix = "&6&lDTC &8➥ ";
@Getter
private List<Location> locationList;
@Getter @Setter
private Location currentLocation;
@Getter @Setter
private boolean active = false;
@Getter @Setter
private int health = 0;
@Getter
private List<Player> cooldownToHit;
public Location startEvent() {
if(this.isActive()) return null;
final List<Location> locationList = new ArrayList<>(this.plugin.getDtcManager().getLocationList());
final Location location = locationList.get(ThreadLocalRandom.current().nextInt(locationList.size()));
if(location.getBlock().getType() == Material.AIR) {
this.plugin.getDtcManager().setCurrentLocation(location);
this.plugin.getDtcManager().setActive(true);
this.plugin.getDtcManager().setCurrentLocation(location);
this.plugin.getDtcManager().setHealth(30);
location.getBlock().setType(Material.BEACON);
ArmorStand armorStand = (ArmorStand)location.getWorld().spawnEntity(location.clone().add(0.5D, 0.1D, 0.5D), EntityType.ARMOR_STAND);
armorStand.setCustomName(CC.translate("&6&l✧&e&l✧ &6&lCore &e&l✧&6&l✧"));
armorStand.setCustomNameVisible(true);
armorStand.setGravity(false);
armorStand.setVisible(false);
armorStand.setSmall(true);
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.ORANGE).withFade(Color.YELLOW)
.with(FireworkEffect.Type.STAR).trail(true).flicker(true).build());
firework.setFireworkMeta(fireworkMeta);
this.plugin.getServer().getOnlinePlayers().forEach(player -> player.sendMessage(CC.translate(prefix + "&eA destroy the core event has started at: &7" + LocationUtils.locationToFancy(location))));
return location;
} else {
System.out.println("[-] DTC Event force ended due to dtc block obstruction");
}
return null;
}
public void endEvent() {
if(this.getCurrentLocation() == null) return;
Location location = this.getCurrentLocation();
for (Entity entity : location.getWorld().getNearbyEntities(location, 0.3D, 0.6D, 0.3D)) {
if (!(entity instanceof ArmorStand))
continue;
entity.remove();
}
if(location.getBlock().getType() == Material.BEACON)
location.getBlock().setType(Material.AIR);
this.setActive(false);
this.setHealth(0);
this.setCurrentLocation(null);
this.getCooldownToHit().clear();
}
public void removeAllCores() {
for(Location location : this.getLocationList()) {
for (Entity entity : location.getWorld().getNearbyEntities(location, 0.3D, 0.6D, 0.3D)) {
if (!(entity instanceof ArmorStand))
continue;
entity.remove();
}
if(location.getBlock().getType() == Material.BEACON)
location.getBlock().setType(Material.AIR);
}
}
}
+1
View File
@@ -0,0 +1 @@
locations: []
+8
View File
@@ -0,0 +1,8 @@
name: CrankedDTC
main: net.crankedpvp.dtc.DTCPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils