Files
src
build.gradle
settings.gradle
Code
5 1,685
src/main/java/com/yopaits/minievents/AmongUsPlugin.java
package com.yopaits.minievents;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
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.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
public final class AmongUsPlugin extends JavaPlugin implements Listener, CommandExecutor {
private static final String PREFIX = ChatColor.DARK_RED + "[Among Us] " + ChatColor.RESET;
private static final String BODY_PREFIX = ChatColor.RED + "Among Us Body: ";
private static final String TASK_SELECT_TITLE = "AU: Create Task";
private static final String TASK_PLACEMENT_PREFIX = "AU: Place Task: ";
private static final String TASK_TITLE_PREFIX = "AU: Task: ";
private static final String VENT_TITLE = "AU: Vents";
private static final String VOTE_TITLE = "AU: Vote";
private static final String RARITY_TITLE = "AU: Cosmetic Rarity";
private static final String TRIM_TITLE_PREFIX = "AU: Trim: ";
private static final String HIDDEN_TEAM = "amongus_hidden_tags";
private static final List<TaskSpec> TASKS = List.of(
new TaskSpec("Fix Wiring", "REDSTONE", "Connect the wiring: click the panel three times to complete the repair."),
new TaskSpec("Download Data", "PAPER", "Download the station data by completing three progress steps."),
new TaskSpec("Swipe Card", "NAME_TAG", "Swipe your card through the reader three times."),
new TaskSpec("Fuel Engines", "COAL", "Load fuel into the engine in three measured steps."),
new TaskSpec("Align Engine", "COMPASS", "Align the engine controls with three calibration clicks."),
new TaskSpec("Clear Asteroids", "ARROW", "Clear the asteroid field with three successful shots."),
new TaskSpec("Prime Shields", "SHIELD", "Prime the shield system with three activations."),
new TaskSpec("Chart Course", "MAP", "Chart the route by confirming three navigation points."),
new TaskSpec("Stabilize Steering", "LEVER", "Stabilize the steering system in three steps."),
new TaskSpec("Inspect Sample", "GLASS_BOTTLE", "Inspect the sample and complete three analysis steps.")
);
private static final List<String> RARITIES = List.of("Common", "Uncommon", "Rare", "Epic", "Legendary", "Mythic");
private static final List<String> ARMOR_MATERIALS = List.of(
"LEATHER_CHESTPLATE", "CHAINMAIL_CHESTPLATE", "IRON_CHESTPLATE",
"GOLDEN_CHESTPLATE", "DIAMOND_CHESTPLATE", "NETHERITE_CHESTPLATE"
);
private static final List<String> TRIM_PATTERNS = List.of(
"sentry", "dune", "coast", "wild", "ward", "eye", "vex", "tide", "snout",
"rib", "spire", "wayfinder", "shaper", "raiser", "host", "silence", "flow", "bolt"
);
private final Map<UUID, Role> roles = new HashMap<>();
private final Set<UUID> deadPlayers = new HashSet<>();
private final Set<UUID> gamePlayers = new HashSet<>();
private final Map<UUID, List<String>> remainingTasks = new HashMap<>();
private final Map<UUID, Integer> taskProgress = new HashMap<>();
private final Map<UUID, Long> killCooldowns = new HashMap<>();
private final Map<UUID, Long> ventCooldowns = new HashMap<>();
private final Map<UUID, String> votes = new HashMap<>();
private final Map<UUID, List<Location>> ventMenus = new HashMap<>();
private final Map<UUID, List<UUID>> voteMenus = new HashMap<>();
private final Set<UUID> bannedPlayers = new HashSet<>();
private final Set<String> claimedCosmetics = new HashSet<>();
private final Map<UUID, Set<String>> ownedCosmetics = new HashMap<>();
private final Map<UUID, String> equippedCosmetics = new HashMap<>();
private final Map<String, String> taskStations = new LinkedHashMap<>();
private final List<Location> vents = new ArrayList<>();
private final Set<String> cosmeticCrates = new HashSet<>();
private final Map<UUID, Location> firstDoorCorners = new HashMap<>();
private final Map<UUID, Location> secondDoorCorners = new HashMap<>();
private final Map<Integer, List<DoorCell>> doorRegions = new LinkedHashMap<>();
private Team hiddenTeam;
private NamespacedKey cosmeticArmorKey;
private int imposterCount;
private int playerLimit;
private int taskAmount;
private int killCooldownSeconds;
private int nextDoorId;
private boolean gameActive;
private boolean meetingActive;
private boolean doorsClosed;
private int meetingToken;
@Override
public void onEnable() {
saveDefaultConfig();
cosmeticArmorKey = new NamespacedKey(this, "cosmetic_armor");
loadPersistentData();
imposterCount = Math.max(1, getConfig().getInt("imposter-count", 1));
playerLimit = Math.max(3, getConfig().getInt("player-limit", 10));
taskAmount = Math.max(1, Math.min(TASKS.size(), getConfig().getInt("task-amount", 5)));
killCooldownSeconds = Math.max(0, getConfig().getInt("kill-cooldown-seconds", 30));
setupHiddenTeam();
Bukkit.getPluginManager().registerEvents(this, this);
for (String name : List.of("ahelp", "lobby", "role", "asetlobby", "asetmetting", "aimposteramont",
"acreatevent", "acreatetask", "acosmeticscrate", "astart", "aend", "aban", "akick",
"aplayerlimit", "ataskamont", "akillcooldown", "astats", "adoorset", "doorsabotage",
"lightsabotage", "meeting")) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(this);
}
}
}
@Override
public void onDisable() {
applyDoorState(false);
doorsClosed = false;
getConfig().set("doors-closed", false);
persistData();
if (hiddenTeam != null) {
for (String entry : new HashSet<>(hiddenTeam.getEntries())) {
hiddenTeam.removeEntry(entry);
}
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String name = command.getName().toLowerCase(Locale.ROOT);
if (name.startsWith("a") && !sender.isOp()) {
sender.sendMessage(PREFIX + ChatColor.RED + "This command is for operators only.");
return true;
}
switch (name) {
case "ahelp" -> sendHelp(sender);
case "role" -> showRole(sender);
case "lobby" -> leaveForLobby(sender);
case "asetlobby" -> setPoint(sender, "lobby", "Lobby");
case "asetmetting" -> setPoint(sender, "meeting-room", "Meeting room");
case "aimposteramont" -> setAmount(sender, args, "imposter-count", "Imposter count", 1, 10);
case "aplayerlimit" -> setAmount(sender, args, "player-limit", "Player limit", 3, 39);
case "ataskamont" -> setAmount(sender, args, "task-amount", "Task amount", 1, TASKS.size());
case "akillcooldown" -> setKillCooldown(sender, args);
case "acreatevent" -> createVent(sender);
case "acreatetask" -> openTaskPlacement(sender);
case "acosmeticscrate" -> placeCosmeticsCrate(sender);
case "astart" -> startGame(sender);
case "aend" -> {
if (gameActive) {
finishGame(null, "The game was ended by an operator.");
} else {
sender.sendMessage(PREFIX + "There is no active game.");
}
}
case "aban" -> banPlayer(sender, args);
case "akick" -> kickPlayer(sender, args);
case "astats" -> showStats(sender);
case "adoorset" -> createDoor(sender);
case "doorsabotage" -> sabotageDoors(sender);
case "lightsabotage" -> sabotageLights(sender);
case "meeting" -> {
if (sender instanceof Player player) {