Files
assets
src
build.gradle
pack.mcmeta
pack.png
settings.gradle
Code
28 641
src/main/java/com/brokensmp/BrokenSmp.java
package com.brokensmp;
import com.cryptomorin.xseries.XAttribute;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
public final class BrokenSmp extends JavaPlugin implements Listener {
private final Map<UUID, String> characters = new HashMap<>();
private final Map<UUID, Long> cooldowns = new HashMap<>();
private final Map<UUID, Long> active = new HashMap<>();
private final Map<UUID, Double> originalScale = new HashMap<>();
private final Map<UUID, Map<String, Double>> originalReach = new HashMap<>();
private final Map<UUID, LivingEntity> held = new HashMap<>();
private final Map<UUID, Boolean> originalGravity = new HashMap<>();
private final Map<UUID, Float> previousPitch = new HashMap<>();
private final Map<UUID, Long> lastSlam = new HashMap<>();
private final Map<UUID, Set<Block>> illusions = new HashMap<>();
private final Map<UUID, Location> lastFootprint = new HashMap<>();
private final Map<UUID, Boolean> watchingGlow = new HashMap<>();
private final Set<UUID> watchingInvisible = new HashSet<>();
private final Random random = new Random();
private long ticks;
@Override
public void onEnable() {
saveDefaultConfig();
if (getClass().getClassLoader().getResource("broken-smp-resource-pack.zip") != null) {
saveResource("broken-smp-resource-pack.zip", true);
} else {
getLogger().warning("Resource pack is missing from the plugin jar; ability icons will not be available until the pack is installed.");
}
getServer().getPluginManager().registerEvents(this, this);
getServer().getScheduler().runTaskTimer(this, this::tick, 1L, 1L);
}
@Override
public void onDisable() {
for (Player player : Bukkit.getOnlinePlayers()) {
endAbility(player);
clearPassive(player);
player.sendActionBar(Component.empty());
}
restoreWatchingGlow();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 3 && args[0].equalsIgnoreCase("cooldown") && args[1].equalsIgnoreCase("reset")) {
if (!sender.hasPermission("brokensmp.cooldown.reset")) {
sender.sendMessage("§cYou do not have permission to reset cooldowns.");
return true;
}
if (args[2].equalsIgnoreCase("@a")) {
for (Player target : Bukkit.getOnlinePlayers()) cooldowns.remove(target.getUniqueId());
sender.sendMessage("§aReset cooldowns for all online players.");
} else {
Player target = Bukkit.getPlayerExact(args[2]);
if (target == null) {
sender.sendMessage("§cPlayer not found or not online.");
return true;
}
cooldowns.remove(target.getUniqueId());
sender.sendMessage("§aReset cooldown for " + target.getName() + ".");
}
return true;
}
if (!(sender instanceof Player player)) {
sender.sendMessage("Players only.");
return true;
}
if (args.length != 1) return false;
String name = args[0].toLowerCase(java.util.Locale.ROOT);
if (name.equals("use")) {
activate(player);
return true;
}
if (!List.of("giant-alex", "entity303", "0000", "herobrine", "null").contains(name)) return false;
endAbility(player);
clearPassive(player);
characters.put(player.getUniqueId(), name);
applyPassive(player, name);
showAbilityIcon(player, name, System.currentTimeMillis());
player.sendMessage("§aCharacter selected: " + name + ". Use /broken use to activate your ability.");
return true;
}
private void activate(Player player) {
UUID id = player.getUniqueId();
String character = characters.get(id);
if (character == null) {
player.sendMessage("§cSelect a character with /broken first.");
return;
}
if (active.containsKey(id) || cooldowns.getOrDefault(id, 0L) > System.currentTimeMillis()) {
player.sendMessage("§cYour ability is not ready.");
return;
}
if (character.equals("herobrine")) {
player.sendMessage("§cI Am Here requires the VexBot dependency, which is not installed in this project.");
return;
}
if (character.equals("entity303")) {
RayTraceResult result = player.getWorld().rayTraceEntities(player.getEyeLocation(), player.getEyeLocation().getDirection(), 20, 0.3,
e -> e instanceof LivingEntity && e != player && !e.isDead());
if (result == null || !(result.getHitEntity() instanceof LivingEntity target)) {
player.sendMessage("§cLook at an entity first.");
return;
}
held.put(id, target);
originalGravity.put(id, target.hasGravity());
target.setGravity(false);
previousPitch.put(id, player.getLocation().getPitch());
}
if (character.equals("giant-alex")) {
AttributeInstance scale = attribute(player, "scale");
if (scale != null) {
originalScale.put(id, scale.getBaseValue());
scale.setBaseValue(Math.min(scale.getBaseValue() * 3.0, 16.0));
}
}
if (character.equals("null")) {
for (Player viewer : Bukkit.getOnlinePlayers()) if (!viewer.equals(player)) viewer.hidePlayer(this, player);
}
active.put(id, System.currentTimeMillis() + 10_000L);
cooldowns.put(id, System.currentTimeMillis() + Math.max(10, getConfig().getLong("cooldown-seconds", 30)) * 1000L);
showAbilityIcon(player, character, System.currentTimeMillis());
sound(player, "ENTITY_ENDERMAN_TELEPORT");
}
private void showAbilityIcon(Player player, String character, long now) {
String icon = cooldowns.getOrDefault(player.getUniqueId(), 0L) > now || active.containsKey(player.getUniqueId())
? "\ue305" : switch (character) {
case "giant-alex" -> "\ue300";
case "entity303" -> "\ue301";
case "0000" -> "\ue302";
case "herobrine" -> "\ue303";
case "null" -> "\ue304";
default -> "";
};
player.sendActionBar(Component.text(icon).font(Key.key("minecraft", "broken_smp")));
}
private void tick() {
ticks++;
long now = System.currentTimeMillis();
if (ticks % 20 == 0) updateWatching();
for (Player player : Bukkit.getOnlinePlayers()) {
UUID id = player.getUniqueId();
String character = characters.get(id);
if (character == null) continue;
if (ticks % 10 == 0) showAbilityIcon(player, character, now);
if (ticks % 100 == 0) {
if (character.equals("entity303")) {
effect(player, "STRENGTH", 220, 0);
effect(player, "SPEED", 220, 0);
effect(player, "FIRE_RESISTANCE", 220, 0);
} else if (character.equals("null")) effect(player, "NIGHT_VISION", 300, 0);
}
if (character.equals("null") && ticks % 8 == 0 && !active.containsKey(id)) {
particle(player.getLocation().add(0, 0.2, 0), "SMOKE", 4);
if (random.nextInt(20) == 0) for (Player nearby : player.getWorld().getPlayers())