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
+30
View File
@@ -0,0 +1,30 @@
<?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>CustomExplosions</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,77 @@
package net.crankedpvp.customexplosions;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import lombok.Getter;
import me.mattstudios.mf.base.CommandManager;
import me.mattstudios.mf.base.components.TypeResult;
import net.crankedpvp.customexplosions.commands.AdminExplosiveCommand;
import net.crankedpvp.customexplosions.listeners.CreeperListener;
import net.crankedpvp.customexplosions.listeners.TntListener;
import net.crankedpvp.customexplosions.struct.CreeperTypes;
import net.crankedpvp.customexplosions.struct.TNTTypes;
import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.stream.Collectors;
@Getter
public class CustomExplosionsPlugin extends JavaPlugin {
@Getter
private static CustomExplosionsPlugin instance;
private ProtocolManager protocolManager;
private CommandManager commandManager;
public void onEnable() {
instance = this;
this.commandManager = new CommandManager(this, true);
registerCommandParameters();
registerCommandCompletion();
registerCommands();
this.registerListeners();
this.protocolManager = ProtocolLibrary.getProtocolManager();
}
public void onDisable() {
instance = null;
}
private void registerListeners() {
//this.getServer().getPluginManager().registerEvents((Listener)new TntListener(), (Plugin)this);
this.getServer().getPluginManager().registerEvents((Listener)new CreeperListener(), (Plugin)this);
}
private void registerCommands() {
commandManager.register(new AdminExplosiveCommand());
}
private void registerCommandParameters() {
this.commandManager.getParameterHandler().register(TNTTypes.class, argument -> {
TNTTypes tntTypes = TNTTypes.valueOf(String.valueOf(argument).toUpperCase());
return new TypeResult(tntTypes, argument);
});
this.commandManager.getParameterHandler().register(CreeperTypes.class, argument -> {
CreeperTypes creeperTypes = CreeperTypes.valueOf(String.valueOf(argument).toUpperCase());
return new TypeResult(creeperTypes, argument);
});
}
private void registerCommandCompletion() {
this.commandManager.getCompletionHandler().register("#creepertypes", input -> {
return Arrays.stream(CreeperTypes.values()).map(CreeperTypes::name).collect(Collectors.toList());
});
this.commandManager.getCompletionHandler().register("#tnttypes", input -> {
return Arrays.stream(TNTTypes.values()).map(TNTTypes::name).collect(Collectors.toList());
});
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.customexplosions.commands;
import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.customexplosions.struct.CreeperTypes;
import net.crankedpvp.customexplosions.struct.TNTTypes;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Command("ace")
public class AdminExplosiveCommand extends CommandBase {
@Default
@Permission("cranked.admin")
public void onDefault(CommandSender sender) {
sender.sendMessage(CC.translate("&e&lCranked Custom Explosives"));
sender.sendMessage(CC.translate("&e/ace <tnt/creeper> <type> &f- &7Gives you custom tnt or creeper eggs"));
}
@SubCommand("tnt")
@Permission("cranked.admin")
public void giveTnt(CommandSender sender, @Completion("#tnttypes") TNTTypes type) {
ItemStack item = type.getTNTItem();
Player player = (Player)sender;
player.getInventory().addItem(item);
player.sendMessage(CC.translate("&a + " + type.getItemName()));
}
@SubCommand("creeper")
@Permission("cranked.admin")
public void giveCreeper(CommandSender sender, @Completion("#creepertypes") CreeperTypes type) {
ItemStack item = type.getCCItem();
Player player = (Player)sender;
player.getInventory().addItem(item);
player.sendMessage(CC.translate("&a + " + type.getItemName()));
}
}
@@ -0,0 +1,160 @@
package net.crankedpvp.customexplosions.listeners;
import lombok.SneakyThrows;
import net.crankedpvp.crankedutils.utils.WorldGuardUtils;
import net.crankedpvp.customexplosions.struct.CreeperTypes;
import net.minecraft.server.v1_8_R3.EntityLiving;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreeper;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
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.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.*;
public class CreeperListener implements Listener {
private final List<Material> nonSolidBlocks;
public static final Map<UUID, CreeperTypes> creepers = new HashMap<>();
public CreeperListener() {
this.nonSolidBlocks = new ArrayList<>(Arrays.asList(Material.AIR, Material.CHEST, Material.OBSIDIAN));
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerUseCreeperEgg(PlayerInteractEvent e) {
CreeperTypes ct;
if (e.isCancelled() && e.useItemInHand() != Event.Result.ALLOW) {
return;
}
if (e.hasItem() && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) && (ct = this.getCCType(e.getItem())) != null) {
this.processCustomCreeperPlaced(e, ct);
}
}
public void processCustomCreeperPlaced(PlayerInteractEvent e, CreeperTypes ct) {
if (e.hasItem() && (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
Location spawnLoc;
Block b;
e.setCancelled(true);
Player p = e.getPlayer();
try {
Material m2;
try {
b = e.getClickedBlock().getY() < 254 ? p.getTargetBlock((HashSet<Byte>) null, 4) : e.getClickedBlock();
} catch (Exception err) {
b = e.getClickedBlock();
}
if (e.getClickedBlock().getY() >= 254 && e.getBlockFace() != BlockFace.UP) {
return;
}
if (!WorldGuardUtils.canPvPInRegion(b.getLocation())) {
return;
}
spawnLoc = b.getLocation().getY() >= 255.0 ? b.getLocation() : b.getLocation().add(0.0, 1.0, 0.0);
ItemStack egg = e.getItem();
if (egg.getAmount() > 1) {
egg.setAmount(egg.getAmount() - 1);
p.setItemInHand(egg);
} else {
p.setItemInHand(null);
}
spawnLoc.add(0.5, 0.0, 0.5);
} catch (Exception err) {
err.printStackTrace();
return;
}
Bukkit.getLogger().info("[CosmicCustomCreeper] (" + ct.name() + ") spawnLocation: " + spawnLoc);
Creeper c = (Creeper) b.getWorld().spawnEntity(spawnLoc, EntityType.CREEPER);
c.setCustomName(ct.getMobName());
c.setCustomNameVisible(true);
creepers.put(c.getUniqueId(), ct);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCustomCreeperExplode(EntityExplodeEvent e) {
if (e.getEntity() == null || !creepers.containsKey(e.getEntity().getUniqueId())) {
return;
}
Creeper c = (Creeper) e.getEntity();
if (creepers.containsKey(c.getUniqueId())) {
CreeperTypes egg_type = creepers.get(c.getUniqueId());
Bukkit.getLogger().info("[CosmicCustomCreepers] EntityExplodeEvent for CustomCreeperEgg: " + egg_type.name() + " entity: " + c);
switch (egg_type) {
case HUGE:
Location loc = c.getLocation();
this.spawnFastExplosion(loc.clone().add(0.0, 3.0, 0.0));
this.spawnFastExplosion(loc.clone().add(0.0, -3.0, 0.0));
if (new Random().nextBoolean()) {
this.spawnFastExplosion(loc.clone().add(3.0, 0.0, 0.0));
this.spawnFastExplosion(loc.clone().add(0.0, 0.0, 3.0));
} else {
this.spawnFastExplosion(loc.clone().add(-3.0, 0.0, 0.0));
this.spawnFastExplosion(loc.clone().add(0.0, 0.0, -3.0));
}
break;
case LUCKY:
//This is handled in the spawners plugin (SpawnerBreakListener)
break;
case RAID:
//This is handled in the spawners plugin (SpawnerBreakListener)
break;
default:
Bukkit.getLogger().info("[CosmicCustomCreeper] No Creeper type found!");
}
}
}
private void spawnFastExplosion(Location l) {
if (this.nonSolidBlocks.contains(l.getBlock().getType()) || l.getBlock().isLiquid()) {
return;
}
CraftCreeper creeper = l.getWorld().spawn(l, CraftCreeper.class);
net.minecraft.server.v1_8_R3.Entity nms = ((CraftEntity) creeper).getHandle();
NBTTagCompound nbt = new NBTTagCompound();
nms.c(nbt);
nbt.setInt("Fuse", 0);
EntityLiving living = (EntityLiving) nms;
living.a(nbt);
}
private CreeperTypes getCCType(ItemStack creeper_egg) {
if (!(creeper_egg != null && creeper_egg.hasItemMeta() && creeper_egg.getItemMeta().hasDisplayName() && creeper_egg.getItemMeta().hasLore())) {
return null;
}
CreeperTypes tnt_type = null;
String name = creeper_egg.getItemMeta().getDisplayName();
for (CreeperTypes tt : CreeperTypes.values()) {
if (!name.equals(tt.getItemName())) continue;
tnt_type = tt;
break;
}
return tnt_type;
}
}
@@ -0,0 +1,169 @@
package net.crankedpvp.customexplosions.listeners;
import net.crankedpvp.customexplosions.CustomExplosionsPlugin;
import net.crankedpvp.customexplosions.struct.TNTTypes;
import net.minecraft.server.v1_8_R3.EntityTNTPrimed;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftTNTPrimed;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class TntListener implements Listener {
public static Map<Location, TNTTypes> tnt_tracker = new HashMap<>();
private final List<Material> nonSolidBlocks;
public static final Map<UUID, TNTTypes> customTnt = new HashMap<>();
public TntListener() {
this.nonSolidBlocks = new ArrayList<Material>(Arrays.asList(Material.AIR, Material.SAND, Material.WATER, Material.LAVA, Material.STATIONARY_LAVA, Material.STATIONARY_WATER));
}
@EventHandler(priority= EventPriority.MONITOR, ignoreCancelled=true)
public void onTNTPlace(BlockPlaceEvent e) {
if (e.getBlockPlaced().getType() == Material.TNT) {
TNTTypes tnt_type = this.getTNTType(e.getItemInHand());
if (tnt_type == null) {
return;
}
tnt_tracker.put(e.getBlockPlaced().getLocation(), tnt_type);
}
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if (e.getItem().getType() == Material.TNT) {
TNTTypes tnt_type = this.getTNTType(e.getItem());
if (tnt_type == null) {
return;
}
tnt_tracker.put(e.getBlock().getLocation(), tnt_type);
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onTNTBreak(BlockBreakEvent e) {
if (e.getBlock().getType() == Material.TNT && tnt_tracker.containsKey(e.getBlock().getLocation())) {
e.setCancelled(true);
Location loc = e.getBlock().getLocation();
e.getBlock().setType(Material.AIR);
e.getBlock().getWorld().dropItemNaturally(loc, tnt_tracker.get(loc).getTNTItem());
tnt_tracker.remove(loc);
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onExplosivePrime(ExplosionPrimeEvent e) {
if (e.getEntity() != null && e.getEntity() instanceof TNTPrimed) {
EntityTNTPrimed tntPrimed = ((CraftTNTPrimed)e.getEntity()).getHandle();
TNTTypes tntType = tnt_tracker.get(e.getEntity().getLocation());
if (tntType != null) {
customTnt.put(e.getEntity().getUniqueId(), tntType);
return;
}
Location loc = tntPrimed.getSource().getBukkitEntity().getLocation();
TNTTypes tnt_type = tnt_tracker.remove(loc);
if (tnt_type != null) {
customTnt.put(e.getEntity().getUniqueId(), tnt_type);
}
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTNTExplode(EntityExplodeEvent e) {
if (e.getEntity() == null || e.getEntityType() != EntityType.PRIMED_TNT)
return;
TNTPrimed tnt = (TNTPrimed)e.getEntity();
if (customTnt.containsKey(tnt.getUniqueId())) {
TNTTypes tnt_type = customTnt.get(tnt.getUniqueId());
switch (tnt_type) {
case LUCKY:
//Coded in AstroSpawners plugin
case HUGE:
Location loc = tnt.getLocation();
spawnFastExplosion(loc.clone().add(0.0D, 3.0D, 0.0D), true);
spawnFastExplosion(loc.clone().add(0.0D, -3.0D, 0.0D), true);
if (ThreadLocalRandom.current().nextBoolean()) {
spawnFastExplosion(loc.clone().add(3.0D, 0.0D, 0.0D), true);
spawnFastExplosion(loc.clone().add(0.0D, 0.0D, 3.0D), true);
} else {
spawnFastExplosion(loc.clone().add(-3.0D, 0.0D, 0.0D), true);
spawnFastExplosion(loc.clone().add(0.0D, 0.0D, -3.0D), true);
}
break;
case LETHAL:
for (int i = 0; i < 4; i++)
spawnFastExplosion(tnt.getLocation());
break;
case MIMIC:
final Location l = tnt.getLocation();
Bukkit.getScheduler().runTaskLater(CustomExplosionsPlugin.getInstance(), new Runnable() {
public void run() {
TntListener.this.spawnFastExplosion(l);
}
},100L);
Bukkit.getScheduler().runTaskLater(CustomExplosionsPlugin.getInstance(), new Runnable() {
public void run() {
spawnFastExplosion(l);
}
},200L);
Bukkit.getScheduler().runTaskLater(CustomExplosionsPlugin.getInstance(), new Runnable() {
public void run() {
spawnFastExplosion(l);
}
},300L);
break;
default:
Bukkit.getLogger().info("[CosmicCustomCreeper] No Creeper type found!");
}
}
}
private TNTTypes getTNTType(ItemStack tnt_is) {
if (!(tnt_is != null && tnt_is.hasItemMeta() && tnt_is.getItemMeta().hasDisplayName() && tnt_is.getItemMeta().hasLore())) {
return null;
}
TNTTypes tnt_type = null;
String name = tnt_is.getItemMeta().getDisplayName();
for (TNTTypes tt : TNTTypes.values()) {
if (!name.equals(tt.getItemName())) continue;
tnt_type = tt;
break;
}
return tnt_type;
}
private void spawnFastExplosion(Location l) {
this.spawnFastExplosion(l, true);
}
private void spawnFastExplosion(Location l, boolean onlyAir) {
Material type = l.getBlock().getType();
if (onlyAir && type != Material.AIR || !this.nonSolidBlocks.contains(type)) {
return;
}
TNTPrimed tnt = (TNTPrimed)l.getWorld().spawnEntity(l, EntityType.PRIMED_TNT);
tnt.setFuseTicks(0);
}
}
@@ -0,0 +1,33 @@
package net.crankedpvp.customexplosions.struct;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum CreeperTypes {
HUGE(ChatColor.AQUA.toString() + ChatColor.BOLD + "Gigantic Creeper", ChatColor.GRAY.toString() + ChatColor.ITALIC + "Explodes in a much larger radius."),
RAID(ChatColor.RED.toString() + ChatColor.BOLD + "Raid Creeper", ChatColor.GRAY.toString() + ChatColor.ITALIC + "100% chance of spawner drops."),
LUCKY(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Lucky Creeper", ChatColor.GRAY.toString() + ChatColor.ITALIC + "Increases chances of spawner drops.");
final String display;
final String[] lore;
CreeperTypes(String name, String... lore) {
this.display = name;
this.lore = lore;
}
public String getItemName() {
return this.display.replace(ChatColor.BOLD.toString(), "");
}
public String getMobName() {
return this.display;
}
public ItemStack getCCItem() {
return new ItemBuilder(Material.MONSTER_EGG, 1, (short)50).setLore(lore).setName(display).colorize().build();
}
}
@@ -0,0 +1,31 @@
package net.crankedpvp.customexplosions.struct;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum TNTTypes {
HUGE(ChatColor.AQUA + "Gigantic TNT", new String[]{ChatColor.AQUA.toString() + ChatColor.ITALIC + "Explodes in a much larger radius.", "", ChatColor.GRAY + "Spawns 2 extra explosions at", ChatColor.GRAY + "y+3 and y-3 of TNT, and another", ChatColor.GRAY + "2 explosions at either x+3, z+3 or", ChatColor.GRAY + "x-3 and z-3."}),
LETHAL(ChatColor.DARK_RED + "Lethal TNT", new String[]{ChatColor.DARK_RED.toString() + ChatColor.ITALIC + "A more dense, dangerous explosion.", "", ChatColor.GRAY + "Creates 4x extra TNT explosions at", ChatColor.GRAY + "same location as the original."}),
LUCKY(ChatColor.YELLOW + "Lucky TNT", new String[]{ChatColor.YELLOW.toString() + ChatColor.ITALIC + "Increases chances of spawner drops.", "", ChatColor.GRAY + "200% the normal chance of a", ChatColor.GRAY + "spawner dropping from explosion."}),
MIMIC(ChatColor.GREEN + "Mimic TNT", new String[]{ChatColor.GREEN.toString() + ChatColor.ITALIC + "Repeats the same explosion many times.", "", ChatColor.GRAY + "Spawns a TNT explosion at", ChatColor.GRAY + "same location every 5s", ChatColor.GRAY + "for 15s total, or 3 explosions."});
final String display;
final String[] lore;
TNTTypes(String name, String[] lore) {
this.display = name;
this.lore = lore;
}
public String getItemName() {
return this.display;
}
public ItemStack getTNTItem() {
return new ItemBuilder(Material.TNT, display, lore).colorize().build();
}
}
@@ -0,0 +1,7 @@
name: CrankedCustomExplosives
main: net.crankedpvp.customexplosions.CustomExplosionsPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils