tagList = getTags();
for (CombatTag combatTag : tagList) {
if (combatTag.doesEnemyMatch(entity)) {
return combatTag;
}
}
return null;
}
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/object/TagReason.java
================================================
package com.github.sirblobman.combatlogx.api.object;
/**
* The reason for putting a player into combat.
*/
public enum TagReason {
/**
* Unknown reason for being tagged. Usually occurs from the tag command.
* This can also occur from the Damage Tagger expansion.
*/
UNKNOWN,
/**
* The player was damaged by an enemy.
*/
ATTACKED,
/**
* The player caused an enemy to take damage.
*/
ATTACKER;
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/object/TagType.java
================================================
package com.github.sirblobman.combatlogx.api.object;
/**
* The type of combat that a player was tagged with.
*/
public enum TagType {
/**
* Unknown type for being tagged. Usually occurs from the tag command.
*/
UNKNOWN,
/**
* CombatTag was caused by another player or themselves.
*/
PLAYER,
/**
* CombatTag was caused by a mob.
*/
MOB,
/**
* CombatTag was caused by the Damage Tagger expansion.
*/
DAMAGE,
/**
* CombatTag was caused by a custom mob from the MythicMobs plugin.
*/
MYTHIC_MOB;
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/object/TimerType.java
================================================
package com.github.sirblobman.combatlogx.api.object;
/**
* The type of timer that will be used by CombatLogX
*/
public enum TimerType {
/**
* Every player will be tagged for the same amount of time.
*/
GLOBAL,
/**
* Some players will have special combat times based on their permissions, others will use the global time.
*/
PERMISSION
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/object/TimerUpdater.java
================================================
package com.github.sirblobman.combatlogx.api.object;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import com.github.sirblobman.combatlogx.api.manager.ITimerManager;
/**
* If you are going to implement this class, don't forget to register your instance with the timer manager.
*
* @see ITimerManager
* @see ITimerManager#addUpdaterTask(TimerUpdater)
*/
public interface TimerUpdater {
/**
* This method is executed every tick while a player is in combat.
*
* @param player The player for this update.
* @param timeLeftMillis The amount of time left in combat for this player.
*/
void update(@NotNull Player player, long timeLeftMillis);
/**
* This method is executed whenever a player is untagged.
*
* @param player The player for this removal.
*/
void remove(@NotNull Player player);
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/object/UntagReason.java
================================================
package com.github.sirblobman.combatlogx.api.object;
/**
* The reason for removing a player from combat.
*/
public enum UntagReason {
/**
* The player waited patiently until they were no longer in combat
*/
EXPIRE(true),
/**
* The player died and the config option was enabled to untag them
*/
SELF_DEATH(true),
/**
* The player's enemy died and the config option was enabled to untag them
*/
ENEMY_DEATH(true),
/**
* The enemy of the player forgave them.
*/
ENEMY_FORGIVE(true),
/**
* The player disconnected from the server
*/
QUIT,
/**
* The player was kicked by a plugin or timed out
*/
KICK;
private final boolean expire;
UntagReason() {
this(false);
}
UntagReason(boolean expire) {
this.expire = expire;
}
public boolean isExpire() {
return this.expire;
}
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/placeholder/IPlaceholderExpansion.java
================================================
package com.github.sirblobman.combatlogx.api.placeholder;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.ICombatLogXNeeded;
import com.github.sirblobman.api.shaded.adventure.text.Component;
import com.github.sirblobman.api.shaded.adventure.text.minimessage.MiniMessage;
import com.github.sirblobman.api.shaded.adventure.text.serializer.legacy.LegacyComponentSerializer;
/**
* You must override all required methods and at least one of the following methods:
*
* - {@link #getReplacementString(Player, List, String)}
* - {@link #getReplacement(Player, List, String)}
*
*
* If you do not override at least one, you will get an infinite loop.
*/
public interface IPlaceholderExpansion extends ICombatLogXNeeded {
@NotNull String getId();
default @Nullable String getReplacementString(@NotNull Player player, @NotNull List enemyList,
@NotNull String placeholder) {
Component replacement = getReplacement(player, enemyList, placeholder);
if (replacement == null || Component.empty().equals(replacement)) {
return "";
}
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
return serializer.serialize(replacement);
}
@SuppressWarnings("UnnecessaryUnicodeEscape")
default @Nullable Component getReplacement(@NotNull Player player, @NotNull List enemyList,
@NotNull String placeholder) {
String string = getReplacementString(player, enemyList, placeholder);
if (string == null || string.isEmpty()) {
return Component.empty();
}
if (string.contains("\u00A7")) {
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection();
return serializer.deserialize(string);
}
if (string.contains("&")) {
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand();
return serializer.deserialize(string);
}
ICombatLogX combatLogX = getCombatLogX();
LanguageManager languageManager = combatLogX.getLanguageManager();
MiniMessage miniMessage = languageManager.getMiniMessage();
return miniMessage.deserialize(string);
}
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/placeholder/PlaceholderHelper.java
================================================
package com.github.sirblobman.combatlogx.api.placeholder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.api.nms.EntityHandler;
import com.github.sirblobman.api.nms.MultiVersionHandler;
import com.github.sirblobman.api.utility.paper.PaperChecker;
import com.github.sirblobman.api.utility.paper.PaperHelper;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.api.shaded.adventure.text.Component;
import me.clip.placeholderapi.PlaceholderAPI;
public final class PlaceholderHelper {
public static @NotNull Component getEnemyName(@NotNull ICombatLogX plugin, @NotNull Player player,
@Nullable Entity entity) {
if (entity == null) {
return getUnknownEnemy(plugin, player);
}
if (PaperChecker.hasNativeComponentSupport()) {
Component customName = PaperHelper.getCustomName(entity);
if (customName != null) {
return customName;
}
}
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
String entityName = entityHandler.getName(entity);
return Component.text(entityName);
}
public static @NotNull Component getUnknownEnemy(@NotNull ICombatLogX plugin, @NotNull Player player) {
LanguageManager languageManager = plugin.getLanguageManager();
return languageManager.getMessage(player, "placeholder.unknown-enemy");
}
public static @NotNull String replacePlaceholderAPI(@NotNull Player player, @NotNull String string) {
PluginManager pluginManager = Bukkit.getPluginManager();
if (pluginManager.isPluginEnabled("PlaceholderAPI")) {
return PlaceholderAPI.setPlaceholders(player, string);
}
return string;
}
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/utility/CommandHelper.java
================================================
package com.github.sirblobman.combatlogx.api.utility;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.folia.FoliaHelper;
import com.github.sirblobman.api.folia.details.RunnableTask;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
public final class CommandHelper {
public static void runSync(@NotNull ICombatLogX plugin, @NotNull Runnable runnable) {
FoliaHelper foliaHelper = plugin.getFoliaHelper();
TaskScheduler scheduler = foliaHelper.getScheduler();
RunnableTask task = new RunnableTask(plugin.getPlugin(), runnable);
scheduler.scheduleTask(task);
}
public static void runAsConsole(@NotNull ICombatLogX plugin, @NotNull String command) {
try {
CommandSender console = Bukkit.getConsoleSender();
Bukkit.dispatchCommand(console, command);
} catch (Exception ex) {
String messageFormat = "Failed to execute command '/%s' as the server console:";
String logMessage = String.format(Locale.US, messageFormat, command);
Logger logger = plugin.getLogger();
logger.log(Level.SEVERE, logMessage, ex);
}
}
public static void runAsPlayer(@NotNull ICombatLogX plugin, @NotNull Player player, @NotNull String command) {
try {
player.performCommand(command);
} catch (Exception ex) {
String playerName = player.getName();
String messageFormat = "Failed to execute command '/%s' as player '%s':";
String logMessage = String.format(Locale.US, messageFormat, command, playerName);
Logger logger = plugin.getLogger();
logger.log(Level.SEVERE, logMessage, ex);
}
}
public static void runAsOperator(@NotNull ICombatLogX plugin, @NotNull Player player, @NotNull String command) {
if (player.isOp()) {
runAsPlayer(plugin, player, command);
return;
}
try {
player.setOp(true);
player.performCommand(command);
} catch (Exception ex) {
String playerName = player.getName();
String messageFormat = "Failed to execute command '/%s' as player '%s' with operator permissions:";
String logMessage = String.format(Locale.US, messageFormat, command, playerName);
Logger logger = plugin.getLogger();
logger.log(Level.SEVERE, logMessage, ex);
} finally {
player.setOp(false);
}
}
}
================================================
FILE: api/src/main/java/com/github/sirblobman/combatlogx/api/utility/EntityHelper.java
================================================
package com.github.sirblobman.combatlogx.api.utility;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.projectiles.ProjectileSource;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.configuration.MainConfiguration;
public final class EntityHelper {
public static @NotNull Entity linkTNT(@NotNull Entity original) {
if (!(original instanceof TNTPrimed)) {
return original;
}
TNTPrimed tntEntity = (TNTPrimed) original;
Entity source = tntEntity.getSource();
return (source == null ? original : source);
}
public static @NotNull Entity linkPet(@NotNull Entity original) {
if (!(original instanceof Tameable)) {
return original;
}
Tameable tameable = (Tameable) original;
AnimalTamer animalTamer = tameable.getOwner();
if (!(animalTamer instanceof Entity)) {
return original;
}
return (Entity) animalTamer;
}
public static @NotNull Entity linkProjectile(@NotNull ICombatLogX plugin, @NotNull Entity original) {
if (!(original instanceof Projectile)) {
return original;
}
Projectile projectile = (Projectile) original;
if (isProjectileIgnored(plugin, projectile)) {
return original;
}
ProjectileSource shooter = projectile.getShooter();
if (!(shooter instanceof Entity)) {
return original;
}
return (Entity) shooter;
}
public static boolean isNPC(@NotNull Entity entity) {
return entity.hasMetadata("NPC");
}
private static boolean isProjectileIgnored(@NotNull ICombatLogX plugin, @NotNull Projectile projectile) {
EntityType projectileType = projectile.getType();
MainConfiguration configuration = plugin.getConfiguration();
return configuration.isProjectileIgnored(projectileType);
}
}
================================================
FILE: api/src/main/resources/default-region-expansion-config.yml
================================================
# How should CombatLogX prevent players from entering non-pvp areas?
# Valid Modes:
# DISABLED - Ignore players.
# KNOCKBACK_PLAYER - Add some opposite velocity to the player. They will be pushed backwards.
# CANCEL_EVENT - Cancel the move event for the player.
# VULNERABLE - Allow the player to enter the area, but disable the pvp protection from the region plugin.
# KILL_PLAYER - Set the health of the player to zero.
# TELEPORT_TO_ENEMY - Teleport the player to their current enemy, or cancel the event if there are no enemies.
# Default: "KNOCKBACK_PLAYER"
no-entry-mode: "KNOCKBACK_PLAYER"
# This value is only used if 'no-entry-mode' is KNOCKBACK_PLAYER
# How much should the backwards velocity be multiplied by?
# Default: 1.5
knockback-strength: 1.5
# How much time (in seconds) should the plugin wait before sending another 'no-entry' message?
# Default: 30
message-cooldown: 30
# Should the region plugin also prevent teleporting?
# Teleport prevention will always use the CANCEL_EVENT mode.
prevent-teleport: true
# Are there any reasons that a teleport should not be cancelled?
# You can find a list of valid values in the link below:
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html
ignored-teleport-cause-list:
- "PLUGIN" # Some plugins don't like when CombatLogX cancels their teleports
- "UNKNOWN" # Allowing 'UNKNOWN' may fix some glitches with region protection plugins
================================================
FILE: build.gradle.kts
================================================
val baseVersion = providers.gradleProperty("version.base").get()
val betaVersion = providers.gradleProperty("version.beta").get().toBooleanStrict()
val betaString = if (betaVersion) "Beta-" else ""
val jenkinsBuild = providers.environmentVariable("BUILD_NUMBER").orElse("Unofficial").get()
rootProject.version = "${baseVersion}.${betaString}${jenkinsBuild}"
plugins {
id("java")
}
subprojects {
apply(plugin = "java")
java {
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
}
repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://nexus.sirblobman.xyz/public/")
}
dependencies {
compileOnly("org.jetbrains:annotations:26.0.2-1") // JetBrains Annotations
compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT") // Base Spigot API
compileOnly("com.github.sirblobman.api:core:2.9-SNAPSHOT") // BlueSlimeCore
}
tasks.withType {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:deprecation")
}
}
================================================
FILE: builder/build.gradle.kts
================================================
plugins {
id("distribution")
}
val coreJar: Configuration by configurations.creating
val pluginJar: Configuration by configurations.creating
val expansion: Configuration by configurations.creating
dependencies {
// BlueSlimeCore
coreJar("com.github.sirblobman.api:core:2.9-SNAPSHOT")
// CombatLogX
pluginJar(project(path = ":plugin", configuration = "shadow"))
// Normal Expansions
expansion(project(":expansion:action-bar"))
expansion(project(":expansion:boss-bar"))
expansion(project(path = ":expansion:cheat-prevention", configuration = "shadow"))
expansion(project(":expansion:damage-tagger"))
expansion(project(":expansion:damage-effects"))
expansion(project(":expansion:death-effects"))
expansion(project(path = ":expansion:end-crystal", configuration = "shadow"))
expansion(project(":expansion:force-field"))
expansion(project(":expansion:glowing"))
expansion(project(":expansion:logger"))
expansion(project(path = ":expansion:loot-protection", configuration = "shadow"))
expansion(project(":expansion:mob-tagger"))
expansion(project(":expansion:newbie-helper"))
expansion(project(":expansion:rewards"))
expansion(project(":expansion:scoreboard"))
// Compatibility expansions
expansion(project(":expansion:compatibility:AngelChest"))
expansion(project(":expansion:compatibility:ASkyBlock"))
expansion(project(":expansion:compatibility:BSkyBlock"))
expansion(project(":expansion:compatibility:Citizens"))
expansion(project(":expansion:compatibility:CMI"))
expansion(project(":expansion:compatibility:CrackShot"))
expansion(project(":expansion:compatibility:CrashClaim"))
expansion(project(":expansion:compatibility:EssentialsX"))
expansion(project(":expansion:compatibility:FabledSkyBlock"))
expansion(project(":expansion:compatibility:Factions"))
expansion(project(":expansion:compatibility:FeatherBoard"))
expansion(project(":expansion:compatibility:GriefDefender"))
expansion(project(":expansion:compatibility:GriefPrevention"))
expansion(project(":expansion:compatibility:HuskHomes"))
expansion(project(":expansion:compatibility:HuskSync"))
expansion(project(":expansion:compatibility:HuskTowns"))
expansion(project(":expansion:compatibility:iDisguise"))
expansion(project(":expansion:compatibility:IridiumSkyblock"))
expansion(project(":expansion:compatibility:KingdomsX"))
expansion(project(":expansion:compatibility:Konquest"))
expansion(project(":expansion:compatibility:Lands"))
expansion(project(":expansion:compatibility:LibsDisguises"))
expansion(project(":expansion:compatibility:LuckPerms"))
expansion(project(":expansion:compatibility:MarriageMaster"))
expansion(project(":expansion:compatibility:MCPets"))
expansion(project(":expansion:compatibility:MythicMobs"))
expansion(project(":expansion:compatibility:PlaceholderAPI"))
expansion(project(":expansion:compatibility:PlayerParticles"))
expansion(project(":expansion:compatibility:PreciousStones"))
expansion(project(":expansion:compatibility:ProtectionStones"))
expansion(project(":expansion:compatibility:RedProtect"))
expansion(project(":expansion:compatibility:Residence"))
expansion(project(":expansion:compatibility:SuperiorSkyblock"))
expansion(project(":expansion:compatibility:SuperVanish"))
expansion(project(":expansion:compatibility:Towny"))
expansion(project(":expansion:compatibility:UltimateClaims"))
expansion(project(":expansion:compatibility:uSkyBlock"))
expansion(project(":expansion:compatibility:VanishNoPacket"))
expansion(project(path = ":expansion:compatibility:WorldGuard", configuration = "shadow"))
// expansion(project(":expansion:compatibility:ZNPCsPlus"))
}
distributions {
main {
contents {
into("/") {
// README.TXT
from(sourceSets.getByName("main").allSource)
// CombatLogX.jar
from(pluginJar)
// BlueSlimeCore.jar
from(coreJar)
rename("core-2.9-SNAPSHOT.jar", "BlueSlimeCore.jar")
}
into("/CombatLogX/expansions/") {
// All Expansions
from(expansion)
}
}
}
}
tasks {
named("jar") {
enabled = false
}
named("distTar") {
enabled = false
}
named("distZip") {
isPreserveFileTimestamps = true
archiveBaseName.set("CombatLogX-${rootProject.version}")
}
}
================================================
FILE: builder/src/main/resources/README.TXT
================================================
Installation Guide:
1. Download the CombatLogX.zip file from Jenkins or SpigotMC.
2. Extract the contents of the CombatLogX.zip to your PC.
3. Click the stop button on the panel. If your server doesn't use a panel, type "stop" into the console.
4. Upload CombatLogX.jar and BlueSlimeCore.jar to your server /plugins/ folder.
5. Upload the contents of CombatLogX/expansions to your server /plugins/CombatLogX/expansions folder.
6. If the files were uploaded and extracted correctly, your server should have the following files:
File: /plugins/CombatLogX.jar
File /plugins/BlueSlimeCore.jar
Folder: /plugins/CombatLogX/
Folder: /plugins/CombatLogX/expansions/
Multiple Files: /plugins/CombatLogX/expansions/*.jar
7. Delete the CombatLogX.zip file.
8. Restart your server using the panel or your startup script.
9. Edit the configuration files for the main plugin, languages, and expansions.
10. Type the command /clx reload to reload the configuration files.
11. If you want to remove an expansion, delete the jar file from /plugins/CombatLogX/expansions.
Server Shutdown:
- To stop your server properly, click the stop button on the panel.
- If your server is hosted locally or does not have a panel, type 'stop' into the console window.
Server Startup:
- To start your server properly, click the start button on the panel.
- If your server is hosted locally or does not have a panel, execute the start script.
Server Files:
If CombatLogX is installed correctly, your server will have the following files:
- Folder: /plugins
- Folder: /plugins/CombatLogX
- Folder: /plugins/CombatLogX/expansions
- File: /plugins/CombatLogX.jar
- File: /plugins/BlueSlimeCore.jar
- Multiple Files: /plugins/CombatLogX/expansions/*.jar
================================================
FILE: crowdin.yml
================================================
project_id: '459244'
pull_request_title: 'Automatic Crowdin Translation Updates'
files:
- source: "/plugin/src/main/resources/language/en_us.lang.yml"
translation: "/plugin/src/main/resources/language/%locale_with_underscore%.lang.yml"
================================================
FILE: expansion/action-bar/README.MD
================================================
# CombatLogX Expansion: Action Bar
The action bar expansion shows an action bar to every player that is in combat.
## Features
- Customizable action bar message and progress bar.
- Progress bar changes as timer goes down.
## Commands
- **/combatlogx toggle:**
- **/combatlogx toggle actionbar:** Enable or disable your action bar display.
================================================
FILE: expansion/action-bar/gradle.properties
================================================
expansion.name=ActionBar
expansion.prefix=Action Bar
================================================
FILE: expansion/action-bar/src/main/java/combatlogx/expansion/action/bar/ActionBarExpansion.java
================================================
package combatlogx.expansion.action.bar;
import java.util.logging.Logger;
import com.github.sirblobman.api.configuration.ConfigurationManager;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.manager.ITimerManager;
import combatlogx.expansion.action.bar.configuration.ActionBarConfiguration;
public final class ActionBarExpansion extends Expansion {
private final ActionBarConfiguration configuration;
public ActionBarExpansion(ICombatLogX plugin) {
super(plugin);
this.configuration = new ActionBarConfiguration();
}
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("config.yml");
}
@Override
public void onEnable() {
ICombatLogX plugin = getPlugin();
int majorVersion = VersionUtility.getMajorVersion();
int minorVersion = VersionUtility.getMinorVersion();
if (majorVersion == 1 && minorVersion < 8) {
Logger logger = getLogger();
logger.warning("This expansion requires Spigot 1.8.8 or higher.");
selfDisable();
return;
}
reloadConfig();
ITimerManager timerManager = plugin.getTimerManager();
timerManager.addUpdaterTask(new ActionBarUpdater(this));
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("config.yml");
getConfiguration().load(configurationManager.get("config.yml"));
}
ActionBarConfiguration getConfiguration() {
return this.configuration;
}
}
================================================
FILE: expansion/action-bar/src/main/java/combatlogx/expansion/action/bar/ActionBarUpdater.java
================================================
package combatlogx.expansion.action.bar;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.configuration.PlayerDataManager;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.api.utility.Validate;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.manager.IPlaceholderManager;
import com.github.sirblobman.combatlogx.api.object.TagInformation;
import com.github.sirblobman.combatlogx.api.object.TimerUpdater;
import com.github.sirblobman.api.shaded.adventure.text.Component;
import com.github.sirblobman.api.shaded.adventure.text.TextComponent;
import com.github.sirblobman.api.shaded.adventure.text.TextReplacementConfig;
import com.github.sirblobman.api.shaded.adventure.text.format.TextColor;
import combatlogx.expansion.action.bar.configuration.ActionBarConfiguration;
public final class ActionBarUpdater implements TimerUpdater {
private final ActionBarExpansion expansion;
public ActionBarUpdater(ActionBarExpansion expansion) {
this.expansion = Validate.notNull(expansion, "expansion must not be null!");
}
private ActionBarExpansion getExpansion() {
return this.expansion;
}
private ActionBarConfiguration getConfiguration() {
ActionBarExpansion expansion = getExpansion();
return expansion.getConfiguration();
}
private ICombatLogX getCombatLogX() {
ActionBarExpansion expansion = getExpansion();
return expansion.getPlugin();
}
private LanguageManager getLanguageManager() {
ICombatLogX combatLogX = getCombatLogX();
return combatLogX.getLanguageManager();
}
private PlayerDataManager getPlayerDataManager() {
ICombatLogX combatLogX = getCombatLogX();
return combatLogX.getPlayerDataManager();
}
@Override
public void update(Player player, long timeLeftMillis) {
if (isDisabled(player)) {
return;
}
sendActionBar(player, timeLeftMillis);
}
@Override
public void remove(Player player) {
update(player, 0L);
}
private boolean isGlobalEnabled() {
ActionBarConfiguration configuration = getConfiguration();
return configuration.isEnabled();
}
private boolean isDisabled(Player player) {
if (isGlobalEnabled()) {
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration playerData = playerDataManager.get(player);
return !playerData.getBoolean("actionbar", true);
}
return true;
}
private void sendActionBar(Player player, long timeLeftMillis) {
LanguageManager languageManager = getLanguageManager();
if (timeLeftMillis <= 0) {
String path = ("expansion.action-bar.ended");
languageManager.sendActionBar(player, path);
return;
}
ICombatLogX combatLogX = getCombatLogX();
ICombatManager combatManager = combatLogX.getCombatManager();
IPlaceholderManager placeholderManager = combatLogX.getPlaceholderManager();
Component message = languageManager.getMessage(player, "expansion.action-bar.timer");
TextReplacementConfig replacementConfig = getBarsReplacement(player, timeLeftMillis);
message = message.replaceText(replacementConfig);
TagInformation tagInformation = combatManager.getTagInformation(player);
if (tagInformation != null) {
List enemyList = tagInformation.getEnemies();
Pattern placeholderPattern = Pattern.compile("\\{(\\S+)}");
TextReplacementConfig.Builder builder = TextReplacementConfig.builder();
builder.match(placeholderPattern);
builder.replacement((matchResult, builderCopy) -> {
String placeholder = matchResult.group(1);
Component replacement = placeholderManager.getPlaceholderReplacementComponent(player,
enemyList, placeholder);
return (replacement == null ? Component.text(placeholder) : replacement);
});
TextReplacementConfig replacement = builder.build();
message = message.replaceText(replacement);
}
languageManager.sendActionBar(player, message);
}
private TextReplacementConfig getBarsReplacement(Player player, long timeLeftMillis) {
TextReplacementConfig.Builder builder = TextReplacementConfig.builder();
builder.matchLiteral("{bars}");
builder.replacement(getBars(player, timeLeftMillis));
return builder.build();
}
private Component getBars(Player player, long timeLeftMillis) {
ActionBarConfiguration configuration = getConfiguration();
long scale = configuration.getScale();
String leftSymbol = configuration.getLeftSymbol();
String rightSymbol = configuration.getRightSymbol();
TextColor leftColor = configuration.getLeftColor();
TextColor rightColor = configuration.getRightColor();
ICombatLogX plugin = getCombatLogX();
ICombatManager combatManager = plugin.getCombatManager();
long timerMaxSeconds = combatManager.getMaxTimerSeconds(player);
double timerMaxMillis = TimeUnit.SECONDS.toMillis(timerMaxSeconds);
double scaleDouble = (double) scale;
double timeLeftMillisDouble = (double) timeLeftMillis;
double percent = clamp(timeLeftMillisDouble / timerMaxMillis);
long leftBarsCount = Math.round(scaleDouble * percent);
long rightBarsCount = (scale - leftBarsCount);
TextComponent.Builder builder = Component.text();
Component leftSymbolComponent = Component.text(leftSymbol, leftColor);
Component rightSymbolComponent = Component.text(rightSymbol, rightColor);
for (long i = 0; i < leftBarsCount; i++) {
builder.append(leftSymbolComponent);
}
for (long i = 0; i < rightBarsCount; i++) {
builder.append(rightSymbolComponent);
}
return builder.build();
}
private double clamp(double value) {
return Math.max(0.0D, Math.min(value, 1.0D));
}
}
================================================
FILE: expansion/action-bar/src/main/java/combatlogx/expansion/action/bar/configuration/ActionBarConfiguration.java
================================================
package combatlogx.expansion.action.bar.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.configuration.IConfigurable;
import com.github.sirblobman.api.shaded.adventure.text.format.NamedTextColor;
import com.github.sirblobman.api.shaded.adventure.text.format.TextColor;
public final class ActionBarConfiguration implements IConfigurable {
private boolean enabled;
private long scale;
private String leftColorString;
private String rightColorString;
private String leftSymbol;
private String rightSymbol;
private transient TextColor leftColor;
private transient TextColor rightColor;
public ActionBarConfiguration() {
setEnabled(true);
setScale(15L);
setLeftColorString("GREEN");
setRightColorString("RED");
setLeftSymbol("|");
setRightSymbol("|");
}
@Override
public void load(ConfigurationSection config) {
setEnabled(config.getBoolean("enabled", true));
setScale(config.getLong("scale", 15L));
setLeftColorString(config.getString("left-color", "GREEN"));
setRightColorString(config.getString("right-color", "RED"));
setLeftSymbol(config.getString("left-symbol", "|"));
setRightSymbol(config.getString("right-symbol", "|"));
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public long getScale() {
return this.scale;
}
public void setScale(long scale) {
this.scale = scale;
}
public String getLeftColorString() {
return this.leftColorString;
}
public void setLeftColorString(@NotNull String leftColorString) {
this.leftColorString = leftColorString;
this.leftColor = null;
}
public @NotNull String getRightColorString() {
return this.rightColorString;
}
public void setRightColorString(@NotNull String rightColorString) {
this.rightColorString = rightColorString;
this.rightColor = null;
}
public @NotNull String getLeftSymbol() {
return this.leftSymbol;
}
public void setLeftSymbol(@NotNull String leftSymbol) {
this.leftSymbol = leftSymbol;
}
public @NotNull String getRightSymbol() {
return rightSymbol;
}
public void setRightSymbol(@NotNull String rightSymbol) {
this.rightSymbol = rightSymbol;
}
public @NotNull TextColor getLeftColor() {
if (this.leftColor != null) {
return this.leftColor;
}
String leftColorString = getLeftColorString();
return (this.leftColor = parseTextColor(leftColorString, NamedTextColor.GREEN));
}
public @NotNull TextColor getRightColor() {
if (this.rightColor != null) {
return this.rightColor;
}
String rightColorString = getRightColorString();
return (this.rightColor = parseTextColor(rightColorString, NamedTextColor.RED));
}
private @NotNull TextColor parseTextColor(@NotNull String colorString, @NotNull TextColor defaultColor) {
if (colorString.isEmpty()) {
return defaultColor;
}
if (colorString.startsWith("#") && colorString.length() == 7) {
try {
String colorHex = colorString.substring(1);
int colorInt = Integer.parseInt(colorHex, 16);
return TextColor.color(colorInt);
} catch (IllegalArgumentException ex) {
return defaultColor;
}
}
NamedTextColor namedTextColor = NamedTextColor.NAMES.value(colorString);
return (namedTextColor != null ? namedTextColor : defaultColor);
}
}
================================================
FILE: expansion/action-bar/src/main/resources/config.yml
================================================
# This option is here to quickly toggle this expansion on a live server that must stay online.
# We recommend that you remove the Action Bar expansion jar if you will not use the feature.
enabled: true
# Scale is the amount of symbols for the {bars} placeholder.
scale: 15
# Left Color is the color code for the left part of the {bars} placeholder.
# A named color must be selected, or you can use the hex value.
# You can find a list of official color names at the bottom of this file.
# Example: "GREEN"
# Example 2: "#00FF00"
left-color: "GREEN"
# Left Symbol is the symbol used for the left part of the {bars} placeholder
# Unicode is supported, but must be converted.
# Example: "\u00A7"
# Default: "|"
left-symbol: "|"
# Right Color is the color code for the right part of the {bars} placeholder.
# A named color must be selected, or you can use the hex value.
# You can find a list of official color names at the bottom of this file.
# Example: "RED"
# Example 2: "#FF0000"
right-color: "RED"
# Right Symbol is the symbol used for the right part of the {bars} placeholder
# Unicode is supported, but must be converted.
# Example: "\u00A7"
# Default: "|"
right-symbol: "|"
## Reminder:
## The action bar format is in your selected language file
## (Default: en_us.lang.yml)
## Adventure NamedTextColor Value Map
## Legacy Color Code : Named Color
# &0 : BLACK
# &1 : DARK_BLUE
# &2 : DARK_GREEN
# &3 : DARK_AQUA
# &4 : DARK_RED
# &5 : DARK_PURPLE
# &6 : GOLD
# &7 : GRAY
# &8 : DARK_GRAY
# &9 : BLUE
# &a : GREEN
# &b : AQUA
# &c : RED
# &d : LIGHT_PURPLE
# &e : YELLOW
# &f : WHITE
================================================
FILE: expansion/action-bar/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.action.bar.ActionBarExpansion"
version: "17.4"
author: "SirBlobman"
================================================
FILE: expansion/boss-bar/README.MD
================================================
# CombatLogX Expansion: Boss Bar
The boss bar expansion shows a boss bar to every player that is in combat.
## Features
- Customizable bar color and style.
- Customizable boss bar message.
- Boss Bar health changes as timer goes down.
## Commands
- **/combatlogx toggle:**
- **/combatlogx toggle bossbar:** Enable or disable your boss bar display.
================================================
FILE: expansion/boss-bar/gradle.properties
================================================
expansion.name=BossBar
expansion.prefix=Boss Bar
================================================
FILE: expansion/boss-bar/src/main/java/combatlogx/expansion/boss/bar/BossBarConfiguration.java
================================================
package combatlogx.expansion.boss.bar;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.configuration.IConfigurable;
import com.github.sirblobman.api.shaded.adventure.bossbar.BossBar;
import com.github.sirblobman.api.shaded.adventure.text.format.NamedTextColor;
import com.github.sirblobman.api.shaded.adventure.text.format.TextColor;
public final class BossBarConfiguration implements IConfigurable {
private boolean enabled;
private String bossBarColorName;
private String bossBarStyleName;
private long scale;
private String leftColorString;
private String rightColorString;
private String leftSymbol;
private String rightSymbol;
private transient BossBar.Color bossBarColor;
private transient BossBar.Overlay bossBarStyle;
private transient TextColor leftColor;
private transient TextColor rightColor;
public BossBarConfiguration() {
setEnabled(true);
setBossBarColorName("YELLOW");
setBossBarStyleName("PROGRESS");
setScale(15L);
setLeftColorString("GREEN");
setRightColorString("RED");
setLeftSymbol("|");
setRightSymbol("|");
}
@Override
public void load(ConfigurationSection config) {
setEnabled(config.getBoolean("enabled", true));
setBossBarColorName(config.getString("bar-color", "YELLOW"));
setBossBarStyleName(config.getString("bar-style", "PROGRESS"));
setScale(config.getLong("scale", 15L));
setLeftColorString(config.getString("left-color", "GREEN"));
setRightColorString(config.getString("right-color", "RED"));
setLeftSymbol(config.getString("left-symbol", "|"));
setRightSymbol(config.getString("right-symbol", "|"));
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public long getScale() {
return scale;
}
public void setScale(long scale) {
this.scale = scale;
}
public String getLeftColorString() {
return leftColorString;
}
public void setLeftColorString(String leftColorString) {
this.leftColorString = leftColorString;
this.leftColor = null;
}
public String getRightColorString() {
return rightColorString;
}
public void setRightColorString(String rightColorString) {
this.rightColorString = rightColorString;
this.rightColor = null;
}
public String getLeftSymbol() {
return leftSymbol;
}
public void setLeftSymbol(String leftSymbol) {
this.leftSymbol = leftSymbol;
}
public String getRightSymbol() {
return rightSymbol;
}
public void setRightSymbol(String rightSymbol) {
this.rightSymbol = rightSymbol;
}
@NotNull
public TextColor getLeftColor() {
if (this.leftColor != null) {
return this.leftColor;
}
String leftColorString = getLeftColorString();
return (this.leftColor = parseTextColor(leftColorString, NamedTextColor.GREEN));
}
@NotNull
public TextColor getRightColor() {
if (this.rightColor != null) {
return this.rightColor;
}
String rightColorString = getRightColorString();
return (this.rightColor = parseTextColor(rightColorString, NamedTextColor.RED));
}
@NotNull
private TextColor parseTextColor(String colorString, TextColor defaultColor) {
if (colorString == null || colorString.isEmpty()) {
return defaultColor;
}
if (colorString.startsWith("#") && colorString.length() == 7) {
try {
String colorHex = colorString.substring(1);
int colorInt = Integer.parseInt(colorHex, 16);
return TextColor.color(colorInt);
} catch (IllegalArgumentException ex) {
return defaultColor;
}
}
NamedTextColor namedTextColor = NamedTextColor.NAMES.value(colorString);
return (namedTextColor != null ? namedTextColor : defaultColor);
}
public String getBossBarColorName() {
return bossBarColorName;
}
public void setBossBarColorName(String bossBarColorName) {
this.bossBarColorName = bossBarColorName;
this.bossBarColor = null;
}
public String getBossBarStyleName() {
return bossBarStyleName;
}
public void setBossBarStyleName(String bossBarStyleName) {
this.bossBarStyleName = bossBarStyleName;
this.bossBarStyle = null;
}
@NotNull
public BossBar.Color getBossBarColor() {
if (this.bossBarColor != null) {
return this.bossBarColor;
}
String bossBarColorName = getBossBarColorName();
return (this.bossBarColor = parseBossBarColor(bossBarColorName));
}
@NotNull
public BossBar.Overlay getBossBarStyle() {
if (this.bossBarStyle != null) {
return this.bossBarStyle;
}
String bossBarStyleName = getBossBarStyleName();
return (this.bossBarStyle = parseBossBarStyle(bossBarStyleName));
}
private BossBar.Color parseBossBarColor(String name) {
if (name == null || name.isEmpty()) {
return BossBar.Color.YELLOW;
}
try {
return BossBar.Color.valueOf(name);
} catch (IllegalArgumentException ex) {
return BossBar.Color.YELLOW;
}
}
private BossBar.Overlay parseBossBarStyle(String name) {
if (name == null || name.isEmpty()) {
return BossBar.Overlay.PROGRESS;
}
try {
return BossBar.Overlay.valueOf(name);
} catch (IllegalArgumentException ex) {
return BossBar.Overlay.PROGRESS;
}
}
}
================================================
FILE: expansion/boss-bar/src/main/java/combatlogx/expansion/boss/bar/BossBarExpansion.java
================================================
package combatlogx.expansion.boss.bar;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.file.YamlConfiguration;
import com.github.sirblobman.api.configuration.ConfigurationManager;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.manager.ITimerManager;
public final class BossBarExpansion extends Expansion {
private final BossBarConfiguration configuration;
public BossBarExpansion(ICombatLogX plugin) {
super(plugin);
this.configuration = new BossBarConfiguration();
}
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("config.yml");
}
@Override
public void onEnable() {
reloadConfig();
ITimerManager timerManager = getTimerManager();
timerManager.addUpdaterTask(new BossBarUpdater(this));
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("config.yml");
BossBarConfiguration configuration = getConfiguration();
YamlConfiguration yamlConfiguration = configurationManager.get("config.yml");
configuration.load(yamlConfiguration);
}
public @NotNull BossBarConfiguration getConfiguration() {
return this.configuration;
}
private @NotNull ITimerManager getTimerManager() {
ICombatLogX plugin = getPlugin();
return plugin.getTimerManager();
}
}
================================================
FILE: expansion/boss-bar/src/main/java/combatlogx/expansion/boss/bar/BossBarUpdater.java
================================================
package combatlogx.expansion.boss.bar;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.configuration.PlayerDataManager;
import com.github.sirblobman.api.folia.FoliaHelper;
import com.github.sirblobman.api.folia.details.EntityTaskDetails;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.api.plugin.ConfigurablePlugin;
import com.github.sirblobman.api.utility.Validate;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.manager.IPlaceholderManager;
import com.github.sirblobman.combatlogx.api.object.TagInformation;
import com.github.sirblobman.combatlogx.api.object.TimerUpdater;
import com.github.sirblobman.api.shaded.adventure.audience.Audience;
import com.github.sirblobman.api.shaded.adventure.bossbar.BossBar;
import com.github.sirblobman.api.shaded.adventure.bossbar.BossBar.Color;
import com.github.sirblobman.api.shaded.adventure.bossbar.BossBar.Overlay;
import com.github.sirblobman.api.shaded.adventure.text.Component;
import com.github.sirblobman.api.shaded.adventure.text.TextComponent;
import com.github.sirblobman.api.shaded.adventure.text.TextReplacementConfig;
import com.github.sirblobman.api.shaded.adventure.text.format.TextColor;
public final class BossBarUpdater implements TimerUpdater {
private final BossBarExpansion expansion;
private final Map bossBarMap;
public BossBarUpdater(BossBarExpansion expansion) {
this.expansion = Validate.notNull(expansion, "expansion must not be null!");
this.bossBarMap = new ConcurrentHashMap<>();
}
@Override
public void update(@NotNull Player player, long timeLeftMillis) {
if (isDisabled(player)) {
actualRemove(player);
return;
}
Component title = getTitle(player, timeLeftMillis);
if (Component.empty().equals(title)) {
actualRemove(player);
return;
}
float progress = getProgress(player, timeLeftMillis);
BossBar.Color color = getBossBarColor();
BossBar.Overlay overlay = getBossBarOverlay();
BossBar bossBar = getBossBar(player, true);
bossBar.progress(progress);
bossBar.color(color);
bossBar.overlay(overlay);
bossBar.name(title);
Audience audience = getAudience(player);
audience.showBossBar(bossBar);
}
@Override
public void remove(@NotNull Player player) {
update(player, 0L);
ICombatLogX combatLogX = getCombatLogX();
ConfigurablePlugin plugin = combatLogX.getPlugin();
if (!plugin.isEnabled()) {
return;
}
FoliaHelper foliaHelper = combatLogX.getFoliaHelper();
TaskScheduler scheduler = foliaHelper.getScheduler();
scheduler.scheduleEntityTask(new EntityTaskDetails(plugin, player) {
@Override
public void run() {
Player player = getEntity();
if (player != null) {
actualRemove(player);
}
}
});
}
private BossBarExpansion getExpansion() {
return this.expansion;
}
private ICombatLogX getCombatLogX() {
BossBarExpansion expansion = getExpansion();
return expansion.getPlugin();
}
private LanguageManager getLanguageManager() {
ICombatLogX combatLogX = getCombatLogX();
return combatLogX.getLanguageManager();
}
private PlayerDataManager getPlayerDataManager() {
ICombatLogX combatLogX = getCombatLogX();
return combatLogX.getPlayerDataManager();
}
private ICombatManager getCombatManager() {
ICombatLogX combatLogX = getCombatLogX();
return combatLogX.getCombatManager();
}
private boolean isGlobalEnabled() {
BossBarConfiguration configuration = getConfiguration();
return configuration.isEnabled();
}
private boolean isDisabled(Player player) {
if (isGlobalEnabled()) {
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration playerData = playerDataManager.get(player);
return !playerData.getBoolean("bossbar", true);
}
return true;
}
@Contract("_, true -> !null")
private BossBar getBossBar(Player player, boolean create) {
UUID playerId = player.getUniqueId();
if (this.bossBarMap.containsKey(playerId)) {
return this.bossBarMap.get(playerId);
}
if (create) {
Component defaultTitle = Component.text("Default Title");
BossBar defaultBossBar = BossBar.bossBar(defaultTitle, 1.0F, Color.PURPLE, Overlay.PROGRESS);
this.bossBarMap.put(playerId, defaultBossBar);
return defaultBossBar;
}
return null;
}
private Audience getAudience(Player player) {
LanguageManager languageManager = getLanguageManager();
return languageManager.getAudience(player);
}
private void actualRemove(Player player) {
BossBar bossBar = getBossBar(player, false);
if (bossBar == null) {
return;
}
Audience audience = getAudience(player);
audience.hideBossBar(bossBar);
UUID playerId = player.getUniqueId();
this.bossBarMap.remove(playerId);
}
private Color getBossBarColor() {
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion < 9) {
return Color.PURPLE;
}
BossBarConfiguration configuration = getConfiguration();
return configuration.getBossBarColor();
}
private Overlay getBossBarOverlay() {
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion < 9) {
return Overlay.PROGRESS;
}
BossBarConfiguration configuration = getConfiguration();
return configuration.getBossBarStyle();
}
private float getProgress(Player player, float timeLeftMillis) {
ICombatManager combatManager = getCombatManager();
long timerMaxSeconds = combatManager.getMaxTimerSeconds(player);
float timerMaxMillis = TimeUnit.SECONDS.toMillis(timerMaxSeconds);
float barPercentage = (timeLeftMillis / timerMaxMillis);
if (barPercentage <= 0.0F) {
return 0.0F;
}
return Math.min(barPercentage, 1.0F);
}
private Component getTitle(Player player, long timeLeftMillis) {
LanguageManager languageManager = getLanguageManager();
if (timeLeftMillis <= 0) {
String path = ("expansion.boss-bar.ended");
return languageManager.getMessage(player, path);
}
ICombatLogX combatLogX = getCombatLogX();
ICombatManager combatManager = combatLogX.getCombatManager();
IPlaceholderManager placeholderManager = combatLogX.getPlaceholderManager();
Component message = languageManager.getMessage(player, "expansion.boss-bar.timer");
TextReplacementConfig replacementConfig = getBarsReplacement(player, timeLeftMillis);
message = message.replaceText(replacementConfig);
TagInformation tagInformation = combatManager.getTagInformation(player);
if (tagInformation != null) {
List enemyList = tagInformation.getEnemies();
Pattern placeholderPattern = Pattern.compile("\\{(\\S+)}");
TextReplacementConfig.Builder builder = TextReplacementConfig.builder();
builder.match(placeholderPattern);
builder.replacement((matchResult, builderCopy) -> {
String placeholder = matchResult.group(1);
Component replacement = placeholderManager.getPlaceholderReplacementComponent(player,
enemyList, placeholder);
return (replacement == null ? Component.text(placeholder) : replacement);
});
TextReplacementConfig replacement = builder.build();
message = message.replaceText(replacement);
}
return message;
}
private TextReplacementConfig getBarsReplacement(Player player, long timeLeftMillis) {
TextReplacementConfig.Builder builder = TextReplacementConfig.builder();
builder.matchLiteral("{bars}");
builder.replacement(getBars(player, timeLeftMillis));
return builder.build();
}
private BossBarConfiguration getConfiguration() {
BossBarExpansion expansion = getExpansion();
return expansion.getConfiguration();
}
private Component getBars(Player player, long timeLeftMillis) {
BossBarConfiguration configuration = getConfiguration();
long scale = configuration.getScale();
String leftSymbol = configuration.getLeftSymbol();
String rightSymbol = configuration.getRightSymbol();
TextColor leftColor = configuration.getLeftColor();
TextColor rightColor = configuration.getRightColor();
ICombatLogX plugin = getCombatLogX();
ICombatManager combatManager = plugin.getCombatManager();
long timerMaxSeconds = combatManager.getMaxTimerSeconds(player);
double timerMaxMillis = TimeUnit.SECONDS.toMillis(timerMaxSeconds);
double scaleDouble = (double) scale;
double timeLeftMillisDouble = (double) timeLeftMillis;
double percent = clamp(timeLeftMillisDouble / timerMaxMillis);
long leftBarsCount = Math.round(scaleDouble * percent);
long rightBarsCount = (scale - leftBarsCount);
TextComponent.Builder builder = Component.text();
Component leftSymbolComponent = Component.text(leftSymbol, leftColor);
Component rightSymbolComponent = Component.text(rightSymbol, rightColor);
for (long i = 0; i < leftBarsCount; i++) {
builder.append(leftSymbolComponent);
}
for (long i = 0; i < rightBarsCount; i++) {
builder.append(rightSymbolComponent);
}
return builder.build();
}
private double clamp(double value) {
return Math.max(0.0D, Math.min(value, 1.0D));
}
}
================================================
FILE: expansion/boss-bar/src/main/resources/config.yml
================================================
# This option is here to quickly toggle this expansion on a live server that must stay online.
# We recommend that you remove the Boss Bar expansion jar if you will not use the feature.
enabled: true
# You can find a list of colors here:
# https://jd.adventure.kyori.net/api/4.11.0/net/kyori/adventure/bossbar/BossBar.Color.html
bar-color: YELLOW
# You can find a list of styles here:
# https://jd.adventure.kyori.net/api/4.11.0/net/kyori/adventure/bossbar/BossBar.Overlay.html
bar-style: PROGRESS
# Scale is the amount of symbols for the {bars} placeholder.
scale: 15
# Left Color is the color code for the left part of the {bars} placeholder.
# A named color must be selected, or you can use the hex value.
# You can find a list of official color names at the bottom of this file.
# Example: "GREEN"
# Example 2: "#00FF00"
left-color: "GREEN"
# Left Symbol is the symbol used for the left part of the {bars} placeholder
# Unicode is supported, but must be converted.
# Example: "\u00A7"
# Default: "|"
left-symbol: "|"
# Right Color is the color code for the right part of the {bars} placeholder.
# A named color must be selected, or you can use the hex value.
# You can find a list of official color names at the bottom of this file.
# Example: "RED"
# Example 2: "#FF0000"
right-color: "RED"
# Right Symbol is the symbol used for the right part of the {bars} placeholder
# Unicode is supported, but must be converted.
# Example: "\u00A7"
# Default: "|"
right-symbol: "|"
## Reminder:
## The boss bar format is in your selected language file
## (Default: en_us.lang.yml)
## Adventure NamedTextColor Value Map
## Legacy Color Code : Named Color
# &0 : BLACK
# &1 : DARK_BLUE
# &2 : DARK_GREEN
# &3 : DARK_AQUA
# &4 : DARK_RED
# &5 : DARK_PURPLE
# &6 : GOLD
# &7 : GRAY
# &8 : DARK_GRAY
# &9 : BLUE
# &a : GREEN
# &b : AQUA
# &c : RED
# &d : LIGHT_PURPLE
# &e : YELLOW
# &f : WHITE
## Extra Information:
## Color and Style are only available in 1.9 or higher.
## 1.8 and below will always be PURPLE and PROGRESS.
## Reminder:
## The boss bar format is in your selected language file
## (Default: en_us.lang.yml)
================================================
FILE: expansion/boss-bar/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.boss.bar.BossBarExpansion"
version: "17.1"
author: "SirBlobman"
================================================
FILE: expansion/build.gradle.kts
================================================
tasks.named("jar") {
enabled = false
}
subprojects {
val expansionName = findProperty("expansion.name") ?: "invalid"
val expansionPrefix = findProperty("expansion.prefix") ?: expansionName
dependencies {
compileOnly(project(":api"))
}
tasks {
named("jar") {
archiveFileName.set("$expansionPrefix.jar")
}
processResources {
val expansionDescription = findProperty("expansion.description") ?: ""
filesMatching("expansion.yml") {
expand(
mapOf(
"expansionName" to expansionName,
"expansionPrefix" to expansionPrefix,
"expansionDescription" to expansionDescription
)
)
}
}
}
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/ICheatPreventionExpansion.java
================================================
package combatlogx.expansion.cheat.prevention;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.cheat.prevention.configuration.IBlockConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IBucketConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IChatConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ICommandConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IEntityConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IFlightConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IGameModeConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IInventoryConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IPotionConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ITeleportConfiguration;
public interface ICheatPreventionExpansion {
@NotNull Expansion getExpansion();
@NotNull IConfiguration getConfiguration();
@NotNull IBlockConfiguration getBlockConfiguration();
@NotNull IBucketConfiguration getBucketConfiguration();
@NotNull IChatConfiguration getChatConfiguration();
@NotNull ICommandConfiguration getCommandConfiguration();
@NotNull IEntityConfiguration getEntityConfiguration();
@NotNull IFlightConfiguration getFlightConfiguration();
@NotNull IGameModeConfiguration getGameModeConfiguration();
@NotNull IInventoryConfiguration getInventoryConfiguration();
@NotNull IItemConfiguration getItemConfiguration();
@NotNull IPotionConfiguration getPotionConfiguration();
@NotNull ITeleportConfiguration getTeleportConfiguration();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IBlockConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.api.configuration.IConfigurable;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
public interface IBlockConfiguration extends IConfigurable {
boolean isPreventInteraction();
boolean isPreventBreaking();
boolean isPreventPlacing();
boolean isPreventPortalCreation();
boolean isPreventInteraction(@NotNull XMaterial blockType);
boolean isPreventBreaking(@NotNull XMaterial blockType);
boolean isPreventPlacing(@NotNull XMaterial blockType);
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IBucketConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.api.configuration.IConfigurable;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
public interface IBucketConfiguration extends IConfigurable {
boolean isPreventBucketEmpty();
boolean isPreventBucketFill();
boolean isPreventEmpty(@NotNull XMaterial material);
boolean isPreventFill(@NotNull XMaterial material);
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IChatConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IChatConfiguration extends IConfigurable {
boolean isDisableChat();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/ICommandConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.permissions.Permission;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface ICommandConfiguration extends IConfigurable {
int getDelayAfterCombat();
boolean isBlocked(@NotNull String command);
boolean isAllowed(@NotNull String command);
@Nullable Permission getBypassPermission();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IConfiguration extends IConfigurable {
int getMessageCooldown();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IEntityConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IEntityConfiguration extends IConfigurable {
boolean isPreventInteraction();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IFlightConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IFlightConfiguration extends IConfigurable {
boolean isPreventFlying();
boolean isPreventFallDamage();
boolean isForceDisableFlight();
boolean isFlightRetag();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IGameModeConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.GameMode;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IGameModeConfiguration extends IConfigurable {
boolean isPreventSwitching();
boolean isUntagOnSwitch();
boolean isForceSwitch();
GameMode getForceMode();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IInventoryConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.event.inventory.InventoryType;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IInventoryConfiguration extends IConfigurable {
boolean isClose();
boolean isCloseOnRetag();
boolean isPreventOpening();
boolean isNoMessage(@NotNull InventoryType type);
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IItemConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IItemConfiguration extends IConfigurable {
boolean isPreventDrop();
boolean isPreventPickup();
boolean isPreventElytra();
boolean isForcePreventElytra();
boolean isPreventFireworks();
boolean isElytraRetag();
boolean isPreventTotem();
boolean isPreventRiptide();
boolean isRiptideRetag();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/IPotionConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.potion.PotionEffectType;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface IPotionConfiguration extends IConfigurable {
boolean isBlocked(@NotNull PotionEffectType effectType);
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/configuration/ITeleportConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.github.sirblobman.api.configuration.IConfigurable;
public interface ITeleportConfiguration extends IConfigurable {
boolean isPreventPortals();
boolean isPreventTeleportation();
boolean isEnderPearlRetag();
boolean isUntag();
boolean isAllowed(@NotNull TeleportCause cause);
boolean isForceDisableEnderPearl();
}
================================================
FILE: expansion/cheat-prevention/abstract/src/main/java/combatlogx/expansion/cheat/prevention/listener/CheatPreventionListener.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.api.language.replacer.Replacer;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IConfiguration;
public abstract class CheatPreventionListener extends ExpansionListener {
private final ICheatPreventionExpansion expansion;
private final Map> messageCooldownMap;
public CheatPreventionListener(@NotNull ICheatPreventionExpansion expansion) {
super(expansion.getExpansion());
this.expansion = expansion;
this.messageCooldownMap = new ConcurrentHashMap<>();
}
protected final @NotNull ICheatPreventionExpansion getCheatPrevention() {
return this.expansion;
}
protected final void sendMessageIgnoreCooldown(@NotNull Player player, @NotNull String key,
Replacer @NotNull ... replacer) {
LanguageManager languageManager = getLanguageManager();
languageManager.sendMessageWithPrefix(player, key, replacer);
addMessageCooldown(player, key);
}
protected final void sendMessage(@NotNull Player player, @NotNull String key, Replacer @NotNull ... replacer) {
long systemMillis = System.currentTimeMillis();
long expireMillis = getCooldownExpireTime(player, key);
if (systemMillis < expireMillis) {
return;
}
sendMessageIgnoreCooldown(player, key, replacer);
}
private long getNewMessageCooldownExpireTime() {
ICheatPreventionExpansion cheatPrevention = getCheatPrevention();
IConfiguration configuration = cheatPrevention.getConfiguration();
long cooldownSeconds = configuration.getMessageCooldown();
long cooldownMillis = TimeUnit.SECONDS.toMillis(cooldownSeconds);
long systemMillis = System.currentTimeMillis();
return (systemMillis + cooldownMillis);
}
private long getCooldownExpireTime(Player player, String key) {
UUID playerId = player.getUniqueId();
Map expireTimeMap = this.messageCooldownMap.getOrDefault(playerId, new HashMap<>());
return expireTimeMap.getOrDefault(key, 0L);
}
private void addMessageCooldown(Player player, String key) {
UUID playerId = player.getUniqueId();
Map expireTimeMap = this.messageCooldownMap.getOrDefault(playerId, new HashMap<>());
expireTimeMap.put(key, getNewMessageCooldownExpireTime());
this.messageCooldownMap.put(playerId, expireTimeMap);
}
}
================================================
FILE: expansion/cheat-prevention/build.gradle.kts
================================================
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("com.gradleup.shadow") version "9.2.2"
}
dependencies {
implementation(project(":expansion:cheat-prevention:abstract"))
implementation(project(":expansion:cheat-prevention:legacy"))
implementation(project(":expansion:cheat-prevention:paper"))
implementation(project(path = ":expansion:cheat-prevention:modern", configuration = "default"))
}
tasks {
named("jar") {
enabled = false
}
named("shadowJar") {
val expansionName = findProperty("expansion.name") ?: "invalid"
val expansionPrefix = findProperty("expansion.prefix") ?: expansionName
archiveFileName.set("$expansionPrefix.jar")
archiveClassifier.set(null as String?)
}
named("build") {
dependsOn("shadowJar")
}
}
================================================
FILE: expansion/cheat-prevention/gradle.properties
================================================
version.spigot=1.16.5-R0.1-SNAPSHOT
expansion.name=CheatPrevention
expansion.prefix=Cheat Prevention
================================================
FILE: expansion/cheat-prevention/legacy/build.gradle.kts
================================================
dependencies {
compileOnly(project(":expansion:cheat-prevention:abstract"))
}
================================================
FILE: expansion/cheat-prevention/legacy/gradle.properties
================================================
version.spigot=1.8.8-R0.1-SNAPSHOT
================================================
FILE: expansion/cheat-prevention/legacy/src/main/java/combatlogx/expansion/cheat/prevention/listener/legacy/ListenerChat.java
================================================
package combatlogx.expansion.cheat.prevention.listener.legacy;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IChatConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerChat extends CheatPreventionListener {
public ListenerChat(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent e) {
if (isChatDisabled()) {
Player player = e.getPlayer();
if (!isInCombat(player)) {
return;
}
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.no-chat");
}
}
private @NotNull IChatConfiguration getChatConfiguration() {
ICheatPreventionExpansion cheatPrevention = getCheatPrevention();
return cheatPrevention.getChatConfiguration();
}
private boolean isChatDisabled() {
IChatConfiguration chatConfiguration = getChatConfiguration();
return chatConfiguration.isDisableChat();
}
}
================================================
FILE: expansion/cheat-prevention/legacy/src/main/java/combatlogx/expansion/cheat/prevention/listener/legacy/ListenerLegacyItemPickup.java
================================================
package combatlogx.expansion.cheat.prevention.listener.legacy;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerPickupItemEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerLegacyItemPickup extends CheatPreventionListener {
public ListenerLegacyItemPickup(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPickup(PlayerPickupItemEvent e) {
if (isPreventPickup()) {
Player player = e.getPlayer();
if (!isInCombat(player)) {
return;
}
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.items.no-pickup");
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventPickup() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isPreventPickup();
}
}
================================================
FILE: expansion/cheat-prevention/legacy/src/main/java/combatlogx/expansion/cheat/prevention/listener/legacy/ListenerLegacyPortalCreate.java
================================================
package combatlogx.expansion.cheat.prevention.listener.legacy;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityCreatePortalEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IBlockConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerLegacyPortalCreate extends CheatPreventionListener {
public ListenerLegacyPortalCreate(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPortalCreate(EntityCreatePortalEvent e) {
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
if (isPreventPortalCreation() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-portal-creation");
}
}
private @NotNull IBlockConfiguration getBlockConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getBlockConfiguration();
}
private boolean isPreventPortalCreation() {
IBlockConfiguration configuration = getBlockConfiguration();
return configuration.isPreventPortalCreation();
}
}
================================================
FILE: expansion/cheat-prevention/legacy/src/main/java/combatlogx/expansion/cheat/prevention/listener/legacy/ListenerLegacyPotions.java
================================================
package combatlogx.expansion.cheat.prevention.listener.legacy;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IPotionConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerLegacyPotions extends CheatPreventionListener {
public ListenerLegacyPotions(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
Player player = e.getPlayer();
Collection activePotionEffectCollection = player.getActivePotionEffects();
for (PotionEffect potionEffect : activePotionEffectCollection) {
PotionEffectType potionEffectType = potionEffect.getType();
if (isBlocked(potionEffectType)) {
player.removePotionEffect(potionEffectType);
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSplash(PotionSplashEvent e) {
ThrownPotion thrownPotion = e.getPotion();
Collection potionEffectCollection = thrownPotion.getEffects();
Collection affectedEntityCollection = e.getAffectedEntities();
for (LivingEntity affectedEntity : affectedEntityCollection) {
if (!(affectedEntity instanceof Player)) {
continue;
}
Player player = (Player) affectedEntity;
if (!isInCombat(player)) {
continue;
}
for (PotionEffect potionEffect : potionEffectCollection) {
PotionEffectType potionEffectType = potionEffect.getType();
if (!isBlocked(potionEffectType)) {
continue;
}
e.setIntensity(player, 0);
break;
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPotionConsume(PlayerItemConsumeEvent e) {
Player player = e.getPlayer();
if (!isInCombat(player)) {
return;
}
ItemStack item = e.getItem();
XMaterial material = XMaterial.matchXMaterial(item);
if (material != XMaterial.POTION) {
return;
}
Potion potion = Potion.fromItemStack(item);
Collection potionEffectCollection = potion.getEffects();
for (PotionEffect potionEffect : potionEffectCollection) {
PotionEffectType potionEffectType = potionEffect.getType();
if (isBlocked(potionEffectType)) {
e.setCancelled(true);
return;
}
}
}
private @NotNull IPotionConfiguration getPotionConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getPotionConfiguration();
}
private boolean isBlocked(@NotNull PotionEffectType effectType) {
IPotionConfiguration potionConfiguration = getPotionConfiguration();
return potionConfiguration.isBlocked(effectType);
}
}
================================================
FILE: expansion/cheat-prevention/modern/build.gradle.kts
================================================
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
compileOnly(project(":expansion:cheat-prevention:abstract"))
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
}
================================================
FILE: expansion/cheat-prevention/modern/gradle.properties
================================================
version.spigot=1.21.1-R0.1-SNAPSHOT
================================================
FILE: expansion/cheat-prevention/modern/src/main/java/combatlogx/expansion/cheat/prevention/listener/modern/ListenerInventoriesModern.java
================================================
package combatlogx.expansion.cheat.prevention.listener.modern;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IInventoryConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
// 1.20.6 use a InventoryView interface instead of an abstract class
// No code difference, only compilation difference.
public final class ListenerInventoriesModern extends CheatPreventionListener {
public ListenerInventoriesModern(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
if (isClose()) {
Player player = e.getPlayer();
InventoryView openView = player.getOpenInventory();
InventoryType viewType = openView.getType();
player.closeInventory();
if (isMessage(viewType)) {
sendMessage(player, "expansion.cheat-prevention.inventory.force-closed");
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onReTag(PlayerReTagEvent e) {
if (isCloseOnRetag()) {
Player player = e.getPlayer();
InventoryView openView = player.getOpenInventory();
InventoryType viewType = openView.getType();
player.closeInventory();
if (isMessage(viewType)) {
sendMessage(player, "expansion.cheat-prevention.inventory.force-closed");
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onOpen(InventoryOpenEvent e) {
HumanEntity human = e.getPlayer();
if (!(human instanceof Player)) {
return;
}
Player player = (Player) human;
if (isPreventOpening() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.inventory.no-opening");
}
}
private @NotNull IInventoryConfiguration getInventoryConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getInventoryConfiguration();
}
private boolean isClose() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isClose();
}
private boolean isCloseOnRetag() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isCloseOnRetag();
}
private boolean isPreventOpening() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isPreventOpening();
}
private boolean isMessage(@NotNull InventoryType type) {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return !inventoryConfiguration.isNoMessage(type);
}
}
================================================
FILE: expansion/cheat-prevention/paper/build.gradle.kts
================================================
repositories {
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
val spigotVersion = property("version.spigot") as String
compileOnly("com.destroystokyo.paper:paper-api:$spigotVersion")
compileOnly(project(":expansion:cheat-prevention:abstract"))
}
================================================
FILE: expansion/cheat-prevention/paper/gradle.properties
================================================
version.spigot=1.16.5-R0.1-SNAPSHOT
================================================
FILE: expansion/cheat-prevention/paper/src/main/java/combatlogx/expansion/cheat/prevention/listener/paper/ListenerPaperChat.java
================================================
package combatlogx.expansion.cheat.prevention.listener.paper;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import io.papermc.paper.event.player.AsyncChatEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IChatConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerPaperChat extends CheatPreventionListener {
public ListenerPaperChat(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onChat(AsyncChatEvent e) {
Player player = e.getPlayer();
if (isChatDisabled() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.no-chat");
}
}
private @NotNull IChatConfiguration getChatConfiguration() {
ICheatPreventionExpansion cheatPrevention = getCheatPrevention();
return cheatPrevention.getChatConfiguration();
}
private boolean isChatDisabled() {
IChatConfiguration chatConfiguration = getChatConfiguration();
return chatConfiguration.isDisableChat();
}
}
================================================
FILE: expansion/cheat-prevention/paper/src/main/java/combatlogx/expansion/cheat/prevention/listener/paper/ListenerPaperEntityInsideBlock.java
================================================
package combatlogx.expansion.cheat.prevention.listener.paper;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import io.papermc.paper.event.entity.EntityInsideBlockEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.ITeleportConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerPaperEntityInsideBlock extends CheatPreventionListener {
public ListenerPaperEntityInsideBlock(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityInsideBlock(EntityInsideBlockEvent e) {
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
if (isPreventPortals() && isInCombat(player)) {
check(player, e);
}
}
private void check(@NotNull Player player, @NotNull EntityInsideBlockEvent e) {
Block block = e.getBlock();
Material blockType = block.getType();
if (blockType != Material.END_PORTAL && blockType != Material.NETHER_PORTAL
&& blockType != Material.END_GATEWAY) {
return;
}
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.teleportation.block-portal");
}
private @NotNull ITeleportConfiguration getTeleportationConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getTeleportConfiguration();
}
private boolean isPreventPortals() {
ITeleportConfiguration teleportationConfiguration = getTeleportationConfiguration();
return teleportationConfiguration.isPreventPortals();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/CheatPreventionExpansion.java
================================================
package combatlogx.expansion.cheat.prevention;
import java.util.logging.Logger;
import combatlogx.expansion.cheat.prevention.listener.*;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.api.configuration.ConfigurationManager;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.cheat.prevention.configuration.BlockConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.BucketConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ChatConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.CheatPreventionConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.CommandConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.EntityConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.FlightConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.GameModeConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IBlockConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IBucketConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IChatConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ICommandConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IEntityConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IFlightConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IGameModeConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IInventoryConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.IPotionConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ITeleportConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.InventoryConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.ItemConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.PotionConfiguration;
import combatlogx.expansion.cheat.prevention.configuration.TeleportConfiguration;
import combatlogx.expansion.cheat.prevention.listener.legacy.ListenerChat;
import combatlogx.expansion.cheat.prevention.listener.legacy.ListenerLegacyItemPickup;
import combatlogx.expansion.cheat.prevention.listener.legacy.ListenerLegacyPortalCreate;
import combatlogx.expansion.cheat.prevention.listener.legacy.ListenerLegacyPotions;
import combatlogx.expansion.cheat.prevention.listener.modern.ListenerInventoriesModern;
import combatlogx.expansion.cheat.prevention.listener.modern.ListenerModernItemPickup;
import combatlogx.expansion.cheat.prevention.listener.modern.ListenerModernPortalCreate;
import combatlogx.expansion.cheat.prevention.listener.modern.ListenerModernPotions;
import combatlogx.expansion.cheat.prevention.listener.paper.ListenerPaperChat;
import combatlogx.expansion.cheat.prevention.listener.paper.ListenerPaperEntityInsideBlock;
import combatlogx.expansion.cheat.prevention.task.ElytraRetagTask;
import combatlogx.expansion.cheat.prevention.task.FlightRetagTask;
public final class CheatPreventionExpansion extends Expansion implements ICheatPreventionExpansion {
private final CheatPreventionConfiguration configuration;
private final BlockConfiguration blockConfiguration;
private final BucketConfiguration bucketConfiguration;
private final ChatConfiguration chatConfiguration;
private final CommandConfiguration commandConfiguration;
private final EntityConfiguration entityConfiguration;
private final FlightConfiguration flightConfiguration;
private final GameModeConfiguration gameModeConfiguration;
private final InventoryConfiguration inventoryConfiguration;
private final ItemConfiguration itemConfiguration;
private final PotionConfiguration potionConfiguration;
private final TeleportConfiguration teleportConfiguration;
public CheatPreventionExpansion(ICombatLogX plugin) {
super(plugin);
this.configuration = new CheatPreventionConfiguration();
this.blockConfiguration = new BlockConfiguration();
this.bucketConfiguration = new BucketConfiguration();
this.chatConfiguration = new ChatConfiguration();
this.commandConfiguration = new CommandConfiguration();
this.entityConfiguration = new EntityConfiguration();
this.flightConfiguration = new FlightConfiguration();
this.gameModeConfiguration = new GameModeConfiguration();
this.inventoryConfiguration = new InventoryConfiguration();
this.itemConfiguration = new ItemConfiguration();
this.potionConfiguration = new PotionConfiguration();
this.teleportConfiguration = new TeleportConfiguration();
}
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("blocks.yml");
configurationManager.saveDefault("buckets.yml");
configurationManager.saveDefault("chat.yml");
configurationManager.saveDefault("commands.yml");
configurationManager.saveDefault("config.yml");
configurationManager.saveDefault("entities.yml");
configurationManager.saveDefault("flight.yml");
configurationManager.saveDefault("game-mode.yml");
configurationManager.saveDefault("inventories.yml");
configurationManager.saveDefault("items.yml");
configurationManager.saveDefault("potions.yml");
configurationManager.saveDefault("teleportation.yml");
}
@Override
public void onEnable() {
reloadConfig();
registerListeners();
registerTasks();
int minorVersion = VersionUtility.getMinorVersion();
registerVersionListeners(minorVersion);
registerVersionTasks(minorVersion);
registerPaperListeners();
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("blocks.yml");
configurationManager.reload("buckets.yml");
configurationManager.reload("chat.yml");
configurationManager.reload("commands.yml");
configurationManager.reload("config.yml");
configurationManager.reload("entities.yml");
configurationManager.reload("flight.yml");
configurationManager.reload("game-mode.yml");
configurationManager.reload("inventories.yml");
configurationManager.reload("items.yml");
configurationManager.reload("potions.yml");
configurationManager.reload("teleportation.yml");
getBlockConfiguration().load(configurationManager.get("blocks.yml"));
getBucketConfiguration().load(configurationManager.get("buckets.yml"));
getChatConfiguration().load(configurationManager.get("chat.yml"));
getCommandConfiguration().load(configurationManager.get("commands.yml"));
getConfiguration().load(configurationManager.get("config.yml"));
getEntityConfiguration().load(configurationManager.get("entities.yml"));
getFlightConfiguration().load(configurationManager.get("flight.yml"));
getGameModeConfiguration().load(configurationManager.get("game-mode.yml"));
getInventoryConfiguration().load(configurationManager.get("inventories.yml"));
getItemConfiguration().load(configurationManager.get("items.yml"));
getPotionConfiguration().load(configurationManager.get("potions.yml"));
getTeleportConfiguration().load(configurationManager.get("teleportation.yml"));
}
@Override
public @NotNull Expansion getExpansion() {
return this;
}
@Override
public @NotNull IConfiguration getConfiguration() {
return this.configuration;
}
@Override
public @NotNull IBlockConfiguration getBlockConfiguration() {
return this.blockConfiguration;
}
@Override
public @NotNull IBucketConfiguration getBucketConfiguration() {
return this.bucketConfiguration;
}
@Override
public @NotNull IChatConfiguration getChatConfiguration() {
return this.chatConfiguration;
}
@Override
public @NotNull ICommandConfiguration getCommandConfiguration() {
return this.commandConfiguration;
}
@Override
public @NotNull IEntityConfiguration getEntityConfiguration() {
return this.entityConfiguration;
}
@Override
public @NotNull IFlightConfiguration getFlightConfiguration() {
return this.flightConfiguration;
}
@Override
public @NotNull IGameModeConfiguration getGameModeConfiguration() {
return this.gameModeConfiguration;
}
@Override
public @NotNull IInventoryConfiguration getInventoryConfiguration() {
return this.inventoryConfiguration;
}
@Override
public @NotNull IItemConfiguration getItemConfiguration() {
return this.itemConfiguration;
}
@Override
public @NotNull IPotionConfiguration getPotionConfiguration() {
return this.potionConfiguration;
}
@Override
public @NotNull ITeleportConfiguration getTeleportConfiguration() {
return this.teleportConfiguration;
}
private void registerListeners() {
new ListenerBlocks(this).register();
new ListenerBuckets(this).register();
new ListenerCommands(this).register();
new ListenerDrop(this).register();
new ListenerEntities(this).register();
new ListenerFlight(this).register();
new ListenerGameMode(this).register();
new ListenerTeleport(this).register();
new ListenerEnderPearl(this).register();
}
private void registerVersionListeners(int minorVersion) {
// Elytra were added in 1.9.
if (minorVersion >= 9) {
new ListenerElytra(this).register();
}
// Totem of Undying was added in 1.11.
if (minorVersion >= 11) {
new ListenerTotem(this).register();
}
// PlayerPickupItemEvent was deprecated in favor of EntityPickupItemEvent in 1.12.
if (minorVersion < 12) {
new ListenerLegacyItemPickup(this).register();
} else {
new ListenerModernItemPickup(this).register();
}
// The Riptide enchantment was added in 1.13.
if (minorVersion >= 13) {
new ListenerRiptide(this).register();
}
// EntityPotionEffect was added in 1.13.
if (minorVersion >= 13) {
new ListenerModernPotions(this).register();
} else {
new ListenerLegacyPotions(this).register();
}
// EntityCreatePortalEvent was replaced with PortalCreateEvent#getEntity in 1.14.
if (minorVersion < 14) {
new ListenerLegacyPortalCreate(this).register();
} else {
new ListenerModernPortalCreate(this).register();
}
// InventoryView can be an interface or abstract class depending on version
if (isAbstractInventoryView()) {
new ListenerInventoriesModern(this).register();
} else {
new ListenerInventories(this).register();
}
}
private boolean isAbstractInventoryView() {
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion > 20) {
return true;
}
String minecraftVersion = VersionUtility.getMinecraftVersion();
return (minecraftVersion.equals("1.20.5") || minecraftVersion.equals("1.20.6"));
}
private void registerTasks() {
new FlightRetagTask(this).register();
}
private void registerVersionTasks(int minorVersion) {
// Elytra were added in 1.9.
if (minorVersion >= 9) {
new ElytraRetagTask(this).register();
}
}
// Paper has some custom event classes that don't exist on Spigot.
private void registerPaperListeners() {
if (checkPaperClass("io.papermc.paper.event.player.AsyncChatEvent")) {
new ListenerPaperChat(this).register();
} else {
new ListenerChat(this).register();
}
if (checkPaperClass("io.papermc.paper.event.entity.EntityInsideBlockEvent")) {
new ListenerPaperEntityInsideBlock(this).register();
}
}
private boolean checkPaperClass(String className) {
try {
Class.forName(className);
return true;
} catch (ReflectiveOperationException ex) {
Logger logger = getLogger();
logger.info(className + " is not supported on this server version.");
return false;
}
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/BlockConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
import static com.github.sirblobman.api.utility.ConfigurationHelper.parseEnums;
public final class BlockConfiguration implements IBlockConfiguration {
private final Set preventInteractionSet;
private final Set preventBreakingSet;
private final Set preventPlacingSet;
private boolean preventInteraction;
private boolean preventBreaking;
private boolean preventPlacing;
private boolean preventPortalCreation;
public BlockConfiguration() {
this.preventInteraction = false;
this.preventBreaking = true;
this.preventPlacing = true;
this.preventPortalCreation = false;
this.preventInteractionSet = EnumSet.noneOf(XMaterial.class);
this.preventBreakingSet = EnumSet.noneOf(XMaterial.class);
this.preventPlacingSet = EnumSet.noneOf(XMaterial.class);
}
@Override
public void load(ConfigurationSection config) {
setPreventInteraction(config.getBoolean("prevent-interaction", false));
setPreventBreaking(config.getBoolean("prevent-breaking", true));
setPreventPlacing(config.getBoolean("prevent-placing", true));
setPreventPortalCreation(config.getBoolean("prevent-portal-creation", false));
setPreventInteractionTypes(parseEnums(config.getStringList("prevent-interaction-list"), XMaterial.class));
setPreventBreakingTypes(parseEnums(config.getStringList("prevent-breaking-list"), XMaterial.class));
setPreventPlacingTypes(parseEnums(config.getStringList("prevent-placing-list"), XMaterial.class));
}
@Override
public boolean isPreventInteraction() {
return this.preventInteraction;
}
public void setPreventInteraction(boolean value) {
this.preventInteraction = value;
}
@Override
public boolean isPreventBreaking() {
return this.preventBreaking;
}
public void setPreventBreaking(boolean value) {
this.preventBreaking = value;
}
@Override
public boolean isPreventPlacing() {
return this.preventPlacing;
}
public void setPreventPlacing(boolean value) {
this.preventPlacing = value;
}
@Override
public boolean isPreventPortalCreation() {
return this.preventPortalCreation;
}
public void setPreventPortalCreation(boolean value) {
this.preventPortalCreation = value;
}
public @NotNull Set getPreventInteractionTypes() {
return Collections.unmodifiableSet(this.preventInteractionSet);
}
public void setPreventInteractionTypes(@NotNull Collection types) {
this.preventInteractionSet.clear();
this.preventInteractionSet.addAll(types);
}
public @NotNull Set getPreventBreakingTypes() {
return Collections.unmodifiableSet(this.preventBreakingSet);
}
public void setPreventBreakingTypes(@NotNull Collection types) {
this.preventBreakingSet.clear();
this.preventBreakingSet.addAll(types);
}
public @NotNull Set getPreventPlacingTypes() {
return Collections.unmodifiableSet(this.preventPlacingSet);
}
public void setPreventPlacingTypes(@NotNull Collection types) {
this.preventPlacingSet.clear();
this.preventPlacingSet.addAll(types);
}
@Override
public boolean isPreventInteraction(@NotNull XMaterial blockType) {
Set typeSet = getPreventInteractionTypes();
return typeSet.contains(blockType);
}
@Override
public boolean isPreventBreaking(@NotNull XMaterial blockType) {
Set typeSet = getPreventBreakingTypes();
return typeSet.contains(blockType);
}
@Override
public boolean isPreventPlacing(@NotNull XMaterial blockType) {
Set typeSet = getPreventPlacingTypes();
return typeSet.contains(blockType);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/BucketConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
import static com.github.sirblobman.api.utility.ConfigurationHelper.parseEnums;
public final class BucketConfiguration implements IBucketConfiguration {
private final Set preventBucketEmptyTypeSet;
private final Set preventBucketFillTypeSet;
private boolean preventBucketEmpty;
private boolean preventBucketFill;
public BucketConfiguration() {
this.preventBucketEmpty = false;
this.preventBucketFill = false;
this.preventBucketEmptyTypeSet = EnumSet.noneOf(XMaterial.class);
this.preventBucketFillTypeSet = EnumSet.noneOf(XMaterial.class);
}
@Override
public void load(@NotNull ConfigurationSection config) {
setPreventBucketEmpty(config.getBoolean("prevent-bucket-empty", false));
setPreventBucketFill(config.getBoolean("prevent-bucket-fill", false));
setPreventBucketEmptyTypes(parseEnums(config.getStringList("prevent-bucket-empty-list"), XMaterial.class));
setPreventBucketFillTypes(parseEnums(config.getStringList("prevent-bucket-fill-list"), XMaterial.class));
}
@Override
public boolean isPreventBucketEmpty() {
return this.preventBucketEmpty;
}
public void setPreventBucketEmpty(boolean value) {
this.preventBucketEmpty = value;
}
@Override
public boolean isPreventBucketFill() {
return this.preventBucketFill;
}
public void setPreventBucketFill(boolean value) {
this.preventBucketFill = value;
}
public @NotNull Set getPreventBucketEmptyTypes() {
return Collections.unmodifiableSet(this.preventBucketEmptyTypeSet);
}
public void setPreventBucketEmptyTypes(@NotNull Collection types) {
this.preventBucketEmptyTypeSet.clear();
this.preventBucketEmptyTypeSet.addAll(types);
}
public @NotNull Set getPreventBucketFillTypes() {
return Collections.unmodifiableSet(this.preventBucketFillTypeSet);
}
public void setPreventBucketFillTypes(@NotNull Collection types) {
this.preventBucketFillTypeSet.clear();
this.preventBucketFillTypeSet.addAll(types);
}
@Override
public boolean isPreventEmpty(@NotNull XMaterial material) {
Set typeSet = getPreventBucketEmptyTypes();
return typeSet.contains(material);
}
@Override
public boolean isPreventFill(@NotNull XMaterial material) {
Set typeSet = getPreventBucketFillTypes();
return typeSet.contains(material);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/ChatConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.configuration.ConfigurationSection;
public final class ChatConfiguration implements IChatConfiguration {
private boolean disableChat;
public ChatConfiguration() {
this.disableChat = false;
}
@Override
public void load(ConfigurationSection config) {
setDisableChat(config.getBoolean("disable-chat", false));
}
@Override
public boolean isDisableChat() {
return this.disableChat;
}
public void setDisableChat(boolean disableChat) {
this.disableChat = disableChat;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/CheatPreventionConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.configuration.ConfigurationSection;
public final class CheatPreventionConfiguration implements IConfiguration {
private int messageCooldown;
public CheatPreventionConfiguration() {
this.messageCooldown = 30;
}
@Override
public void load(ConfigurationSection config) {
setMessageCooldown(config.getInt("message-cooldown", 30));
}
@Override
public int getMessageCooldown() {
return this.messageCooldown;
}
public void setMessageCooldown(int messageCooldown) {
this.messageCooldown = messageCooldown;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/CommandConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
public final class CommandConfiguration implements ICommandConfiguration {
private final List blockedCommandList;
private final List allowedCommandList;
private int delayAfterCombat;
private String bypassPermissionName;
private transient Permission bypassPermission;
public CommandConfiguration() {
this.delayAfterCombat = 0;
this.blockedCommandList = new ArrayList<>();
this.allowedCommandList = new ArrayList<>();
this.bypassPermissionName = null;
this.bypassPermission = null;
}
@Override
public void load(ConfigurationSection config) {
setDelayAfterCombat(config.getInt("delay-after-combat", 0));
setBlockedCommands(config.getStringList("blocked-command-list"));
setAllowedCommands(config.getStringList("allowed-command-list"));
setBypassPermissionName(config.getString("bypass-permission"));
}
@Override
public int getDelayAfterCombat() {
return this.delayAfterCombat;
}
public void setDelayAfterCombat(int delay) {
this.delayAfterCombat = delay;
}
public @Nullable String getBypassPermissionName() {
return this.bypassPermissionName;
}
public void setBypassPermissionName(@Nullable String permissionName) {
this.bypassPermissionName = permissionName;
this.bypassPermission = null;
}
@Override
public @Nullable Permission getBypassPermission() {
if (this.bypassPermission != null) {
return this.bypassPermission;
}
String permissionName = getBypassPermissionName();
if (permissionName == null || permissionName.isEmpty()) {
return null;
}
String permissionDescription = "CombatLogX CheatPrevention command blocker bypass.";
this.bypassPermission = new Permission(permissionName, permissionDescription, PermissionDefault.FALSE);
return this.bypassPermission;
}
public @NotNull List getAllowedCommands() {
return Collections.unmodifiableList(this.allowedCommandList);
}
public void setAllowedCommands(@NotNull Collection commands) {
this.allowedCommandList.clear();
this.allowedCommandList.addAll(commands);
}
@Override
public boolean isAllowed(@NotNull String command) {
List allowedCommandList = getAllowedCommands();
if (allowedCommandList.contains("*")) {
return true;
}
String commandLowercase = command.toLowerCase(Locale.US);
for (String allowedCommand : allowedCommandList) {
String allowedCommandLowercase = allowedCommand.toLowerCase(Locale.US);
if (commandLowercase.equals(allowedCommandLowercase)) {
return true;
}
String withSpace = (allowedCommand + " ");
if (commandLowercase.startsWith(withSpace)) {
return true;
}
}
return false;
}
public @NotNull List getBlockedCommands() {
return Collections.unmodifiableList(this.blockedCommandList);
}
public void setBlockedCommands(@NotNull Collection commands) {
this.blockedCommandList.clear();
this.blockedCommandList.addAll(commands);
}
@Override
public boolean isBlocked(@NotNull String command) {
List blockedCommandList = getBlockedCommands();
if (blockedCommandList.contains("*")) {
return true;
}
String commandLowercase = command.toLowerCase(Locale.US);
for (String blockedCommand : blockedCommandList) {
String blockedCommandLowercase = blockedCommand.toLowerCase(Locale.US);
if (commandLowercase.equals(blockedCommandLowercase)) {
return true;
}
String withSpace = (blockedCommand + " ");
if (commandLowercase.startsWith(withSpace)) {
return true;
}
}
return false;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/EntityConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.configuration.ConfigurationSection;
public final class EntityConfiguration implements IEntityConfiguration {
private boolean preventInteraction;
public EntityConfiguration() {
this.preventInteraction = false;
}
@Override
public void load(ConfigurationSection config) {
setPreventInteraction(config.getBoolean("prevent-interaction", false));
}
@Override
public boolean isPreventInteraction() {
return this.preventInteraction;
}
public void setPreventInteraction(boolean value) {
this.preventInteraction = value;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/FlightConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.configuration.ConfigurationSection;
public final class FlightConfiguration implements IFlightConfiguration {
private boolean preventFlying;
private boolean preventFallDamage;
private boolean forceDisableFlight;
private boolean flightRetag;
public FlightConfiguration() {
this.preventFlying = true;
this.preventFallDamage = true;
this.forceDisableFlight = false;
this.flightRetag = false;
}
@Override
public void load(ConfigurationSection config) {
setPreventFlying(config.getBoolean("prevent-flying", true));
setPreventFallDamage(config.getBoolean("prevent-fall-damahe", true));
setForceDisableFlight(config.getBoolean("force-disable-flight", false));
setFlightRetag(config.getBoolean("flight-retag", false));
}
@Override
public boolean isPreventFlying() {
return this.preventFlying;
}
public void setPreventFlying(boolean preventFlying) {
this.preventFlying = preventFlying;
}
@Override
public boolean isPreventFallDamage() {
return this.preventFallDamage;
}
public void setPreventFallDamage(boolean preventFallDamage) {
this.preventFallDamage = preventFallDamage;
}
@Override
public boolean isForceDisableFlight() {
return this.forceDisableFlight;
}
public void setForceDisableFlight(boolean forceDisableFlight) {
this.forceDisableFlight = forceDisableFlight;
}
@Override
public boolean isFlightRetag() {
return this.flightRetag;
}
public void setFlightRetag(boolean flightRetag) {
this.flightRetag = flightRetag;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/GameModeConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.GameMode;
import org.bukkit.configuration.ConfigurationSection;
import static com.github.sirblobman.api.utility.ConfigurationHelper.parseEnum;
public final class GameModeConfiguration implements IGameModeConfiguration {
private boolean preventSwitching;
private boolean untagOnSwitch;
private boolean forceSwitch;
private GameMode forceMode;
public GameModeConfiguration() {
this.preventSwitching = true;
this.untagOnSwitch = false;
this.forceSwitch = false;
this.forceMode = GameMode.SURVIVAL;
}
@Override
public void load(ConfigurationSection config) {
setPreventSwitching(config.getBoolean("prevent-switching", true));
setUntagOnSwitch(config.getBoolean("untag-on-switch", false));
setForceSwitch(config.getBoolean("force-switch", false));
String forceModeName = config.getString("force-mode", "SURVIVAL");
setForceMode(parseEnum(GameMode.class, forceModeName, GameMode.SURVIVAL));
}
@Override
public boolean isPreventSwitching() {
return this.preventSwitching;
}
public void setPreventSwitching(boolean preventSwitching) {
this.preventSwitching = preventSwitching;
}
@Override
public boolean isUntagOnSwitch() {
return this.untagOnSwitch;
}
public void setUntagOnSwitch(boolean untagOnSwitch) {
this.untagOnSwitch = untagOnSwitch;
}
@Override
public boolean isForceSwitch() {
return this.forceSwitch;
}
public void setForceSwitch(boolean forceSwitch) {
this.forceSwitch = forceSwitch;
}
@Override
public @NotNull GameMode getForceMode() {
return this.forceMode;
}
public void setForceMode(@NotNull GameMode forceMode) {
this.forceMode = forceMode;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/InventoryConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryType;
import static com.github.sirblobman.api.utility.ConfigurationHelper.parseEnums;
public final class InventoryConfiguration implements IInventoryConfiguration {
private final Set noCloseMessageTypeSet;
private boolean close;
private boolean closeOnRetag;
private boolean preventOpening;
public InventoryConfiguration() {
this.close = true;
this.closeOnRetag = true;
this.preventOpening = true;
this.noCloseMessageTypeSet = EnumSet.noneOf(InventoryType.class);
}
@Override
public void load(ConfigurationSection config) {
setClose(config.getBoolean("close", true));
setCloseOnRetag(config.getBoolean("close-on-retag", true));
setPreventOpening(config.getBoolean("prevent-opening", true));
List inventoryTypeNameList = config.getStringList("no-close-message-type-list");
setNoCloseMessageTypes(parseEnums(inventoryTypeNameList, InventoryType.class));
}
@Override
public boolean isClose() {
return this.close;
}
public void setClose(boolean close) {
this.close = close;
}
@Override
public boolean isCloseOnRetag() {
return this.closeOnRetag;
}
public void setCloseOnRetag(boolean closeOnRetag) {
this.closeOnRetag = closeOnRetag;
}
@Override
public boolean isPreventOpening() {
return this.preventOpening;
}
public void setPreventOpening(boolean preventOpening) {
this.preventOpening = preventOpening;
}
public @NotNull Set getNoCloseMessageTypes() {
return Collections.unmodifiableSet(this.noCloseMessageTypeSet);
}
public void setNoCloseMessageTypes(@NotNull Collection types) {
this.noCloseMessageTypeSet.clear();
this.noCloseMessageTypeSet.addAll(types);
}
@Override
public boolean isNoMessage(@NotNull InventoryType type) {
Set typeSet = getNoCloseMessageTypes();
return typeSet.contains(type);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/ItemConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import org.bukkit.configuration.ConfigurationSection;
public final class ItemConfiguration implements IItemConfiguration {
private boolean preventDrop;
private boolean preventPickup;
private boolean preventElytra;
private boolean forcePreventElytra;
private boolean preventFireworks;
private boolean elytraRetag;
private boolean preventTotem;
private boolean preventRiptide;
private boolean riptideRetag;
public ItemConfiguration() {
this.preventDrop = true;
this.preventPickup = true;
this.preventElytra = true;
this.forcePreventElytra = false;
this.preventFireworks = false;
this.elytraRetag = false;
this.preventTotem = false;
this.preventRiptide = false;
this.riptideRetag = false;
}
@Override
public void load(ConfigurationSection config) {
setPreventDrop(config.getBoolean("prevent-drop", true));
setPreventPickup(config.getBoolean("prevent-pickup", true));
setPreventElytra(config.getBoolean("prevent-elytra", true));
setForcePreventElytra(config.getBoolean("force-prevent-elytra", true));
setPreventFireworks(config.getBoolean("prevent-fireworks", false));
setElytraRetag(config.getBoolean("elytra-retag", false));
setPreventTotem(config.getBoolean("prevent-totem", false));
setPreventRiptide(config.getBoolean("prevent-riptide", false));
setRiptideRetag(config.getBoolean("riptide-retag", false));
}
@Override
public boolean isPreventDrop() {
return this.preventDrop;
}
public void setPreventDrop(boolean preventDrop) {
this.preventDrop = preventDrop;
}
@Override
public boolean isPreventPickup() {
return this.preventPickup;
}
public void setPreventPickup(boolean preventPickup) {
this.preventPickup = preventPickup;
}
@Override
public boolean isPreventElytra() {
return this.preventElytra;
}
public void setPreventElytra(boolean preventElytra) {
this.preventElytra = preventElytra;
}
@Override
public boolean isForcePreventElytra() {
return this.forcePreventElytra;
}
public void setForcePreventElytra(boolean forcePreventElytra) {
this.forcePreventElytra = forcePreventElytra;
}
@Override
public boolean isElytraRetag() {
return this.elytraRetag;
}
public void setElytraRetag(boolean elytraRetag) {
this.elytraRetag = elytraRetag;
}
@Override
public boolean isPreventTotem() {
return this.preventTotem;
}
public void setPreventTotem(boolean preventTotem) {
this.preventTotem = preventTotem;
}
@Override
public boolean isPreventRiptide() {
return this.preventRiptide;
}
public void setPreventRiptide(boolean preventRiptide) {
this.preventRiptide = preventRiptide;
}
@Override
public boolean isRiptideRetag() {
return this.riptideRetag;
}
public void setRiptideRetag(boolean riptideRetag) {
this.riptideRetag = riptideRetag;
}
@Override
public boolean isPreventFireworks() {
return this.preventFireworks;
}
public void setPreventFireworks(boolean preventFireworks) {
this.preventFireworks = preventFireworks;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/PotionConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.potion.PotionEffectType;
public final class PotionConfiguration implements IPotionConfiguration {
private final Set blockedPotionTypeSet;
private boolean blockedPotionTypeSetInverted;
public PotionConfiguration() {
this.blockedPotionTypeSet = new HashSet<>();
this.blockedPotionTypeSetInverted = false;
}
@Override
public void load(ConfigurationSection config) {
setBlockedPotionTypeSetInverted(config.getBoolean("blocked-potion-type-list-inverted", false));
List potionTypeNameList = config.getStringList("blocked-potion-type-list");
List potionEffectTypeList = new ArrayList<>();
for (String potionTypeName : potionTypeNameList) {
PotionEffectType potionEffectType = PotionEffectType.getByName(potionTypeName);
if (potionEffectType != null) {
potionEffectTypeList.add(potionEffectType);
}
}
setBlockedPotionTypes(potionEffectTypeList);
}
public boolean isBlockedPotionTypeSetInverted() {
return this.blockedPotionTypeSetInverted;
}
public void setBlockedPotionTypeSetInverted(boolean blockedPotionTypeSetInverted) {
this.blockedPotionTypeSetInverted = blockedPotionTypeSetInverted;
}
public @NotNull Set getBlockedPotionTypes() {
return Collections.unmodifiableSet(this.blockedPotionTypeSet);
}
public void setBlockedPotionTypes(@NotNull Collection types) {
this.blockedPotionTypeSet.clear();
this.blockedPotionTypeSet.addAll(types);
}
@Override
public boolean isBlocked(@NotNull PotionEffectType effectType) {
Set blockedPotionTypeSet = getBlockedPotionTypes();
boolean inverted = isBlockedPotionTypeSetInverted();
boolean contains = blockedPotionTypeSet.contains(effectType);
return (inverted != contains);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/configuration/TeleportConfiguration.java
================================================
package combatlogx.expansion.cheat.prevention.configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import static com.github.sirblobman.api.utility.ConfigurationHelper.parseEnums;
public final class TeleportConfiguration implements ITeleportConfiguration {
private final Set allowedTeleportCauseSet;
private boolean preventPortals;
private boolean preventTeleportation;
private boolean enderPearlRetag;
private boolean untag;
private boolean forceDisableEnderPearl;
public TeleportConfiguration() {
this.preventPortals = true;
this.preventTeleportation = true;
this.enderPearlRetag = false;
this.untag = false;
this.allowedTeleportCauseSet = EnumSet.noneOf(TeleportCause.class);
this.forceDisableEnderPearl = false;
}
@Override
public void load(ConfigurationSection config) {
setPreventPortals(config.getBoolean("prevent-portals", true));
setPreventTeleportation(config.getBoolean("prevent-teleportation", true));
setEnderPearlRetag(config.getBoolean("ender-pearl-retag", false));
setUntag(config.getBoolean("untag", false));
setForceDisableEnderPearl(config.getBoolean("force-disable-ender-pearl", false));
List allowedTeleportCauseNameList = config.getStringList("allowed-teleport-cause-list");
setAllowedTeleportCauses(parseEnums(allowedTeleportCauseNameList, TeleportCause.class));
}
@Override
public boolean isPreventPortals() {
return this.preventPortals;
}
public void setPreventPortals(boolean preventPortals) {
this.preventPortals = preventPortals;
}
@Override
public boolean isPreventTeleportation() {
return this.preventTeleportation;
}
public void setPreventTeleportation(boolean preventTeleportation) {
this.preventTeleportation = preventTeleportation;
}
@Override
public boolean isEnderPearlRetag() {
return this.enderPearlRetag;
}
public void setEnderPearlRetag(boolean enderPearlRetag) {
this.enderPearlRetag = enderPearlRetag;
}
@Override
public boolean isUntag() {
return this.untag;
}
public void setUntag(boolean untag) {
this.untag = untag;
}
public @NotNull Set getAllowedTeleportCauses() {
return Collections.unmodifiableSet(this.allowedTeleportCauseSet);
}
public void setAllowedTeleportCauses(@NotNull Collection causes) {
this.allowedTeleportCauseSet.clear();
this.allowedTeleportCauseSet.addAll(causes);
}
@Override
public boolean isAllowed(@NotNull TeleportCause cause) {
Set causeSet = getAllowedTeleportCauses();
return causeSet.contains(cause);
}
@Override
public boolean isForceDisableEnderPearl() {
return this.forceDisableEnderPearl;
}
public void setForceDisableEnderPearl(boolean forceDisableEnderPearl) {
this.forceDisableEnderPearl = forceDisableEnderPearl;
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerBlocks.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import java.util.Locale;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IBlockConfiguration;
public final class ListenerBlocks extends CheatPreventionListener {
public ListenerBlocks(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
Action action = e.getAction();
if (action != Action.RIGHT_CLICK_BLOCK && action != Action.LEFT_CLICK_BLOCK && action != Action.PHYSICAL) {
return;
}
Block block = e.getClickedBlock();
if (block == null) {
return;
}
Player player = e.getPlayer();
if (isPreventInteract(fetchMaterial(block)) && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-interaction");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
Block block = e.getBlock();
if (isPreventBreak(fetchMaterial(block)) && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-breaking");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) {
Player player = e.getPlayer();
Block block = e.getBlock();
if (isPreventPlace(fetchMaterial(block)) && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-placing");
}
}
private @NotNull IBlockConfiguration getBlockConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getBlockConfiguration();
}
private boolean isPreventBreak(@NotNull XMaterial material) {
IBlockConfiguration blockConfiguration = getBlockConfiguration();
if (blockConfiguration.isPreventBreaking()) {
return blockConfiguration.isPreventBreaking(material);
}
return false;
}
private boolean isPreventPlace(@NotNull XMaterial material) {
IBlockConfiguration blockConfiguration = getBlockConfiguration();
if (blockConfiguration.isPreventPlacing()) {
return blockConfiguration.isPreventPlacing(material);
}
return false;
}
private boolean isPreventInteract(@NotNull XMaterial material) {
IBlockConfiguration blockConfiguration = getBlockConfiguration();
if (blockConfiguration.isPreventInteraction()) {
return blockConfiguration.isPreventInteraction(material);
}
return false;
}
@SuppressWarnings("deprecation")
private @NotNull XMaterial fetchMaterial(@NotNull Block block) {
int minorVersion = VersionUtility.getMinorVersion();
Material bukkitType = block.getType();
if (minorVersion < 13) {
int data = block.getData();
String materialName = String.format(Locale.US, "%s:%s", bukkitType.name(), data);
return XMaterial.matchXMaterial(materialName).orElse(XMaterial.AIR);
} else {
return XMaterial.matchXMaterial(bukkitType);
}
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerBuckets.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import com.github.sirblobman.api.shaded.xseries.XMaterial;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IBucketConfiguration;
public final class ListenerBuckets extends CheatPreventionListener {
public ListenerBuckets(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBucketEmpty(PlayerBucketEmptyEvent e) {
Player player = e.getPlayer();
Material bukkitMaterial = e.getBucket();
XMaterial material = XMaterial.matchXMaterial(bukkitMaterial);
if (isInCombat(player) && isPreventEmpty(material)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.buckets.no-empty");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBucketEmpty(PlayerBucketFillEvent e) {
Player player = e.getPlayer();
Material bukkitMaterial = e.getBucket();
XMaterial material = XMaterial.matchXMaterial(bukkitMaterial);
if (isInCombat(player) && isPreventFill(material)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.buckets.no-fill");
}
}
private @NotNull IBucketConfiguration getBucketConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getBucketConfiguration();
}
private boolean isPreventEmpty(@NotNull XMaterial material) {
IBucketConfiguration configuration = getBucketConfiguration();
return (configuration.isPreventBucketEmpty() && configuration.isPreventEmpty(material));
}
private boolean isPreventFill(@NotNull XMaterial material) {
IBucketConfiguration configuration = getBucketConfiguration();
return (configuration.isPreventBucketFill() && configuration.isPreventFill(material));
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerCommands.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.permissions.Permission;
import com.github.sirblobman.api.language.replacer.Replacer;
import com.github.sirblobman.api.language.replacer.StringReplacer;
import com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent;
import com.github.sirblobman.combatlogx.api.object.UntagReason;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.ICommandConfiguration;
public final class ListenerCommands extends CheatPreventionListener {
private final Map cooldownMap;
public ListenerCommands(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
this.cooldownMap = new HashMap<>();
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void beforeCommandLowest(PlayerCommandPreprocessEvent e) {
checkEvent(e);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void beforeCommandHigh(PlayerCommandPreprocessEvent e) {
checkEvent(e);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onUntag(PlayerUntagEvent e) {
UntagReason untagReason = e.getUntagReason();
if (!untagReason.isExpire()) {
return;
}
Player player = e.getPlayer();
addCooldown(player);
}
private @NotNull ICommandConfiguration getCommandConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getCommandConfiguration();
}
private boolean hasBypassPermission(Player player) {
ICommandConfiguration commandConfiguration = getCommandConfiguration();
Permission bypassPermission = commandConfiguration.getBypassPermission();
if (bypassPermission == null) {
return false;
}
return player.hasPermission(bypassPermission);
}
private long getNewExpireTime() {
ICommandConfiguration commandConfiguration = getCommandConfiguration();
long cooldownSeconds = commandConfiguration.getDelayAfterCombat();
long cooldownMillis = TimeUnit.SECONDS.toMillis(cooldownSeconds);
long systemMillis = System.currentTimeMillis();
return (systemMillis + cooldownMillis);
}
private boolean isInCooldown(Player player) {
UUID uuid = player.getUniqueId();
if (this.cooldownMap.containsKey(uuid)) {
long expireMillis = this.cooldownMap.get(uuid);
long systemMillis = System.currentTimeMillis();
if (systemMillis < expireMillis) {
return true;
}
this.cooldownMap.remove(uuid);
return false;
}
return false;
}
private void addCooldown(Player player) {
UUID playerId = player.getUniqueId();
long expireMillis = getNewExpireTime();
this.cooldownMap.put(playerId, expireMillis);
}
private String fixCommand(String command) {
if (command.startsWith("/")) {
return command;
}
return ("/" + command);
}
private boolean isBlocked(String command) {
ICommandConfiguration commandConfiguration = getCommandConfiguration();
return commandConfiguration.isBlocked(command);
}
private boolean isAllowed(String command) {
ICommandConfiguration commandConfiguration = getCommandConfiguration();
return commandConfiguration.isAllowed(command);
}
private void checkEvent(PlayerCommandPreprocessEvent e) {
Player player = e.getPlayer();
if (!isInCombat(player) && !isInCooldown(player)) {
return;
}
if (hasBypassPermission(player)) {
return;
}
String command = e.getMessage();
String realCommand = fixCommand(command);
if (isAllowed(realCommand) || !isBlocked(realCommand)) {
return;
}
e.setCancelled(true);
Replacer replacer = new StringReplacer("{command}", realCommand);
sendMessageIgnoreCooldown(player, "expansion.cheat-prevention.command-blocked", replacer);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerDrop.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerDropItemEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
public final class ListenerDrop extends CheatPreventionListener {
public ListenerDrop(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDrop(PlayerDropItemEvent e) {
Player player = e.getPlayer();
if (isPreventDrop() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.items.no-dropping");
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventDrop() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isPreventDrop();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerElytra.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.projectiles.ProjectileSource;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
public final class ListenerElytra extends CheatPreventionListener {
public ListenerElytra(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
Player player = e.getPlayer();
if (player.isGliding() && isForcePreventElytra()) {
player.setGliding(false);
sendMessage(player, "expansion.cheat-prevention.elytra.force-disabled");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onToggle(EntityToggleGlideEvent e) {
if (!e.isGliding()) {
return;
}
Entity entity = e.getEntity();
if (!(entity instanceof Player player)) {
return;
}
if (isInCombat(player) && isPreventElytra()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.elytra.no-gliding");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onLaunch(ProjectileLaunchEvent e) {
if (!isPreventFireworks()) {
return;
}
Projectile projectile = e.getEntity();
if (projectile instanceof Firework firework) {
ProjectileSource shooter = firework.getShooter();
if (shooter instanceof Player player && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.elytra.no-fireworks");
}
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventElytra() {
return getItemConfiguration().isPreventElytra();
}
private boolean isForcePreventElytra() {
return getItemConfiguration().isForcePreventElytra();
}
private boolean isPreventFireworks() {
return getItemConfiguration().isPreventFireworks();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerEnderPearl.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.ITeleportConfiguration;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
public final class ListenerEnderPearl extends CheatPreventionListener {
public ListenerEnderPearl(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onLand(ProjectileLaunchEvent e) {
ICheatPreventionExpansion expansion = getCheatPrevention();
ITeleportConfiguration teleportConfiguration = expansion.getTeleportConfiguration();
if (!teleportConfiguration.isForceDisableEnderPearl()) {
return;
}
Projectile projectile = e.getEntity();
if (!(projectile instanceof EnderPearl enderPearl)) {
return;
}
ProjectileSource shooter = enderPearl.getShooter();
if (shooter instanceof Player player && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.teleportation.block-pearl");
}
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerEntities.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IEntityConfiguration;
public final class ListenerEntities extends CheatPreventionListener {
public ListenerEntities(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInteract(PlayerInteractEntityEvent e) {
Player player = e.getPlayer();
if (isInCombat(player) && isPreventInteraction()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.no-entity-interaction");
}
}
private @NotNull IEntityConfiguration getEntityConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getEntityConfiguration();
}
private boolean isPreventInteraction() {
IEntityConfiguration entityConfiguration = getEntityConfiguration();
return entityConfiguration.isPreventInteraction();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerFlight.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IFlightConfiguration;
public final class ListenerFlight extends CheatPreventionListener {
private final Set noFallDamageSet;
public ListenerFlight(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
this.noFallDamageSet = new HashSet<>();
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
printDebug("Detected PlayerTagEvent...");
Player player = e.getPlayer();
printDebug("Checking player allow flight value...");
checkAllowFlight(player);
printDebug("Checking player flying value...");
checkFlight(player);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onToggle(PlayerToggleFlightEvent e) {
Player player = e.getPlayer();
if (e.isFlying() && isPreventFlight() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.flight.no-flying");
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
DamageCause damageCause = e.getCause();
if (damageCause != DamageCause.FALL) {
return;
}
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
UUID playerId = player.getUniqueId();
if (isPreventFallDamage() && this.noFallDamageSet.remove(playerId)) {
e.setCancelled(true);
}
}
private @NotNull IFlightConfiguration getFlightConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getFlightConfiguration();
}
private boolean isPreventFlight() {
IFlightConfiguration flightConfiguration = getFlightConfiguration();
return flightConfiguration.isPreventFlying();
}
private boolean isForceDisableFlight() {
IFlightConfiguration flightConfiguration = getFlightConfiguration();
return flightConfiguration.isForceDisableFlight();
}
private boolean isPreventFallDamage() {
IFlightConfiguration flightConfiguration = getFlightConfiguration();
return flightConfiguration.isPreventFallDamage();
}
private void checkFlight(Player player) {
if (isPreventFlight() && player.isFlying()) {
player.setFlying(false);
if (isPreventFallDamage()) {
UUID playerId = player.getUniqueId();
this.noFallDamageSet.add(playerId);
}
sendMessage(player, "expansion.cheat-prevention.flight.force-disabled");
}
}
private void checkAllowFlight(Player player) {
if (player.getAllowFlight() && isForceDisableFlight()) {
player.setAllowFlight(false);
sendMessage(player, "expansion.cheat-prevention.flight.force-disabled");
}
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerGameMode.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import com.github.sirblobman.api.language.replacer.Replacer;
import com.github.sirblobman.api.language.replacer.StringReplacer;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.UntagReason;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IGameModeConfiguration;
public final class ListenerGameMode extends CheatPreventionListener {
public ListenerGameMode(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSwitch(PlayerGameModeChangeEvent e) {
Player player = e.getPlayer();
if (isInCombat(player)) {
GameMode gameMode = e.getNewGameMode();
GameMode forceMode = getForceSwitchMode();
if (gameMode == forceMode) {
return;
}
if (isPreventSwitching()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.game-mode.no-switch");
return;
}
checkUntag(player);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
if (isForceSwitch()) {
Player player = e.getPlayer();
GameMode gameMode = getForceSwitchMode();
player.setGameMode(gameMode);
String gameModeName = gameMode.name();
Replacer replacer = new StringReplacer("{game_mode}", gameModeName);
sendMessage(player, "expansion.cheat-prevention.game-mode.force-switch", replacer);
}
}
private void checkUntag(@NotNull Player player) {
if (isUntagOnSwitch()) {
ICombatManager combatManager = getCombatManager();
combatManager.untag(player, UntagReason.EXPIRE);
}
}
private @NotNull IGameModeConfiguration getGameModeConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getGameModeConfiguration();
}
private boolean isPreventSwitching() {
IGameModeConfiguration gameModeConfiguration = getGameModeConfiguration();
return gameModeConfiguration.isPreventSwitching();
}
private boolean isForceSwitch() {
IGameModeConfiguration gameModeConfiguration = getGameModeConfiguration();
return gameModeConfiguration.isForceSwitch();
}
private boolean isUntagOnSwitch() {
IGameModeConfiguration gameModeConfiguration = getGameModeConfiguration();
return gameModeConfiguration.isUntagOnSwitch();
}
private @NotNull GameMode getForceSwitchMode() {
IGameModeConfiguration gameModeConfiguration = getGameModeConfiguration();
return gameModeConfiguration.getForceMode();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerInventories.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;
import com.github.sirblobman.combatlogx.api.event.PlayerReTagEvent;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IInventoryConfiguration;
public final class ListenerInventories extends CheatPreventionListener {
public ListenerInventories(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
if (isClose()) {
Player player = e.getPlayer();
InventoryView openView = player.getOpenInventory();
InventoryType viewType = openView.getType();
player.closeInventory();
if (isMessage(viewType)) {
sendMessage(player, "expansion.cheat-prevention.inventory.force-closed");
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onReTag(PlayerReTagEvent e) {
if (isCloseOnRetag()) {
Player player = e.getPlayer();
InventoryView openView = player.getOpenInventory();
InventoryType viewType = openView.getType();
player.closeInventory();
if (isMessage(viewType)) {
sendMessage(player, "expansion.cheat-prevention.inventory.force-closed");
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onOpen(InventoryOpenEvent e) {
HumanEntity human = e.getPlayer();
if (!(human instanceof Player)) {
return;
}
Player player = (Player) human;
if (isPreventOpening() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.inventory.no-opening");
}
}
private @NotNull IInventoryConfiguration getInventoryConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getInventoryConfiguration();
}
private boolean isClose() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isClose();
}
private boolean isCloseOnRetag() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isCloseOnRetag();
}
private boolean isPreventOpening() {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return inventoryConfiguration.isPreventOpening();
}
private boolean isMessage(@NotNull InventoryType type) {
IInventoryConfiguration inventoryConfiguration = getInventoryConfiguration();
return !inventoryConfiguration.isNoMessage(type);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerRiptide.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
public final class ListenerRiptide extends CheatPreventionListener {
public ListenerRiptide(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
if (!player.isRiptiding()) {
return;
}
if (!isInCombat(player)) {
return;
}
if (isPreventRiptide()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.no-riptide");
}
if (isRiptideRetag()) {
ICombatManager combatManager = getCombatManager();
combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventRiptide() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isPreventRiptide();
}
private boolean isRiptideRetag() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isRiptideRetag();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerTeleport.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import com.github.sirblobman.combatlogx.api.object.UntagReason;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.ITeleportConfiguration;
public final class ListenerTeleport extends CheatPreventionListener {
public ListenerTeleport(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent e) {
Player player = e.getPlayer();
if (isInCombat(player)) {
checkPrevention(e);
checkEnderPearlRetag(e);
checkUntag(e);
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPortal(PlayerPortalEvent e) {
Player player = e.getPlayer();
if (isInCombat(player) && isPreventPortals()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.teleportation.block-portal");
}
}
private void checkPrevention(PlayerTeleportEvent e) {
printDebug("Checking if teleport event should be prevented...");
if (e.isCancelled()) {
printDebug("Event is already cancelled.");
return;
}
if (isPreventTeleportation()) {
TeleportCause teleportCause = e.getCause();
if (isAllowed(teleportCause)) {
printDebug("Teleportation cause '" + teleportCause + "' is allowed by the config.");
return;
}
printDebug("Cancelling teleport event.");
e.setCancelled(true);
Player player = e.getPlayer();
String messagePath = getMessagePath(teleportCause);
sendMessage(player, messagePath);
}
}
private void checkEnderPearlRetag(PlayerTeleportEvent e) {
printDebug("Checking if ender pearl should re-tag player...");
if (e.isCancelled()) {
printDebug("Event was cancelled, ignoring.");
return;
}
if (isEnderPearlRetag() && e.getCause() == TeleportCause.ENDER_PEARL) {
Player player = e.getPlayer();
ICombatManager combatManager = getCombatManager();
combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
printDebug("Player will be re-tagged. Done.");
}
}
private void checkUntag(PlayerTeleportEvent e) {
printDebug("Checking if player should be untagged by teleport event...");
if (e.isCancelled()) {
printDebug("Event was cancelled, not untagging.");
return;
}
if (isUntag() && e.getCause() != TeleportCause.UNKNOWN) {
Player player = e.getPlayer();
ICombatManager combatManager = getCombatManager();
combatManager.untag(player, UntagReason.EXPIRE);
printDebug("Untagging player due to teleport event.");
}
}
private String getMessagePath(TeleportCause cause) {
String mainPath = ("expansion.cheat-prevention.teleportation.block-");
String causeName = (cause == TeleportCause.ENDER_PEARL ? "pearl" : "other");
return (mainPath + causeName);
}
private @NotNull ITeleportConfiguration getTeleportConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getTeleportConfiguration();
}
private boolean isPreventTeleportation() {
ITeleportConfiguration teleportConfiguration = getTeleportConfiguration();
return teleportConfiguration.isPreventTeleportation();
}
private boolean isPreventPortals() {
ITeleportConfiguration teleportConfiguration = getTeleportConfiguration();
return teleportConfiguration.isPreventPortals();
}
private boolean isEnderPearlRetag() {
ITeleportConfiguration teleportConfiguration = getTeleportConfiguration();
return teleportConfiguration.isEnderPearlRetag();
}
private boolean isUntag() {
ITeleportConfiguration teleportConfiguration = getTeleportConfiguration();
return teleportConfiguration.isUntag();
}
private boolean isAllowed(@NotNull TeleportCause cause) {
ITeleportConfiguration teleportConfiguration = getTeleportConfiguration();
return teleportConfiguration.isAllowed(cause);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/ListenerTotem.java
================================================
package combatlogx.expansion.cheat.prevention.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityResurrectEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
public final class ListenerTotem extends CheatPreventionListener {
public ListenerTotem(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onResurrect(EntityResurrectEvent e) {
LivingEntity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
if (isInCombat(player) && isPreventTotem()) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.no-totem");
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventTotem() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isPreventTotem();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/modern/ListenerModernItemPickup.java
================================================
package combatlogx.expansion.cheat.prevention.listener.modern;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityPickupItemEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerModernItemPickup extends CheatPreventionListener {
public ListenerModernItemPickup(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPickup(EntityPickupItemEvent e) {
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
if (isPreventPickup() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.items.no-pickup");
}
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private boolean isPreventPickup() {
IItemConfiguration itemConfiguration = getItemConfiguration();
return itemConfiguration.isPreventPickup();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/modern/ListenerModernPortalCreate.java
================================================
package combatlogx.expansion.cheat.prevention.listener.modern;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.world.PortalCreateEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IBlockConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public final class ListenerModernPortalCreate extends CheatPreventionListener {
public ListenerModernPortalCreate(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPortalCreate(PortalCreateEvent e) {
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
if (isPreventPortalCreation() && isInCombat(player)) {
e.setCancelled(true);
sendMessage(player, "expansion.cheat-prevention.blocks.prevent-portal-creation");
}
}
private @NotNull IBlockConfiguration getBlockConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getBlockConfiguration();
}
private boolean isPreventPortalCreation() {
IBlockConfiguration configuration = getBlockConfiguration();
return configuration.isPreventPortalCreation();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/listener/modern/ListenerModernPotions.java
================================================
package combatlogx.expansion.cheat.prevention.listener.modern;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent.Action;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.github.sirblobman.combatlogx.api.event.PlayerTagEvent;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IPotionConfiguration;
import combatlogx.expansion.cheat.prevention.listener.CheatPreventionListener;
public class ListenerModernPotions extends CheatPreventionListener {
public ListenerModernPotions(@NotNull ICheatPreventionExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTag(PlayerTagEvent e) {
Player player = e.getPlayer();
Collection activePotionEffectCollection = player.getActivePotionEffects();
for (PotionEffect potionEffect : activePotionEffectCollection) {
PotionEffectType potionEffectType = potionEffect.getType();
if (isBlocked(potionEffectType)) {
player.removePotionEffect(potionEffectType);
}
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onAddEffect(EntityPotionEffectEvent e) {
Action action = e.getAction();
if (action != Action.ADDED) {
return;
}
EntityType entityType = e.getEntityType();
if (entityType != EntityType.PLAYER) {
return;
}
Player player = (Player) e.getEntity();
if (!isInCombat(player)) {
return;
}
PotionEffectType potionEffectType = e.getModifiedType();
if (isBlocked(potionEffectType)) {
e.setCancelled(true);
}
}
private @NotNull IPotionConfiguration getPotionConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getPotionConfiguration();
}
private boolean isBlocked(@NotNull PotionEffectType effectType) {
IPotionConfiguration potionConfiguration = getPotionConfiguration();
return potionConfiguration.isBlocked(effectType);
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/task/ElytraRetagTask.java
================================================
package combatlogx.expansion.cheat.prevention.task;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.folia.details.TaskDetails;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.api.utility.Validate;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IItemConfiguration;
public final class ElytraRetagTask extends TaskDetails {
private final ICheatPreventionExpansion expansion;
public ElytraRetagTask(@NotNull ICheatPreventionExpansion expansion) {
super(expansion.getExpansion().getPlugin().getPlugin());
this.expansion = Validate.notNull(expansion, "expansion must not be null!");
}
@Override
public void run() {
IItemConfiguration itemConfiguration = getItemConfiguration();
if (itemConfiguration.isElytraRetag()) {
run0();
}
}
private void run0() {
ICombatLogX combatLogX = getCombatLogX();
ICombatManager combatManager = combatLogX.getCombatManager();
List playerList = combatManager.getPlayersInCombat();
for (Player player : playerList) {
if (player.isGliding()) {
combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
}
}
}
public void register() {
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
setDelay(10L);
setPeriod(10L);
scheduler.scheduleTask(this);
}
private @NotNull ICheatPreventionExpansion getCheatPrevention() {
return this.expansion;
}
private @NotNull IItemConfiguration getItemConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getItemConfiguration();
}
private @NotNull Expansion getExpansion() {
ICheatPreventionExpansion cheatPrevention = getCheatPrevention();
return cheatPrevention.getExpansion();
}
private @NotNull ICombatLogX getCombatLogX() {
Expansion expansion = getExpansion();
return expansion.getPlugin();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/java/combatlogx/expansion/cheat/prevention/task/FlightRetagTask.java
================================================
package combatlogx.expansion.cheat.prevention.task;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.folia.details.TaskDetails;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import combatlogx.expansion.cheat.prevention.ICheatPreventionExpansion;
import combatlogx.expansion.cheat.prevention.configuration.IFlightConfiguration;
public final class FlightRetagTask extends TaskDetails {
private final ICheatPreventionExpansion expansion;
public FlightRetagTask(@NotNull ICheatPreventionExpansion expansion) {
super(expansion.getExpansion().getPlugin().getPlugin());
this.expansion = expansion;
}
@Override
public void run() {
IFlightConfiguration flightConfiguration = getFlightConfiguration();
if (flightConfiguration.isFlightRetag()) {
run0();
}
}
private void run0() {
ICombatLogX combatLogX = getCombatLogX();
ICombatManager combatManager = combatLogX.getCombatManager();
List playerList = combatManager.getPlayersInCombat();
for (Player player : playerList) {
if (player.isFlying()) {
combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
}
}
}
public void register() {
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
setDelay(10L);
setPeriod(10L);
scheduler.scheduleTask(this);
}
private @NotNull ICheatPreventionExpansion getCheatPrevention() {
return this.expansion;
}
private @NotNull IFlightConfiguration getFlightConfiguration() {
ICheatPreventionExpansion expansion = getCheatPrevention();
return expansion.getFlightConfiguration();
}
private @NotNull Expansion getExpansion() {
ICheatPreventionExpansion cheatPrevention = getCheatPrevention();
return cheatPrevention.getExpansion();
}
private @NotNull ICombatLogX getCombatLogX() {
Expansion expansion = getExpansion();
return expansion.getPlugin();
}
}
================================================
FILE: expansion/cheat-prevention/src/main/resources/blocks.yml
================================================
# Should players be prevented from interacting with blocks during combat?
# Default: false
prevent-interaction: false
# This is a list of blocks that players should not interact with during combat.
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block interactions.
prevent-interaction-list:
- "*"
# Should players be prevented from breaking blocks during combat?
# Default: true
prevent-breaking: true
# This is a list of blocks that should be prevented from breaking
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block breaking
prevent-breaking-list:
- "*"
# Should players be prevented from placing blocks during combat?
# Default: true
prevent-placing: true
# This is a list of blocks that should be prevented from placing
# Spigot Material List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
# This defaults to prevent all block placing
prevent-placing-list:
- "*"
# Should players be prevented from creating portals during combat?
# This option only works in 1.14.4+
# Default: false
prevent-portal-creation: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/buckets.yml
================================================
# Should players be prevented from emptying buckets during combat?
# Default: false
prevent-bucket-empty: false
# Should players be prevented from filling buckets during combat?
# Default: false
prevent-bucket-fill: false
# Which bucket types cannot be emptied during combat?
# Requires 'prevent-bucket-empty: true'
# Use '*' for all bucket types.
# Use XMaterial names for custom types:
# https://github.com/CryptoMorin/XSeries/blob/master/src/main/java/com/cryptomorin/xseries/XMaterial.java
prevent-bucket-empty-list:
- "*"
# Which bucket types cannot be filled during combat?
# Requires 'prevent-bucket-fill: true'
# Use '*' for all bucket types.
# Use XMaterial names for custom types:
# https://github.com/CryptoMorin/XSeries/blob/master/src/main/java/com/cryptomorin/xseries/XMaterial.java
prevent-bucket-fill-list:
- "LAVA_BUCKET"
================================================
FILE: expansion/cheat-prevention/src/main/resources/chat.yml
================================================
# Should players be prevented from typing in chat during combat?
# Default: false
disable-chat: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/commands.yml
================================================
# How much time do players have to wait to run commands AFTER the combat timer has ended?
# The time is in seconds
# Default: 0
delay-after-combat: 0
# Which commands are blocked during combat?
# DO NOT forget the `/` in front of the commands.
# You can add "*" to the list to block ALL commands.
blocked-command-list:
- "/tp"
- "/fly"
- "/gamemode"
- "/gm"
- "//wand"
- "/spawn"
- "/home"
- "/sethome"
- "/msg"
# Which commands are allowed during combat?
# This list is used if you want to un-block a command that is blocked the the other list.
# You can add "*" to the list to allow ALL commands.
#
# Extra Information: This list overrides the blocked command list
allowed-command-list:
- "/msg SirBlobman"
# Players with this permission will have every command unblocked.
# The permission is not given to OPs by default, you must set it manually.
bypass-permission: "combatlogx.bypass.cheat.prevention.commands"
================================================
FILE: expansion/cheat-prevention/src/main/resources/config.yml
================================================
# How long should the expansion wait before sending the same message again?
# Default: 30 (seconds)
message-cooldown: 30
================================================
FILE: expansion/cheat-prevention/src/main/resources/entities.yml
================================================
# Should players be prevented from right-clicking entities during combat?
# Default: false
prevent-interaction: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.cheat.prevention.CheatPreventionExpansion"
version: "17.10"
author: "SirBlobman"
================================================
FILE: expansion/cheat-prevention/src/main/resources/flight.yml
================================================
# Should players be prevented from flying during combat?
# Default: true
prevent-flying: true
# If a players flight is deactivated by CombatLogX, should the plugin prevent them from taking fall damage?
# The fall damage prevention only works once after flight is disabled.
# Default: true
prevent-fall-damage: true
# Should the 'allow-flight' flag be set to false on a player?
# This may prevent toggle spam but players won't be able to fly after combat ends.
# Default: false
force-disable-flight: false
# Should flying cause a player's timer to reset during combat?
# This option is not useful unless you set 'prevent-flying' and 'force-disable-flight' to 'false'.
# Default: false
flight-retag: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/game-mode.yml
================================================
# Should players be prevented from changing game modes during combat?
# Default: true
prevent-switching: true
# If 'prevent-switching' is false, should players be untagged when they change modes?
# Default: false
untag-on-switch: false
# Should players be forced into a specific game mode when they get into combat?
# Default: false
force-switch: false
# If 'force-switch' is enabled, which mode should be used?
# Valid options can be found in the link below:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/GameMode.html
force-mode: SURVIVAL
================================================
FILE: expansion/cheat-prevention/src/main/resources/inventories.yml
================================================
# Should CombatLogX close a player's inventory when they are first tagged into combat?
# Default: true
close: true
# Should CombatLogX close a player's inventory when they are tagged while already in combat?
close-on-retag: true
# Which inventory types should not trigger an inventory closed message?
# To the server, a player always has an inventory open, even if its just the hotbar.
no-close-message-type-list:
- CREATIVE
- CRAFTING
# Should CombatLogX prevent players from opening new inventories while they are tagged?
# This does not affect client-side-only inventories.
# Default: true
prevent-opening: true
================================================
FILE: expansion/cheat-prevention/src/main/resources/items.yml
================================================
# Should players be prevented from dropping items during combat?
# Default: true
prevent-drop: true
# Should players be prevented from picking up items during combat?
# Default: false
prevent-pickup: true
# Should players be prevented from using Elytra during combat?
# Default: true
prevent-elytra: true
# Should player's that are gliding have their elytra forcefully disabled when tagged?
# Default: false
force-prevent-elytra: false
# Should CombatLogX prevent players from launching fireworks during combat?
# This can be used as an alternative to allow gliding but prevent rocket-based flight.
# Default: false
prevent-fireworks: false
# Should gliding cause a player's timer to reset during combat?
# This option is not useful unless you set 'prevent-elytra' and 'force-prevent-elytra' to 'false'.
# Default: false
elytra-retag: false
# Should players be prevented from using Totems of Undying during combat?
# Default: false
prevent-totem: false
# Should players be prevented from using tridents with the riptide enchantment during combat?
# Default: false
prevent-riptide: false
# Should players that use tridents and the riptide effect increase the combat timer?
# May conflict if both 'prevent-riptide' and 'riptide-retag' are enabled.
# Default: false
riptide-retag: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/potions.yml
================================================
# This is a list of potion effects that will be removed when a player is tagged.
# You can find a list of valid potion types in the link below:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
# You can unblock all potion effects by setting the value of this list to []
# Example: 'blocked-potion-type-list: []'
blocked-potion-type-list:
- INCREASE_DAMAGE
- INVISIBILITY
# Set this to 'true' to turn the 'blocked' list to an 'allowed' list.
blocked-potion-type-list-inverted: false
================================================
FILE: expansion/cheat-prevention/src/main/resources/teleportation.yml
================================================
# Should players be prevented from using nether/end portals during combat?
# Default: true
prevent-portals: true
# Should players be prevented from teleporting away during combat?
# Default: true
prevent-teleportation: true
# Are there any reasons that a teleport should not be cancelled?
# You can find a list of valid values in the link below:
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html
allowed-teleport-cause-list:
- PLUGIN # Some plugins don't like when CombatLogX cancels their teleports
- UNKNOWN # Allowing 'UNKNOWN' may fix some glitches with region protection plugins
- ENDER_PEARL # Most servers think that ender pearls are fair game during combat.
# Should ender pearls cause a player's timer to reset during combat?
# The combat type and combat reason will be marked as UNKNOWN.
# Default: false
ender-pearl-retag: false
# This option is required for Folia servers.
# This enables a separate listener for ender pearls, separate from PlayerTeleportEvent.
# Disabled by default since ender pearls are allowed by most servers.
# Default: false
force-disable-ender-pearl: false
# If a player teleports away, should their tag be removed?
# Default: false
untag: false
================================================
FILE: expansion/compatibility/ASkyBlock/build.gradle.kts
================================================
repositories {
maven("https://repo.codemc.io/repository/maven-public/")
}
dependencies {
compileOnly("com.wasteofplastic:askyblock:3.0.9.4")
}
================================================
FILE: expansion/compatibility/ASkyBlock/gradle.properties
================================================
expansion.name=CompatASkyBlock
expansion.prefix=ASkyBlock Compatibility
================================================
FILE: expansion/compatibility/ASkyBlock/src/main/java/combatlogx/expansion/compatibility/askyblock/ASkyBlockExpansion.java
================================================
package combatlogx.expansion.compatibility.askyblock;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.compatibility.askyblock.listener.ListenerASkyBlock;
public final class ASkyBlockExpansion extends Expansion {
public ASkyBlockExpansion(ICombatLogX plugin) {
super(plugin);
}
@Override
public void onLoad() {
// Do Nothing
}
@Override
public void onEnable() {
if (!checkDependency("ASkyBlock", true)) {
selfDisable();
}
new ListenerASkyBlock(this).register();
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
// Do Nothing
}
}
================================================
FILE: expansion/compatibility/ASkyBlock/src/main/java/combatlogx/expansion/compatibility/askyblock/listener/ListenerASkyBlock.java
================================================
package combatlogx.expansion.compatibility.askyblock.listener;
import java.util.List;
import java.util.UUID;
import org.jetbrains.annotations.Nullable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.github.sirblobman.combatlogx.api.event.PlayerPreTagEvent;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island;
public final class ListenerASkyBlock extends ExpansionListener {
public ListenerASkyBlock(Expansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void beforeTag(PlayerPreTagEvent e) {
Entity enemy = e.getEnemy();
if (!(enemy instanceof Player)) {
return;
}
Player playerEnemy = (Player) enemy;
Player player = e.getPlayer();
if (doesTeamMatch(player, playerEnemy)) {
e.setCancelled(true);
}
}
@Nullable
private Island getIsland(Player player) {
if (player == null) {
return null;
}
UUID playerId = player.getUniqueId();
ASkyBlockAPI api = ASkyBlockAPI.getInstance();
return api.getIslandOwnedBy(playerId);
}
private boolean doesTeamMatch(Player player1, Player player2) {
UUID playerId1 = player1.getUniqueId();
UUID playerId2 = player2.getUniqueId();
if (playerId1.equals(playerId2)) {
return true;
}
Island island = getIsland(player1);
if (island == null) {
return false;
}
List memberIdList = island.getMembers();
return memberIdList.contains(playerId2);
}
}
================================================
FILE: expansion/compatibility/ASkyBlock/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.askyblock.ASkyBlockExpansion"
version: "17.0"
author: "SirBlobman"
plugin-depend:
- "ASkyBlock"
================================================
FILE: expansion/compatibility/AngelChest/build.gradle.kts
================================================
repositories {
maven("https://nexus.sirblobman.xyz/proxy-public")
}
dependencies {
compileOnly("de.jeff_media:AngelChest:13.9.4")
}
================================================
FILE: expansion/compatibility/AngelChest/gradle.properties
================================================
expansion.name=CompatAngelChest
expansion.prefix=AngelChest Compatibility
================================================
FILE: expansion/compatibility/AngelChest/src/main/java/combatlogx/expansion/compatibility/angelchest/AngelChestConfiguration.java
================================================
package combatlogx.expansion.compatibility.angelchest;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.configuration.IConfigurable;
public class AngelChestConfiguration implements IConfigurable {
private boolean preventBreaking;
private boolean preventOpening;
private boolean preventFastLooting;
public AngelChestConfiguration() {
this.preventBreaking = true;
this.preventOpening = true;
this.preventFastLooting = true;
}
@Override
public void load(@NotNull ConfigurationSection section) {
setPreventBreaking(section.getBoolean("prevent-breaking", true));
setPreventOpening(section.getBoolean("prevent-opening", true));
setPreventFastLooting(section.getBoolean("prevent-fast-looting", true));
}
public boolean isPreventBreaking() {
return this.preventBreaking;
}
public void setPreventBreaking(boolean preventBreaking) {
this.preventBreaking = preventBreaking;
}
public boolean isPreventOpening() {
return this.preventOpening;
}
public void setPreventOpening(boolean preventOpening) {
this.preventOpening = preventOpening;
}
public boolean isPreventFastLooting() {
return this.preventFastLooting;
}
public void setPreventFastLooting(boolean preventFastLooting) {
this.preventFastLooting = preventFastLooting;
}
}
================================================
FILE: expansion/compatibility/AngelChest/src/main/java/combatlogx/expansion/compatibility/angelchest/AngelChestExpansion.java
================================================
package combatlogx.expansion.compatibility.angelchest;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.api.configuration.ConfigurationManager;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
public final class AngelChestExpansion extends Expansion {
private final AngelChestConfiguration configuration;
public AngelChestExpansion(ICombatLogX plugin) {
super(plugin);
this.configuration = new AngelChestConfiguration();
}
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("config.yml");
}
@Override
public void onEnable() {
if (!checkDependency("AngelChest", true)) {
selfDisable();
return;
}
reloadConfig();
new ListenerAngelChest(this).register();
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("config.yml");
getConfiguration().load(configurationManager.get("config.yml"));
}
public @NotNull AngelChestConfiguration getConfiguration() {
return this.configuration;
}
}
================================================
FILE: expansion/compatibility/AngelChest/src/main/java/combatlogx/expansion/compatibility/angelchest/ListenerAngelChest.java
================================================
package combatlogx.expansion.compatibility.angelchest;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import de.jeff_media.angelchest.events.AngelChestOpenEvent;
import de.jeff_media.angelchest.events.AngelChestOpenEvent.Reason;
public final class ListenerAngelChest extends ExpansionListener {
private final AngelChestExpansion expansion;
public ListenerAngelChest(@NotNull AngelChestExpansion expansion) {
super(expansion);
this.expansion = expansion;
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onAngelChestOpen(AngelChestOpenEvent e) {
Player player = e.getPlayer();
if (!isInCombat(player)) {
return;
}
Reason reason = e.getReason();
switch (reason) {
case BREAK:
checkBreaking(player, e);
break;
case OPEN_GUI:
checkOpening(player, e);
break;
case FAST_LOOT:
checkFastLooting(player, e);
break;
default:
break;
}
}
private @NotNull AngelChestExpansion getAngelChestExpansion() {
return this.expansion;
}
private @NotNull AngelChestConfiguration getConfiguration() {
AngelChestExpansion expansion = getAngelChestExpansion();
return expansion.getConfiguration();
}
private void checkBreaking(Player player, Cancellable e) {
AngelChestConfiguration configuration = getConfiguration();
if (configuration.isPreventBreaking()) {
e.setCancelled(true);
LanguageManager languageManager = getLanguageManager();
languageManager.sendMessageWithPrefix(player, "expansion.angel-chest.prevent-breaking");
}
}
private void checkOpening(Player player, Cancellable e) {
AngelChestConfiguration configuration = getConfiguration();
if (configuration.isPreventOpening()) {
e.setCancelled(true);
LanguageManager languageManager = getLanguageManager();
languageManager.sendMessageWithPrefix(player, "expansion.angel-chest.prevent-opening");
}
}
private void checkFastLooting(Player player, Cancellable e) {
AngelChestConfiguration configuration = getConfiguration();
if (configuration.isPreventFastLooting()) {
e.setCancelled(true);
LanguageManager languageManager = getLanguageManager();
languageManager.sendMessageWithPrefix(player, "expansion.angel-chest.prevent-fast-looting");
}
}
}
================================================
FILE: expansion/compatibility/AngelChest/src/main/resources/config.yml
================================================
# Should CombatLogX prevent players from breaking AngelChests during combat?
# Default: true
prevent-breaking: true
# Should CombatLogX prevent players from opening AngelChests during combat?
# Default: true
prevent-opening: true
# Should CombatLogX prevent players from fast looting AngelChests during combat?
# Default: true
prevent-fast-looting: true
================================================
FILE: expansion/compatibility/AngelChest/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.angelchest.AngelChestExpansion"
version: "17.2"
author: "olivolja3"
plugin-depend:
- "AngelChest"
================================================
FILE: expansion/compatibility/BSkyBlock/build.gradle.kts
================================================
repositories {
maven("https://repo.codemc.io/repository/bentoboxworld/")
maven("https://repo.codemc.io/repository/maven-snapshots/")
maven("https://repo.codemc.io/repository/maven-public/")
}
dependencies {
compileOnly("world.bentobox:bentobox:3.3.5-SNAPSHOT") // BentoBox
compileOnly("world.bentobox:bskyblock:1.19.1-SNAPSHOT") // BSkyBlock
}
================================================
FILE: expansion/compatibility/BSkyBlock/gradle.properties
================================================
expansion.name=CompatBSkyBlock
expansion.prefix=BSkyBlock Compatibility
================================================
FILE: expansion/compatibility/BSkyBlock/src/main/java/combatlogx/expansion/compatibility/bskyblock/BSkyBlockExpansion.java
================================================
package combatlogx.expansion.compatibility.bskyblock;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.compatibility.bskyblock.hook.HookBentoBox;
import combatlogx.expansion.compatibility.bskyblock.listener.ListenerBSkyBlock;
public final class BSkyBlockExpansion extends Expansion {
public BSkyBlockExpansion(ICombatLogX plugin) {
super(plugin);
}
@Override
public void onLoad() {
// Do Nothing
}
@Override
public void onEnable() {
if (!checkDependency("BentoBox", true)) {
selfDisable();
return;
}
if (!HookBentoBox.findBSkyBlock(this)) {
selfDisable();
return;
}
new ListenerBSkyBlock(this).register();
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
// Do Nothing
}
}
================================================
FILE: expansion/compatibility/BSkyBlock/src/main/java/combatlogx/expansion/compatibility/bskyblock/hook/HookBentoBox.java
================================================
package combatlogx.expansion.compatibility.bskyblock.hook;
import java.util.Locale;
import java.util.Optional;
import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;
import combatlogx.expansion.compatibility.bskyblock.BSkyBlockExpansion;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.managers.AddonsManager;
public final class HookBentoBox {
public static boolean findBSkyBlock(BSkyBlockExpansion expansion) {
Logger logger = expansion.getLogger();
logger.info("Checking BentoBox for BSkyBlock...");
BentoBox bentoBox = JavaPlugin.getPlugin(BentoBox.class);
AddonsManager addonsManager = bentoBox.getAddonsManager();
Optional optionalAddon = addonsManager.getAddonByName("BSkyBlock");
if (optionalAddon.isEmpty()) {
logger.info("Failed to find BSkyBlock in BentoBox.");
return false;
}
Addon addon = optionalAddon.get();
AddonDescription description = addon.getDescription();
String addonName = description.getName();
String addonVersion = description.getVersion();
String message = String.format(Locale.US, "Successfully found a dependency: %s v%s", addonName,
addonVersion);
logger.info(message);
return true;
}
}
================================================
FILE: expansion/compatibility/BSkyBlock/src/main/java/combatlogx/expansion/compatibility/bskyblock/listener/ListenerBSkyBlock.java
================================================
package combatlogx.expansion.compatibility.bskyblock.listener;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.java.JavaPlugin;
import com.github.sirblobman.combatlogx.api.event.PlayerPreTagEvent;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.IslandsManager;
public final class ListenerBSkyBlock extends ExpansionListener {
public ListenerBSkyBlock(Expansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void beforeTag(PlayerPreTagEvent e) {
Entity enemy = e.getEnemy();
if (!(enemy instanceof Player playerEnemy)) {
return;
}
Player player = e.getPlayer();
if (doesTeamMatch(player, playerEnemy)) {
e.setCancelled(true);
}
}
private Island getIsland(Player player) {
if (player == null) {
return null;
}
UUID playerId = player.getUniqueId();
World world = player.getWorld();
BentoBox bentoBox = JavaPlugin.getPlugin(BentoBox.class);
AddonsManager addonsManager = bentoBox.getAddonsManager();
Optional optionalAddon = addonsManager.getAddonByName("BSkyBlock");
if (optionalAddon.isPresent()) {
Addon addon = optionalAddon.get();
IslandsManager islandManager = addon.getIslands();
return islandManager.getIsland(world, playerId);
}
return null;
}
private boolean doesTeamMatch(Player player1, Player player2) {
World world1 = player1.getWorld();
World world2 = player2.getWorld();
UUID worldId1 = world1.getUID();
UUID worldId2 = world2.getUID();
if (!worldId1.equals(worldId2)) {
return false;
}
UUID playerId1 = player1.getUniqueId();
UUID playerId2 = player2.getUniqueId();
if (playerId1.equals(playerId2)) {
return true;
}
Island island = getIsland(player1);
if (island == null) {
return false;
}
Set memberSet = island.getMemberSet();
return memberSet.contains(playerId2);
}
}
================================================
FILE: expansion/compatibility/BSkyBlock/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.bskyblock.BSkyBlockExpansion"
version: "17.3"
author: "SirBlobman"
plugin-depend:
- "BentoBox"
================================================
FILE: expansion/compatibility/CMI/build.gradle.kts
================================================
dependencies {
compileOnly("net.zrips:CMI-API:9.7.4.1")
}
================================================
FILE: expansion/compatibility/CMI/gradle.properties
================================================
expansion.name=CompatCMI
expansion.prefix=CMI Compatibility
================================================
FILE: expansion/compatibility/CMI/src/main/java/combatlogx/expansion/compatibility/cmi/CMIExpansion.java
================================================
package combatlogx.expansion.compatibility.cmi;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.vanish.VanishExpansion;
import com.github.sirblobman.combatlogx.api.expansion.vanish.VanishHandler;
public final class CMIExpansion extends VanishExpansion {
private VanishHandler> vanishHandler;
public CMIExpansion(@NotNull ICombatLogX plugin) {
super(plugin);
this.vanishHandler = null;
}
@Override
public boolean checkDependencies() {
return checkDependency("CMI", true, "9");
}
@Override
public @NotNull VanishHandler> getVanishHandler() {
if (this.vanishHandler == null) {
this.vanishHandler = new VanishHandlerCMI(this);
}
return this.vanishHandler;
}
}
================================================
FILE: expansion/compatibility/CMI/src/main/java/combatlogx/expansion/compatibility/cmi/VanishHandlerCMI.java
================================================
package combatlogx.expansion.compatibility.cmi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.entity.Player;
import com.github.sirblobman.combatlogx.api.expansion.vanish.VanishHandler;
import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Containers.CMIUser;
import com.Zrips.CMI.PlayerManager;
public final class VanishHandlerCMI extends VanishHandler {
public VanishHandlerCMI(@NotNull CMIExpansion expansion) {
super(expansion);
}
@Override
public boolean isVanished(@NotNull Player player) {
CMIUser user = getUser(player);
return (user != null && user.isVanished());
}
private @NotNull CMI getCMI() {
return CMI.getInstance();
}
private @NotNull PlayerManager getPlayerManager() {
CMI cmi = getCMI();
return cmi.getPlayerManager();
}
private @Nullable CMIUser getUser(@NotNull Player player) {
PlayerManager playerManager = getPlayerManager();
return playerManager.getUser(player);
}
}
================================================
FILE: expansion/compatibility/CMI/src/main/resources/config.yml
================================================
# Should players in vanish be preventing from going into combat?
prevent-vanish-tagging-self: true
# Should players in vanish be unable to tag other players?
prevent-vanish-tagging-other: true
================================================
FILE: expansion/compatibility/CMI/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.cmi.CMIExpansion"
version: "17.1"
author: "SirBlobman"
plugin-depend:
- "CMI"
================================================
FILE: expansion/compatibility/Citizens/build.gradle.kts
================================================
repositories {
maven("https://nexus.sirblobman.xyz/proxy-public")
}
dependencies {
compileOnly("net.citizensnpcs:citizensapi:2.0.40-SNAPSHOT")
compileOnly("org.mcmonkey:sentinel:2.9.0-SNAPSHOT")
}
================================================
FILE: expansion/compatibility/Citizens/gradle.properties
================================================
version.spigot=1.13.2-R0.1-SNAPSHOT
expansion.name=CompatCitizens
expansion.prefix=Citizens Compatibility
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/CitizensExpansion.java
================================================
package combatlogx.expansion.compatibility.citizens;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.github.sirblobman.api.configuration.ConfigurationManager;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.configuration.Configuration;
import combatlogx.expansion.compatibility.citizens.configuration.SentinelConfiguration;
import combatlogx.expansion.compatibility.citizens.listener.ListenerCombat;
import combatlogx.expansion.compatibility.citizens.listener.ListenerConvert;
import combatlogx.expansion.compatibility.citizens.listener.ListenerDeath;
import combatlogx.expansion.compatibility.citizens.listener.ListenerJoin;
import combatlogx.expansion.compatibility.citizens.listener.ListenerPunish;
import combatlogx.expansion.compatibility.citizens.listener.ListenerQuit;
import combatlogx.expansion.compatibility.citizens.listener.ListenerResurrect;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import combatlogx.expansion.compatibility.citizens.manager.InventoryManager;
public final class CitizensExpansion extends Expansion {
private static final List SUPPORTED_VERSION_LIST;
static {
SUPPORTED_VERSION_LIST = Arrays.asList("2.0.35", "2.0.36", "2.0.37", "2.0.38", "2.0.39", "2.0.40");
}
private final Configuration configuration;
private final CitizensConfiguration citizensConfiguration;
private final SentinelConfiguration sentinelConfiguration;
private final CombatNpcManager combatNpcManager;
private final InventoryManager inventoryManager;
public CitizensExpansion(@NotNull ICombatLogX plugin) {
super(plugin);
this.configuration = new Configuration();
this.citizensConfiguration = new CitizensConfiguration(this);
this.sentinelConfiguration = new SentinelConfiguration(this);
this.combatNpcManager = new CombatNpcManager(this);
this.inventoryManager = new InventoryManager(this);
}
@Override
public void onLoad() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.saveDefault("config.yml");
configurationManager.saveDefault("citizens.yml");
configurationManager.saveDefault("sentinel.yml");
}
@Override
public void onEnable() {
if (!checkDependency("Citizens", true)) {
selfDisable();
return;
}
Logger logger = getLogger();
PluginManager pluginManager = Bukkit.getPluginManager();
Plugin citizens = pluginManager.getPlugin("Citizens");
if (citizens == null) {
logger.info("Dependency 'Citizens' not enabled.");
selfDisable();
return;
}
String citizensVersion = citizens.getDescription().getVersion();
if (!isCitizensSupported(citizensVersion)) {
logger.info("Dependency 'Citizens' is not the correct version.");
selfDisable();
return;
}
reloadConfig();
registerListeners();
}
@Override
public void onDisable() {
CombatNpcManager combatNpcManager = getCombatNpcManager();
combatNpcManager.removeAll();
}
@Override
public void reloadConfig() {
ConfigurationManager configurationManager = getConfigurationManager();
configurationManager.reload("config.yml");
configurationManager.reload("citizens.yml");
configurationManager.reload("sentinel.yml");
getConfiguration().load(configurationManager.get("config.yml"));
getCitizensConfiguration().load(configurationManager.get("citizens.yml"));
getSentinelConfiguration().load(configurationManager.get("sentinel.yml"));
}
public @NotNull CombatNpcManager getCombatNpcManager() {
return this.combatNpcManager;
}
public @NotNull InventoryManager getInventoryManager() {
return this.inventoryManager;
}
public boolean isSentinelEnabled() {
Configuration configuration = getConfiguration();
SentinelConfiguration sentinelConfiguration = getSentinelConfiguration();
return (configuration.isEnableSentinel() && sentinelConfiguration.isSentinelPluginEnabled());
}
private void registerListeners() {
new ListenerCombat(this).register();
new ListenerDeath(this).register();
new ListenerJoin(this).register();
new ListenerPunish(this).register();
new ListenerQuit(this).register();
// Totem of Undying was added in 1.11.
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion >= 11) {
new ListenerResurrect(this).register();
}
// EntityTransformEvent was added in 1.13
if (minorVersion >= 13) {
new ListenerConvert(this).register();
}
}
private boolean isCitizensSupported(@NotNull String version) {
for(String start : SUPPORTED_VERSION_LIST) {
if(version.startsWith(start)) {
return true;
}
}
return false;
}
public @NotNull Configuration getConfiguration() {
return this.configuration;
}
public @NotNull CitizensConfiguration getCitizensConfiguration() {
return this.citizensConfiguration;
}
public @NotNull SentinelConfiguration getSentinelConfiguration() {
return this.sentinelConfiguration;
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/configuration/CitizensConfiguration.java
================================================
package combatlogx.expansion.compatibility.citizens.configuration;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.EntityType;
import com.github.sirblobman.api.configuration.IConfigurable;
import com.github.sirblobman.api.utility.Validate;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
public final class CitizensConfiguration implements IConfigurable {
private final CitizensExpansion expansion;
private boolean preventPunishments;
private boolean preventLogin;
private EntityType mobType;
private boolean storeInventory;
private boolean storeLocation;
private boolean mobTarget;
private double mobTargetRadius;
private int survivalTime;
private boolean stayUntilEnemyEscapes;
private boolean stayUntilNoDamage;
private boolean preventResurrect;
private boolean tagPlayer;
private boolean alwaysSpawnNpcOnQuit;
private String customNpcNameFormat;
public CitizensConfiguration(@NotNull CitizensExpansion expansion) {
this.expansion = expansion;
this.preventPunishments = true;
this.preventLogin = false;
this.mobType = EntityType.PLAYER;
this.storeInventory = true;
this.storeLocation = true;
this.mobTarget = true;
this.mobTargetRadius = 10.0D;
this.survivalTime = 30;
this.stayUntilEnemyEscapes = false;
this.stayUntilNoDamage = false;
this.preventResurrect = true;
this.tagPlayer = true;
this.alwaysSpawnNpcOnQuit = false;
this.customNpcNameFormat = "{player_name}";
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
private @NotNull Logger getLogger() {
CitizensExpansion expansion = getExpansion();
return expansion.getLogger();
}
@Override
public void load(ConfigurationSection config) {
setPreventPunishments(config.getBoolean("prevent-punishments", true));
setPreventLogin(config.getBoolean("prevent-login", false));
setMobType(config.getString("mob-type", "PLAYER"));
setStoreInventory(config.getBoolean("store-inventory", true));
setStoreLocation(config.getBoolean("store-location", true));
setMobTarget(config.getBoolean("mob-target", true));
setMobTargetRadius(config.getDouble("mob-target-radius", 10.0D));
setSurvivalTime(config.getInt("survival-time", 30));
setStayUntilEnemyEscapes(config.getBoolean("stay-until-enemy-escapes", false));
setStayUntilNoDamage(config.getBoolean("stay-until-no-damage", false));
setPreventResurrect(config.getBoolean("prevent-resurrect", true));
setTagPlayer(config.getBoolean("tag-player", true));
setAlwaysSpawnNpcOnQuit(config.getBoolean("always-spawn-npc-on-quit", false));
setCustomNpcNameFormat(config.getString("custom-npc-name", "{player_name}"));
}
public boolean isPreventPunishments() {
return preventPunishments;
}
public void setPreventPunishments(boolean preventPunishments) {
this.preventPunishments = preventPunishments;
}
public boolean isPreventLogin() {
return preventLogin;
}
public void setPreventLogin(boolean preventLogin) {
this.preventLogin = preventLogin;
}
public @NotNull EntityType getMobType() {
return mobType;
}
public void setMobType(@NotNull EntityType mobType) {
this.mobType = mobType;
}
private void setMobType(@Nullable String mobTypeName) {
if (mobTypeName == null) {
mobTypeName = "PLAYER";
}
try {
EntityType mobType = EntityType.valueOf(mobTypeName);
if (!mobType.isAlive()) {
Logger logger = getLogger();
logger.warning("'" + mobType + "' is a non-living value, default to PLAYER.");
setMobType(EntityType.PLAYER);
return;
}
setMobType(mobType);
} catch (IllegalArgumentException ex) {
Logger logger = getLogger();
logger.warning("'" + mobTypeName + "' is not a valid EntityType.");
logger.warning("Defaulting to PLAYER.");
setMobType(EntityType.PLAYER);
}
}
public boolean isStoreInventory() {
return storeInventory;
}
public void setStoreInventory(boolean storeInventory) {
this.storeInventory = storeInventory;
}
public boolean isStoreLocation() {
return storeLocation;
}
public void setStoreLocation(boolean storeLocation) {
this.storeLocation = storeLocation;
}
public boolean isMobTarget() {
return mobTarget;
}
public void setMobTarget(boolean mobTarget) {
this.mobTarget = mobTarget;
}
public double getMobTargetRadius() {
return mobTargetRadius;
}
public void setMobTargetRadius(double mobTargetRadius) {
this.mobTargetRadius = mobTargetRadius;
}
public int getSurvivalTime() {
return survivalTime;
}
public void setSurvivalTime(int survivalTime) {
this.survivalTime = survivalTime;
}
public boolean isStayUntilEnemyEscapes() {
return stayUntilEnemyEscapes;
}
public void setStayUntilEnemyEscapes(boolean stayUntilEnemyEscapes) {
this.stayUntilEnemyEscapes = stayUntilEnemyEscapes;
}
public boolean isStayUntilNoDamage() {
return stayUntilNoDamage;
}
public void setStayUntilNoDamage(boolean stayUntilNoDamage) {
this.stayUntilNoDamage = stayUntilNoDamage;
}
public boolean isPreventResurrect() {
return preventResurrect;
}
public void setPreventResurrect(boolean preventResurrect) {
this.preventResurrect = preventResurrect;
}
public boolean isTagPlayer() {
return tagPlayer;
}
public void setTagPlayer(boolean tagPlayer) {
this.tagPlayer = tagPlayer;
}
public boolean isAlwaysSpawnNpcOnQuit() {
return alwaysSpawnNpcOnQuit;
}
public void setAlwaysSpawnNpcOnQuit(boolean alwaysSpawnNpcOnQuit) {
this.alwaysSpawnNpcOnQuit = alwaysSpawnNpcOnQuit;
}
public @NotNull String getCustomNpcNameFormat() {
return customNpcNameFormat;
}
public void setCustomNpcNameFormat(@Nullable String customNpcNameFormat) {
Validate.notEmpty(customNpcNameFormat, "customNpcNameFormat must not be null or empty!");
this.customNpcNameFormat = customNpcNameFormat;
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/configuration/Configuration.java
================================================
package combatlogx.expansion.compatibility.citizens.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.ConfigurationSection;
import com.github.sirblobman.api.configuration.IConfigurable;
public final class Configuration implements IConfigurable {
private boolean npcTagging;
private boolean enableSentinel;
public Configuration() {
this.npcTagging = false;
this.enableSentinel = true;
}
@Override
public void load(@NotNull ConfigurationSection config) {
setNpcTagging(config.getBoolean("npc-tagging", false));
setEnableSentinel(config.getBoolean("enable-sentinel", true));
}
public boolean isNpcTagging() {
return this.npcTagging;
}
public void setNpcTagging(boolean npcTagging) {
this.npcTagging = npcTagging;
}
public boolean isEnableSentinel() {
return this.enableSentinel;
}
public void setEnableSentinel(boolean enableSentinel) {
this.enableSentinel = enableSentinel;
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/configuration/SentinelConfiguration.java
================================================
package combatlogx.expansion.compatibility.citizens.configuration;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.PluginManager;
import com.github.sirblobman.api.configuration.IConfigurable;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
public final class SentinelConfiguration implements IConfigurable {
private final CitizensExpansion expansion;
private boolean attackFirst;
private transient boolean sentinelPluginEnabled;
public SentinelConfiguration(@NotNull CitizensExpansion expansion) {
this.expansion = expansion;
this.attackFirst = false;
this.sentinelPluginEnabled = false;
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
@Override
public void load(@NotNull ConfigurationSection config) {
setAttackFirst(config.getBoolean("attack-first", false));
CitizensExpansion expansion = getExpansion();
Configuration configuration = expansion.getConfiguration();
if (configuration.isEnableSentinel()) {
PluginManager pluginManager = Bukkit.getPluginManager();
this.sentinelPluginEnabled = pluginManager.isPluginEnabled("Sentinel");
} else {
this.sentinelPluginEnabled = false;
}
}
public boolean isAttackFirst() {
return this.attackFirst;
}
public void setAttackFirst(boolean attackFirst) {
this.attackFirst = attackFirst;
}
public boolean isSentinelPluginEnabled() {
return this.sentinelPluginEnabled;
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/CitizensExpansionListener.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.entity.Entity;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.configuration.Configuration;
import combatlogx.expansion.compatibility.citizens.configuration.SentinelConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import combatlogx.expansion.compatibility.citizens.manager.InventoryManager;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
public abstract class CitizensExpansionListener extends ExpansionListener {
private final CitizensExpansion expansion;
public CitizensExpansionListener(@NotNull CitizensExpansion expansion) {
super(expansion);
this.expansion = expansion;
}
protected final @NotNull CitizensExpansion getCitizensExpansion() {
return this.expansion;
}
protected final @NotNull Configuration getConfiguration() {
CitizensExpansion expansion = getCitizensExpansion();
return expansion.getConfiguration();
}
protected final @NotNull CitizensConfiguration getCitizensConfiguration() {
CitizensExpansion expansion = getCitizensExpansion();
return expansion.getCitizensConfiguration();
}
protected final @NotNull SentinelConfiguration getSentinelConfiguration() {
CitizensExpansion expansion = getCitizensExpansion();
return expansion.getSentinelConfiguration();
}
protected final @NotNull CombatNpcManager getCombatNpcManager() {
CitizensExpansion expansion = getCitizensExpansion();
return expansion.getCombatNpcManager();
}
protected final @NotNull InventoryManager getInventoryManager() {
CitizensExpansion expansion = getCitizensExpansion();
return expansion.getInventoryManager();
}
protected final @Nullable CombatNPC getCombatNPC(NPC npc) {
CombatNpcManager combatNpcManager = getCombatNpcManager();
return combatNpcManager.getCombatNPC(npc);
}
protected final @Nullable NPC getNPC(@NotNull Entity entity) {
NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
return npcRegistry.getNPC(entity);
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerCombat.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.github.sirblobman.combatlogx.api.event.PlayerPreTagEvent;
import com.github.sirblobman.combatlogx.api.utility.EntityHelper;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.Configuration;
public final class ListenerCombat extends CitizensExpansionListener {
public ListenerCombat(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void beforeTag(PlayerPreTagEvent e) {
printDebug("Detected PlayerPreTagEvent....");
Configuration configuration = getConfiguration();
if (configuration.isNpcTagging()) {
printDebug("NPC tagging is allowed, ignoring event.");
return;
}
Entity entity = e.getEnemy();
if (entity == null) {
printDebug("enemy is null, ignoring.");
return;
}
if (EntityHelper.isNPC(entity)) {
printDebug("enemy is an NPC, cancelling event.");
e.setCancelled(true);
}
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerConvert.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityTransformEvent;
import com.github.sirblobman.combatlogx.api.utility.EntityHelper;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import net.citizensnpcs.api.npc.NPC;
public final class ListenerConvert extends CitizensExpansionListener {
public ListenerConvert(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onConvert(EntityTransformEvent e) {
Entity entity = e.getEntity();
if (!EntityHelper.isNPC(entity)) {
return;
}
NPC npc = getNPC(entity);
if (npc == null) {
return;
}
CombatNPC combatNPC = getCombatNPC(npc);
if (combatNPC != null) {
e.setCancelled(true);
}
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerDeath.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import com.github.sirblobman.api.folia.details.RunnableTask;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import combatlogx.expansion.compatibility.citizens.manager.InventoryManager;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.npc.NPC;
public final class ListenerDeath extends CitizensExpansionListener {
public ListenerDeath(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDeathNPC(NPCDeathEvent e) {
printDebug("Detected NPCDeathEvent...");
NPC npc = e.getNPC();
CombatNPC combatNPC = getCombatNPC(npc);
if (combatNPC == null) {
printDebug("NPC was not a CombatNPC, ignoring event.");
return;
}
printDebug("Setting drops and exp to zero and sending custom death message.");
e.setDroppedExp(0);
e.getDrops().clear();
checkForDeathMessages(e, combatNPC);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDamageNPC(NPCDamageByEntityEvent e) {
printDebug("Detected NPCDamageByEntityEvent...");
CitizensConfiguration configuration = getCitizensConfiguration();
if (!configuration.isStayUntilNoDamage()) {
printDebug("Stay until no damage setting is not enabled, ignoring event.");
return;
}
NPC npc = e.getNPC();
CombatNPC combatNPC = getCombatNPC(npc);
if (combatNPC == null) {
printDebug("NPC was not a CombatNPC, ignoring event.");
return;
}
printDebug("Resetting NPC survival time.");
combatNPC.resetSurvivalTime();
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDespawnNPC(NPCDespawnEvent e) {
printDebug("Detected NPCDespawnEvent...");
DespawnReason despawnReason = e.getReason();
if (despawnReason == DespawnReason.PENDING_RESPAWN) {
printDebug("Despawn reason is PENDING_RESPAWN, ignoring event.");
return;
}
NPC npc = e.getNPC();
CombatNPC combatNPC = getCombatNPC(npc);
if (combatNPC == null) {
printDebug("NPC was not a CombatNPC, ignoring event.");
return;
}
CombatNpcManager combatNpcManager = getCombatNpcManager();
OfflinePlayer offlinePlayer = combatNPC.getOfflineOwner();
if (despawnReason == DespawnReason.DEATH) {
Location location = combatNpcManager.getLocation(npc);
printDebug("Despawn reason was death, drop NPC inventory.");
InventoryManager inventoryManager = getInventoryManager();
inventoryManager.dropInventory(offlinePlayer, location);
}
if (despawnReason != DespawnReason.REMOVAL) {
printDebug("Despawn reason was not removal, destroying NPC.");
combatNpcManager.remove(combatNPC);
printDebug("Destroy NPC later.");
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
scheduler.scheduleTask(new RunnableTask(getJavaPlugin(), npc::destroy));
}
printDebug("Setting player to be punished when they next join.");
YamlConfiguration data = combatNpcManager.getData(offlinePlayer);
data.set("citizens-compatibility.punish-next-join", true);
combatNpcManager.saveData(offlinePlayer);
}
private void checkForDeathMessages(@NotNull NPCDeathEvent e, @NotNull CombatNPC npc) {
OfflinePlayer offlineOwner = npc.getOfflineOwner();
EntityDeathEvent entityDeathEvent = e.getEvent();
if (!(entityDeathEvent instanceof PlayerDeathEvent playerDeathEvent)) {
return;
}
String message = playerDeathEvent.getDeathMessage();
CombatNpcManager combatNpcManager = getCombatNpcManager();
YamlConfiguration data = combatNpcManager.getData(offlineOwner);
data.set("citizens-compatibility.last-death-message", message);
combatNpcManager.saveData(offlineOwner);
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerJoin.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.player.PlayerJoinEvent;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.api.language.ComponentHelper;
import com.github.sirblobman.api.language.LanguageManager;
import com.github.sirblobman.api.shaded.adventure.text.Component;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import combatlogx.expansion.compatibility.citizens.task.PunishTask;
import net.citizensnpcs.api.npc.NPC;
public final class ListenerJoin extends CitizensExpansionListener {
public ListenerJoin(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void beforeLogin(AsyncPlayerPreLoginEvent e) {
printDebug("Detected AsyncPlayerPreLoginEvent...");
UUID playerId = e.getUniqueId();
printDebug("Checking if player with uuid=" + playerId + " can login...");
if (shouldAllowLogin(playerId)) {
printDebug("Login allowed, ignoring event.");
return;
}
CommandSender console = Bukkit.getConsoleSender();
LanguageManager languageManager = getLanguageManager();
String path = ("expansion.citizens-compatibility.prevent-join");
Component npcMessage = languageManager.getMessage(console, path);
e.disallow(Result.KICK_OTHER, ComponentHelper.toLegacy(npcMessage));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(PlayerJoinEvent e) {
printDebug("Detected PlayerJoinEvent...");
Player player = e.getPlayer();
printDebug("Player: " + player.getName());
printDebug("Disabled item pickup for player.");
player.setCanPickupItems(false);
CombatNpcManager combatNpcManager = getCombatNpcManager();
CombatNPC combatNPC = combatNpcManager.getNPC(player);
if (combatNPC != null) {
printDebug("Combat NPC exists for player, removing.");
combatNpcManager.remove(combatNPC);
}
PunishTask punishTask = new PunishTask(getCitizensExpansion(), player);
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
scheduler.scheduleEntityTask(punishTask);
}
private boolean shouldAllowLogin(@NotNull UUID uuid) {
CitizensConfiguration configuration = getCitizensConfiguration();
if (!configuration.isPreventLogin()) {
printDebug("Prevent login option disabled, login allowed.");
return true;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
CombatNpcManager combatNpcManager = getCombatNpcManager();
CombatNPC combatNPC = combatNpcManager.getNPC(offlinePlayer);
if (combatNPC == null) {
printDebug("Combat NPC not found for that player, login allowed.");
return true;
}
NPC originalNPC = combatNPC.getOriginalNPC();
if (!originalNPC.isSpawned()) {
printDebug("Combat NPC was removed, login allowed.");
return true;
}
printDebug("Combat NPC exists and is spawned, login blocked.");
return false;
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerPunish.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
public final class ListenerPunish extends CitizensExpansionListener {
public ListenerPunish(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void beforePunish(PlayerPunishEvent e) {
printDebug("Detected PlayerPunishEvent.");
CitizensConfiguration configuration = getCitizensConfiguration();
if (configuration.isPreventPunishments()) {
printDebug("Cancelling all other CombatLogX punishments.");
e.setCancelled(true);
}
Player player = e.getPlayer();
CombatNpcManager combatNpcManager = getCombatNpcManager();
YamlConfiguration playerData = combatNpcManager.getData(player);
printDebug("Spawning NPC for player " + player.getName());
playerData.set("citizens-compatibility.punish", true);
combatNpcManager.saveData(player);
combatNpcManager.createNPC(player, e.getEnemies());
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerQuit.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import java.util.Collections;
import org.jetbrains.annotations.NotNull;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerQuitEvent;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
public final class ListenerQuit extends CitizensExpansionListener {
public ListenerQuit(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onQuit(PlayerQuitEvent e) {
if (!isAlwaysSpawnOnQuit()) {
return;
}
Player player = e.getPlayer();
CombatNpcManager combatNpcManager = getCombatNpcManager();
YamlConfiguration playerData = combatNpcManager.getData(player);
printDebug("Spawning always-quit NPC for player " + player.getName());
playerData.set("citizens-compatibility.punish", true);
combatNpcManager.saveData(player);
combatNpcManager.createNPC(player, Collections.emptyList());
}
private boolean isAlwaysSpawnOnQuit() {
CitizensConfiguration configuration = getCitizensConfiguration();
return configuration.isAlwaysSpawnNpcOnQuit();
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/listener/ListenerResurrect.java
================================================
package combatlogx.expansion.compatibility.citizens.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityResurrectEvent;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
public final class ListenerResurrect extends CitizensExpansionListener {
public ListenerResurrect(@NotNull CitizensExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onResurrect(EntityResurrectEvent e) {
CitizensConfiguration configuration = getCitizensConfiguration();
if (!configuration.isPreventResurrect()) {
return;
}
LivingEntity entity = e.getEntity();
NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
NPC npc = npcRegistry.getNPC(entity);
if (npc == null) {
return;
}
CombatNPC combatNPC = getCombatNPC(npc);
if (combatNPC == null) {
return;
}
e.setCancelled(true);
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/manager/CombatNpcManager.java
================================================
package combatlogx.expansion.compatibility.citizens.manager;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import com.github.sirblobman.api.configuration.PlayerDataManager;
import com.github.sirblobman.api.folia.details.RunnableTask;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.api.nms.EntityHandler;
import com.github.sirblobman.api.nms.MultiVersionHandler;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.configuration.SentinelConfiguration;
import combatlogx.expansion.compatibility.citizens.object.CombatNPC;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPC.Metadata;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.trait.Owner;
import org.mcmonkey.sentinel.SentinelTrait;
import org.mcmonkey.sentinel.targeting.SentinelTargetLabel;
public final class CombatNpcManager {
private final CitizensExpansion expansion;
private final Map playerNpcMap;
private final Map npcCombatMap;
public CombatNpcManager(@NotNull CitizensExpansion expansion) {
this.expansion = expansion;
this.playerNpcMap = new ConcurrentHashMap<>();
this.npcCombatMap = new ConcurrentHashMap<>();
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
private @NotNull ICombatLogX getCombatLogX() {
CitizensExpansion expansion = getExpansion();
return expansion.getPlugin();
}
public @Nullable CombatNPC getCombatNPC(@Nullable NPC npc) {
if (npc == null) {
return null;
}
UUID npcId = npc.getUniqueId();
return this.npcCombatMap.getOrDefault(npcId, null);
}
public @NotNull YamlConfiguration getData(@NotNull OfflinePlayer player) {
ICombatLogX plugin = getCombatLogX();
PlayerDataManager playerDataManager = plugin.getPlayerDataManager();
return playerDataManager.get(player);
}
public void saveData(@NotNull OfflinePlayer player) {
ICombatLogX plugin = getCombatLogX();
PlayerDataManager playerDataManager = plugin.getPlayerDataManager();
playerDataManager.save(player);
}
public void remove(@NotNull CombatNPC combatNPC) {
OfflinePlayer owner = combatNPC.getOfflineOwner();
NPC originalNPC = combatNPC.getOriginalNPC();
try {
combatNPC.cancel();
} catch (IllegalStateException ignored) {
// Do Nothing
}
saveNPC(owner, originalNPC);
this.playerNpcMap.remove(owner.getUniqueId());
this.npcCombatMap.remove(originalNPC.getUniqueId());
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
scheduler.scheduleTask(new RunnableTask(getCombatLogX().getPlugin(), originalNPC::destroy));
}
public void removeAll() {
Map copyMap = new HashMap<>(this.playerNpcMap);
this.playerNpcMap.clear();
Collection npcCollection = copyMap.values();
npcCollection.forEach(this::remove);
}
public void createNPC(@NotNull Player player, @NotNull List enemyList) {
if (player.hasMetadata("NPC")) {
printDebug("player is an NPC, not spawning.");
return;
}
UUID uuid = player.getUniqueId();
String playerName = player.getName();
printDebug("Spawning NPC for player '" + playerName + "'.");
EntityType entityType = getEntityType();
NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
NPC npc = npcRegistry.createNPC(entityType, playerName);
npc.setProtected(false);
npc.data().set(Metadata.SHOULD_SAVE, false);
printDebug("Created NPC with entity type " + entityType + ".");
String npcNameFormat = getConfiguration().getCustomNpcNameFormat();
printDebug("NPC Name Format: " + npcNameFormat);
String npcName = npcNameFormat.replace("{player_name}", playerName);
npc.setName(npcName);
printDebug("Set NPC custom name to '" + npcName + "'.");
Location location = player.getLocation();
boolean spawn = npc.spawn(location);
if (!spawn) {
printDebug("Failed to spawn an NPC. (npc.spawn() returned false)");
return;
}
Entity entity = npc.getEntity();
if (!(entity instanceof LivingEntity livingEntity)) {
printDebug("NPC for player '" + playerName + "' is not a LivingEntity, removing...");
npc.destroy();
return;
}
livingEntity.setNoDamageTicks(0);
livingEntity.setMaximumNoDamageTicks(0);
printDebug("Forced NPC to be damageable (no damage ticks = 0)");
if (npc.hasTrait(Owner.class)) {
npc.removeTrait(Owner.class);
}
printDebug("Forced NPC to be damageable (removed owner trait)");
ICombatLogX plugin = this.expansion.getPlugin();
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
double health = player.getHealth();
double maxHealth = entityHandler.getMaxHealth(livingEntity);
if (maxHealth < health) {
entityHandler.setMaxHealth(livingEntity, health);
printDebug("Fixed NPC max health.");
}
livingEntity.setHealth(health);
CitizensConfiguration configuration = getConfiguration();
if (configuration.isMobTarget()) {
// npc.data().set(Metadata.TARGETABLE, true);
double radius = configuration.getMobTargetRadius();
if (radius >= 0.0D) {
forceTargetAllNearby(livingEntity, radius);
printDebug("Forced NPC to target nearby enemies.");
}
}
CombatNPC combatNPC = new CombatNPC(this.expansion, npc, player);
printDebug("Created CombatNPC data.");
this.playerNpcMap.put(uuid, combatNPC);
this.npcCombatMap.put(npc.getUniqueId(), combatNPC);
if (!enemyList.isEmpty()) {
Entity mainEnemy = enemyList.getFirst();
if (mainEnemy instanceof Player) {
combatNPC.setEnemy((Player) mainEnemy);
printDebug("Main enemy was player, setting enemy in combat npc.");
}
printDebug("Checking sentinel data...");
checkSentinel(npc, enemyList);
} else {
printDebug("Enemy list was empty for player.");
}
saveLocation(player, npc);
printDebug("Saving last location if configured.");
saveInventory(player);
printDebug("Saving inventory if configured.");
equipNPC(player, npc);
printDebug("Setting NPC equipment to match original player inventory.");
printDebug("Finished setting combat NPC data.");
combatNPC.start();
printDebug("Finished spawning combat NPC.");
}
private void forceTargetAllNearby(@NotNull LivingEntity entity, double radius) {
List nearbyEntityList = entity.getNearbyEntities(radius, radius, radius);
for (Entity nearby : nearbyEntityList) {
if (nearby instanceof Monster monster) {
monster.setTarget(entity);
}
}
}
public @Nullable CombatNPC getNPC(@NotNull OfflinePlayer player) {
UUID playerId = player.getUniqueId();
return this.playerNpcMap.get(playerId);
}
private void saveNPC(@NotNull OfflinePlayer owner, @NotNull NPC npc) {
saveHealth(owner, npc);
saveLocation(owner, npc);
YamlConfiguration data = getData(owner);
data.set("citizens-compatibility.punish", true);
saveData(owner);
}
private void saveHealth(@NotNull OfflinePlayer owner, @NotNull NPC npc) {
double health = getHealth(npc);
YamlConfiguration data = getData(owner);
data.set("citizens-compatibility.health", health);
saveData(owner);
}
private void saveLocation(@NotNull OfflinePlayer owner, @NotNull NPC npc) {
Location location = getLocation(npc);
YamlConfiguration data = getData(owner);
data.set("citizens-compatibility.location", location);
saveData(owner);
}
public void saveInventory(@NotNull Player player) {
CitizensConfiguration configuration = getConfiguration();
if (!configuration.isStoreInventory()) {
return;
}
CitizensExpansion expansion = getExpansion();
InventoryManager inventoryManager = expansion.getInventoryManager();
inventoryManager.storeInventory(player);
PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
player.updateInventory();
}
public void equipNPC(@NotNull Player player, @NotNull NPC npc) {
CitizensExpansion expansion = getExpansion();
InventoryManager inventoryManager = expansion.getInventoryManager();
inventoryManager.equipNPC(player, npc);
}
public double loadHealth(@NotNull Player player) {
YamlConfiguration data = getData(player);
return data.getDouble("citizens-compatibility.health");
}
public @Nullable Location loadLocation(@NotNull Player player) {
YamlConfiguration data = getData(player);
Object locationObject = data.get("citizens-compatibility.location");
if (locationObject instanceof Location) {
return (Location) locationObject;
}
return null;
}
private double getHealth(@NotNull NPC npc) {
if (!npc.isSpawned()) {
return 0.0D;
}
Entity entity = npc.getEntity();
if (!(entity instanceof LivingEntity livingEntity)) {
return 0.0D;
}
return livingEntity.getHealth();
}
public @NotNull Location getLocation(@NotNull NPC npc) {
if (!npc.isSpawned()) {
return npc.getStoredLocation();
}
Entity entity = npc.getEntity();
return entity.getLocation();
}
private @NotNull CitizensConfiguration getConfiguration() {
CitizensExpansion expansion = getExpansion();
return expansion.getCitizensConfiguration();
}
private @NotNull EntityType getEntityType() {
CitizensConfiguration configuration = getConfiguration();
return configuration.getMobType();
}
private void printDebug(@NotNull String message) {
ICombatLogX combatLogX = getCombatLogX();
if (combatLogX.isDebugModeDisabled()) {
return;
}
Logger logger = getExpansion().getLogger();
logger.info("[Debug] [CombatNpcManager] " + message);
}
private void checkSentinel(@NotNull NPC npc, @NotNull List enemyList) {
printDebug("Checking sentinel data...");
CitizensExpansion expansion = getExpansion();
if (!expansion.isSentinelEnabled()) {
printDebug("Sentinel is not enabled. Check the configuration and Sentinel plugin.");
return;
}
SentinelTrait sentinelTrait = npc.getOrAddTrait(SentinelTrait.class);
printDebug("Added sentinel trait to NPC.");
sentinelTrait.setInvincible(false);
printDebug("Set sentinel as not invincible.");
sentinelTrait.respawnTime = -1;
printDebug("Disabled respawn time.");
sentinelTrait.fightback = true;
printDebug("Enabled sentinel fightback.");
SentinelConfiguration configuration = expansion.getSentinelConfiguration();
if (!configuration.isAttackFirst()) {
printDebug("Attack first is disabled.");
return;
}
printDebug("Adding attack first targets to Sentinel.");
for (Entity enemy : enemyList) {
UUID enemyId = enemy.getUniqueId();
String enemyIdString = String.format(Locale.US, "uuid:%s", enemyId);
SentinelTargetLabel targetLabel = new SentinelTargetLabel(enemyIdString);
targetLabel.addToList(sentinelTrait.allTargets);
}
printDebug("Finished setting sentinel data.");
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/manager/InventoryManager.java
================================================
package combatlogx.expansion.compatibility.citizens.manager;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;
import com.github.sirblobman.api.configuration.PlayerDataManager;
import com.github.sirblobman.api.item.ArmorType;
import com.github.sirblobman.api.utility.ItemUtility;
import com.github.sirblobman.api.utility.Validate;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.event.NPCDropItemEvent;
import com.github.sirblobman.combatlogx.api.object.CitizensSlotType;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.object.StoredInventory;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.trait.Equipment;
public final class InventoryManager {
private final CitizensExpansion expansion;
private final Map storedInventoryMap;
public InventoryManager(@NotNull CitizensExpansion expansion) {
this.expansion = expansion;
this.storedInventoryMap = new HashMap<>();
}
public void storeInventory(@NotNull Player player) {
if (player.hasMetadata("NPC")) {
throw new IllegalArgumentException("player must not be an NPC!");
}
PlayerInventory playerInventory = player.getInventory();
StoredInventory storedInventory = StoredInventory.createFrom(playerInventory);
UUID playerId = player.getUniqueId();
this.storedInventoryMap.put(playerId, storedInventory);
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration configuration = playerDataManager.get(player);
ConfigurationSection section = configuration.createSection("citizens-compatibility.stored-inventory");
CitizensExpansion expansion = getExpansion();
storedInventory.save(expansion, section);
playerDataManager.save(player);
}
public @Nullable StoredInventory getStoredInventory(@NotNull OfflinePlayer player) {
UUID playerId = player.getUniqueId();
if (this.storedInventoryMap.containsKey(playerId)) {
return this.storedInventoryMap.get(playerId);
}
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration configuration = playerDataManager.get(player);
String storagePath = ("citizens-compatibility.stored-inventory");
ConfigurationSection section = configuration.getConfigurationSection(storagePath);
if (section == null) {
return null;
}
CitizensExpansion expansion = getExpansion();
return StoredInventory.createFrom(expansion, section);
}
public void removeStoredInventory(@NotNull OfflinePlayer player) {
UUID playerId = player.getUniqueId();
this.storedInventoryMap.remove(playerId);
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration configuration = playerDataManager.get(player);
String storagePath = ("citizens-compatibility.stored-inventory");
configuration.set(storagePath, null);
playerDataManager.save(player);
}
public void restoreInventory(@NotNull Player player) {
if (player.hasMetadata("NPC")) {
throw new IllegalArgumentException("player must not be an NPC!");
}
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
for (int slot = 0; slot < 36; slot++) {
ItemStack item = storedInventory.getItem(slot);
playerInventory.setItem(slot, item);
}
playerInventory.setHelmet(storedInventory.getArmor(ArmorType.HELMET));
playerInventory.setChestplate(storedInventory.getArmor(ArmorType.CHESTPLATE));
playerInventory.setLeggings(storedInventory.getArmor(ArmorType.LEGGINGS));
playerInventory.setBoots(storedInventory.getArmor(ArmorType.BOOTS));
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion < 9) {
restoreHandsLegacy(storedInventory, playerInventory);
} else {
restoreHandsModern(storedInventory, playerInventory);
}
removeStoredInventory(player);
player.updateInventory();
}
public void dropInventory(@NotNull OfflinePlayer player, @NotNull Location location) {
World world = location.getWorld();
Validate.notNull(world, "location must have a valid world!");
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
for (int slot = 0; slot < 36; slot++) {
ItemStack item = storedInventory.getItem(slot);
if (item == null) {
continue;
}
dropItem(item, player, location, CitizensSlotType.INVENTORY);
}
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
ItemStack item = storedInventory.getArmor(armorType);
if (item == null) {
continue;
}
dropItem(item, player, location, CitizensSlotType.ARMOR);
}
ItemStack item = storedInventory.getOffHandItem();
if (item != null) {
dropItem(item, player, location, CitizensSlotType.OFFHAND);
}
removeStoredInventory(player);
}
private void dropItem(@NotNull ItemStack item, @NotNull OfflinePlayer player, @NotNull Location location,
@NotNull CitizensSlotType type) {
World world = location.getWorld();
if (ItemUtility.isAir(item) || world == null) {
return;
}
NPCDropItemEvent event = new NPCDropItemEvent(item, player, location, type);
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.callEvent(event);
if (!event.isCancelled()) {
world.dropItemNaturally(location, event.getItem());
}
}
public void equipNPC(@NotNull OfflinePlayer player, @NotNull NPC npc) {
Equipment equipmentTrait = npc.getOrAddTrait(Equipment.class);
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
ItemStack mainHandItem = storedInventory.getMainHandItem();
if (mainHandItem != null) {
equipmentTrait.set(Equipment.EquipmentSlot.HAND, mainHandItem);
}
if (VersionUtility.getMinorVersion() > 8) {
ItemStack offHandItem = storedInventory.getOffHandItem();
if (offHandItem != null) {
equipmentTrait.set(Equipment.EquipmentSlot.OFF_HAND, offHandItem);
}
}
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
ItemStack item = storedInventory.getArmor(armorType);
if (item != null) {
EquipmentSlot bukkitSlot = armorType.getEquipmentSlot();
Equipment.EquipmentSlot slot = getNpcSlotFromBukkitSlot(bukkitSlot);
equipmentTrait.set(slot, item);
}
}
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
private @NotNull ICombatLogX getICombatLogX() {
CitizensExpansion expansion = getExpansion();
return expansion.getPlugin();
}
private @NotNull PlayerDataManager getPlayerDataManager() {
ICombatLogX plugin = getICombatLogX();
return plugin.getPlayerDataManager();
}
@SuppressWarnings("deprecation")
private void restoreHandsLegacy(@NotNull StoredInventory storedInventory, @NotNull PlayerInventory inventory) {
ItemStack item = storedInventory.getMainHandItem();
inventory.setItemInHand(item);
}
private void restoreHandsModern(@NotNull StoredInventory storedInventory, @NotNull PlayerInventory inventory) {
ItemStack mainHand = storedInventory.getMainHandItem();
ItemStack offHand = storedInventory.getOffHandItem();
inventory.setItemInMainHand(mainHand);
inventory.setItemInOffHand(offHand);
}
private Equipment.EquipmentSlot getNpcSlotFromBukkitSlot(@NotNull EquipmentSlot slot) {
if (VersionUtility.getMinorVersion() > 8) {
if (slot == EquipmentSlot.OFF_HAND) {
return Equipment.EquipmentSlot.OFF_HAND;
}
}
return switch (slot) {
case HEAD -> Equipment.EquipmentSlot.HELMET;
case CHEST -> Equipment.EquipmentSlot.CHESTPLATE;
case LEGS -> Equipment.EquipmentSlot.LEGGINGS;
case FEET -> Equipment.EquipmentSlot.BOOTS;
case HAND -> Equipment.EquipmentSlot.HAND;
default -> null;
};
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/object/CombatNPC.java
================================================
package combatlogx.expansion.compatibility.citizens.object;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.github.sirblobman.api.folia.details.TaskDetails;
import com.github.sirblobman.api.folia.scheduler.TaskScheduler;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagInformation;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import net.citizensnpcs.api.npc.NPC;
public final class CombatNPC extends TaskDetails {
private final CitizensExpansion expansion;
private final NPC originalNPC;
private final UUID ownerId;
private UUID enemyId;
private long survivalTicks;
public CombatNPC(@NotNull CitizensExpansion expansion, @NotNull NPC originalNPC, @NotNull OfflinePlayer owner) {
super(expansion.getPlugin().getPlugin());
this.expansion = expansion;
this.originalNPC = originalNPC;
this.ownerId = owner.getUniqueId();
}
@Override
public void run() {
this.survivalTicks--;
if (this.survivalTicks > 0) {
return;
}
CitizensExpansion expansion = getExpansion();
CitizensConfiguration configuration = expansion.getCitizensConfiguration();
if (configuration.isStayUntilEnemyEscapes() && this.enemyId != null) {
Player player = Bukkit.getPlayer(this.enemyId);
if (player != null) {
ICombatManager combatManager = expansion.getPlugin().getCombatManager();
TagInformation tagInformation = combatManager.getTagInformation(player);
if (tagInformation != null) {
long timeLeftMillis = tagInformation.getMillisLeftCombined();
this.survivalTicks = (timeLeftMillis / 50L) + 1;
return;
}
}
}
CombatNpcManager combatNpcManager = expansion.getCombatNpcManager();
combatNpcManager.remove(this);
}
public void start() {
resetSurvivalTime();
setDelay(1L);
setPeriod(1L);
TaskScheduler scheduler = getCombatLogX().getFoliaHelper().getScheduler();
scheduler.scheduleTask(this);
}
public @NotNull NPC getOriginalNPC() {
return this.originalNPC;
}
public @NotNull UUID getOwnerId() {
return this.ownerId;
}
public @NotNull OfflinePlayer getOfflineOwner() {
UUID ownerId = getOwnerId();
return Bukkit.getOfflinePlayer(ownerId);
}
public void resetSurvivalTime() {
CitizensExpansion expansion = getExpansion();
CitizensConfiguration configuration = expansion.getCitizensConfiguration();
long survivalSeconds = configuration.getSurvivalTime();
this.survivalTicks = (survivalSeconds * 20L);
}
public void setEnemy(@NotNull Player enemy) {
this.enemyId = enemy.getUniqueId();
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
private @NotNull ICombatLogX getCombatLogX() {
CitizensExpansion expansion = getExpansion();
return expansion.getPlugin();
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/object/StoredInventory.java
================================================
package combatlogx.expansion.compatibility.citizens.object;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.github.sirblobman.api.item.ArmorType;
import com.github.sirblobman.api.nms.ItemHandler;
import com.github.sirblobman.api.nms.MultiVersionHandler;
import com.github.sirblobman.api.utility.ItemUtility;
import com.github.sirblobman.api.utility.VersionUtility;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
public final class StoredInventory {
private final Map contentMap;
private final Map armorMap;
private ItemStack mainHand;
private ItemStack offHand;
private StoredInventory() {
this.contentMap = new HashMap<>();
this.armorMap = new EnumMap<>(ArmorType.class);
this.mainHand = null;
this.offHand = null;
}
public static @NotNull StoredInventory createFrom(@NotNull PlayerInventory playerInventory) {
StoredInventory storedInventory = new StoredInventory();
storedInventory.setArmor(ArmorType.HELMET, playerInventory.getHelmet());
storedInventory.setArmor(ArmorType.CHESTPLATE, playerInventory.getChestplate());
storedInventory.setArmor(ArmorType.LEGGINGS, playerInventory.getLeggings());
storedInventory.setArmor(ArmorType.BOOTS, playerInventory.getBoots());
for (int slot = 0; slot < 36; slot++) {
ItemStack item = playerInventory.getItem(slot);
storedInventory.setItemStack(slot, item);
}
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion < 9) {
setHandLegacy(storedInventory, playerInventory);
} else {
setHandModern(storedInventory, playerInventory);
}
return storedInventory;
}
public static @NotNull StoredInventory createFrom(@NotNull CitizensExpansion expansion,
@NotNull ConfigurationSection configuration) {
StoredInventory storedInventory = new StoredInventory();
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
String armorTypeName = armorType.name();
String armorTypePath = ("armor." + armorTypeName);
ItemStack item = loadItemStack(expansion, configuration, armorTypePath);
storedInventory.setArmor(armorType, item);
}
ItemStack mainHand = loadItemStack(expansion, configuration, "main-hand");
ItemStack offHand = loadItemStack(expansion, configuration, "off-hand");
storedInventory.setMainHand(mainHand);
storedInventory.setOffHand(offHand);
for (int slot = 0; slot < 36; slot++) {
String slotName = Integer.toString(slot);
String slotPath = ("content." + slotName);
ItemStack item = loadItemStack(expansion, configuration, slotPath);
storedInventory.setItemStack(slot, item);
}
return storedInventory;
}
@SuppressWarnings("deprecation")
private static void setHandLegacy(@NotNull StoredInventory stored, @NotNull PlayerInventory playerInventory) {
ItemStack item = playerInventory.getItemInHand();
stored.setMainHand(item);
stored.setOffHand(null);
}
private static void setHandModern(@NotNull StoredInventory stored, @NotNull PlayerInventory playerInventory) {
stored.setMainHand(playerInventory.getItemInMainHand());
stored.setOffHand(playerInventory.getItemInOffHand());
}
private static @Nullable ItemStack loadItemStack(@NotNull CitizensExpansion expansion,
@NotNull ConfigurationSection section, @NotNull String path) {
if (!section.isSet(path)) {
return null;
}
if (!section.isString(path)) {
return null;
}
String value = section.getString(path);
if (value == null) {
return null;
}
ICombatLogX plugin = expansion.getPlugin();
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
ItemHandler itemHandler = multiVersionHandler.getItemHandler();
return itemHandler.fromBase64String(value);
}
private static void saveItemStack(@NotNull CitizensExpansion expansion, @NotNull ConfigurationSection section,
@NotNull String path, @Nullable ItemStack item) {
if (ItemUtility.isAir(item)) {
section.set(path, null);
return;
}
ICombatLogX plugin = expansion.getPlugin();
MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
ItemHandler itemHandler = multiVersionHandler.getItemHandler();
String base64 = itemHandler.toBase64String(item);
section.set(path, base64);
}
public @Nullable ItemStack getMainHandItem() {
return (this.mainHand == null ? null : this.mainHand.clone());
}
public @Nullable ItemStack getOffHandItem() {
return (this.offHand == null ? null : this.offHand.clone());
}
public @Nullable ItemStack getArmor(@NotNull ArmorType type) {
ItemStack item = this.armorMap.get(type);
return (item == null ? null : item.clone());
}
public @Nullable ItemStack getItem(int slot) {
ItemStack item = this.contentMap.get(slot);
return (item == null ? null : item.clone());
}
public void save(@NotNull CitizensExpansion expansion, @NotNull ConfigurationSection configuration) {
ItemStack mainHand = getMainHandItem();
saveItemStack(expansion, configuration, "main-hand", mainHand);
ItemStack offHand = getOffHandItem();
saveItemStack(expansion, configuration, "off-hand", offHand);
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
ItemStack item = getArmor(armorType);
String armorTypeName = armorType.name();
String armorTypePath = ("armor." + armorTypeName);
saveItemStack(expansion, configuration, armorTypePath, item);
}
for (int slot = 0; slot < 36; slot++) {
ItemStack item = getItem(slot);
String slotName = Integer.toString(slot);
String slotPath = ("content." + slotName);
saveItemStack(expansion, configuration, slotPath, item);
}
}
private void setItemStack(int slot, @Nullable ItemStack item) {
if (item == null) {
this.contentMap.remove(slot);
} else {
this.contentMap.put(slot, item.clone());
}
}
private void setArmor(@NotNull ArmorType type, @Nullable ItemStack item) {
if (item == null) {
this.armorMap.remove(type);
} else {
this.armorMap.put(type, item.clone());
}
}
private void setMainHand(@Nullable ItemStack item) {
this.mainHand = (item == null ? null : item.clone());
}
private void setOffHand(@Nullable ItemStack item) {
this.offHand = (item == null ? null : item.clone());
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/java/combatlogx/expansion/compatibility/citizens/task/PunishTask.java
================================================
package combatlogx.expansion.compatibility.citizens.task;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Location;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import com.github.sirblobman.api.folia.FoliaHelper;
import com.github.sirblobman.api.folia.details.EntityTaskDetails;
import com.github.sirblobman.api.folia.teleport.TeleportHandler;
import com.github.sirblobman.api.nms.EntityHandler;
import com.github.sirblobman.api.nms.MultiVersionHandler;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import combatlogx.expansion.compatibility.citizens.CitizensExpansion;
import combatlogx.expansion.compatibility.citizens.configuration.CitizensConfiguration;
import combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager;
import combatlogx.expansion.compatibility.citizens.manager.InventoryManager;
public final class PunishTask extends EntityTaskDetails {
private final CitizensExpansion expansion;
public PunishTask(@NotNull CitizensExpansion expansion, @NotNull Player entity) {
super(expansion.getPlugin().getPlugin(), entity);
setDelay(1L);
this.expansion = expansion;
}
@Override
public void run() {
Player player = getEntity();
if (player == null) {
return;
}
punish(player);
player.setCanPickupItems(true);
}
private @NotNull CitizensExpansion getExpansion() {
return this.expansion;
}
private @NotNull CitizensConfiguration getCitizensConfiguration() {
CitizensExpansion expansion = getExpansion();
return expansion.getCitizensConfiguration();
}
private @NotNull CombatNpcManager getCombatNpcManager() {
CitizensExpansion expansion = getExpansion();
return expansion.getCombatNpcManager();
}
private @NotNull InventoryManager getInventoryManager() {
CitizensExpansion expansion = getExpansion();
return expansion.getInventoryManager();
}
private @NotNull ICombatLogX getCombatLogX() {
CitizensExpansion expansion = getExpansion();
return expansion.getPlugin();
}
private @NotNull ICombatManager getCombatManager() {
ICombatLogX plugin = getCombatLogX();
return plugin.getCombatManager();
}
private void punish(@NotNull Player player) {
if (player.hasMetadata("NPC")) {
return;
}
CombatNpcManager combatNpcManager = getCombatNpcManager();
YamlConfiguration playerData = combatNpcManager.getData(player);
if (!playerData.getBoolean("citizens-compatibility.punish")) {
return;
}
playerData.set("citizens-compatibility.punish", false);
combatNpcManager.saveData(player);
CitizensConfiguration configuration = getCitizensConfiguration();
if (configuration.isStoreLocation()) {
Location location = combatNpcManager.loadLocation(player);
if (location != null) {
FoliaHelper foliaHelper = getExpansion().getPlugin().getFoliaHelper();
TeleportHandler teleporter = foliaHelper.getTeleporter();
teleporter.teleport(player, location).join();
}
playerData.set("citizens-compatibility.location", null);
}
if (configuration.isStoreInventory()) {
PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
}
double health = combatNpcManager.loadHealth(player);
setHealth(player, health);
if (health <= 0.0D) {
playerData.set("citizens-compatibility.inventory", null);
playerData.set("citizens-compatibility.armor", null);
}
if (configuration.isStoreInventory()) {
InventoryManager inventoryManager = getInventoryManager();
inventoryManager.restoreInventory(player);
}
if (configuration.isTagPlayer() && health > 0.0D) {
ICombatManager combatManager = getCombatManager();
combatManager.tag(player, null, TagType.UNKNOWN, TagReason.UNKNOWN);
}
}
private void setHealth(@NotNull Player player, double health) {
if (Double.isInfinite(health) || Double.isNaN(health)) {
health = 0.0D;
}
ICombatLogX combatLogX = getCombatLogX();
MultiVersionHandler multiVersionHandler = combatLogX.getMultiVersionHandler();
EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
double maxHealth = entityHandler.getMaxHealth(player);
if (maxHealth < health) {
entityHandler.setMaxHealth(player, health);
}
player.setHealth(health);
}
}
================================================
FILE: expansion/compatibility/Citizens/src/main/resources/citizens.yml
================================================
# Should this expansion prevent other punishments from executing? (e.g. kill, commands, etc...)
# This prevents issues such as killing AND spawning an NPC
# Default: true
prevent-punishments: true
# Should this expansion prevent a player from logging in if they have an NPC active?
# This means they will have to wait until it is killed or despawned.
# Default: false
prevent-login: false
# Which entity type should be used to create NPCs?
# You can find a list of valid EntityTypes in the link below:
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html
# Default: PLAYER
mob-type: PLAYER
# Should we take the player's inventory and put it into the NPC?
# This will prevent items from being dropped unless the NPC is killed.
# Items will be taken when the NPC is spawned and restored to the player once they log back in.
# Armor and held items will be placed in the correct slots.
# Default: true
store-inventory: true
# Should we store the NPC's last location?
# The player will be teleported to that location once they log bck in.
# Default: true
store-location: true
# Should nearby mobs target combat NPCs?
# Default: true
mob-target: true
# How close do mobs need to be to force-target an NPC?
# Set this to 0 to disable this feature.
# Default: 10
mob-target-radius: 10
# How long do combat NPCs last if they are not attacked by mobs or players?
# NPC survival time is in seconds.
# Default: 30
survival-time: 30
# Should an NPC stay alive until their last known enemy is out of combat?
# Default: false
stay-until-enemy-escape: false
# Should the survival time on an NPC reset every time they are hit?
# Default: false
stay-until-no-damage: false
# Should combat NPCs be prevented from using totems of undying?
# Default: true
prevent-resurrect: true
# Should players receive a combat tag when they log back in?
# This only applies if their NPC still had health when it respawned.
tag-player: true
# Should CombatLogX always spawn an NPC, even if the player is not tagged?
always-spawn-npc-on-quit: false
# Custom NPC name
# May be character limited to 16 on some versions.
# Available Placeholders: {player_name}
# DO NOT set this to null or empty.
custom-npc-name: "{player_name}"
================================================
FILE: expansion/compatibility/Citizens/src/main/resources/config.yml
================================================
# Should players be tagged by NPCs?
# Default: false
npc-tagging: false
# Should we use the Sentinel plugin to create combat NPCs?
# Requires Sentinel, which can be found at the link below:
# https://www.spigotmc.org/resources/22017/
# Default: true
enable-sentinel: true
================================================
FILE: expansion/compatibility/Citizens/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.citizens.CitizensExpansion"
version: "17.18"
author: "SirBlobman"
plugin-depend:
- "Citizens"
plugin-soft-depend:
- "Sentinel"
================================================
FILE: expansion/compatibility/Citizens/src/main/resources/sentinel.yml
================================================
# true: Combat NPCs will attack their enemy first.
# false: Combat NPCs will only attack if they are attacked first.
# Default: false
attack-first: false
================================================
FILE: expansion/compatibility/CrackShot/build.gradle.kts
================================================
dependencies {
compileOnly("com.github.Shampaggon:CrackShot:0.98.13")
}
================================================
FILE: expansion/compatibility/CrackShot/gradle.properties
================================================
expansion.name=CompatCrackShot
expansion.prefix=CrackShot Compatibility
================================================
FILE: expansion/compatibility/CrackShot/src/main/java/combatlogx/expansion/compatibility/crackshot/CrackShotExpansion.java
================================================
package combatlogx.expansion.compatibility.crackshot;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
import combatlogx.expansion.compatibility.crackshot.listener.ListenerCrackShot;
public final class CrackShotExpansion extends Expansion {
public CrackShotExpansion(@NotNull ICombatLogX plugin) {
super(plugin);
}
@Override
public void onLoad() {
// Do Nothing
}
@Override
public void onEnable() {
if (!checkDependency("CrackShot", true)) {
selfDisable();
return;
}
new ListenerCrackShot(this).register();
}
@Override
public void onDisable() {
// Do Nothing
}
@Override
public void reloadConfig() {
// Do Nothing
}
}
================================================
FILE: expansion/compatibility/CrackShot/src/main/java/combatlogx/expansion/compatibility/crackshot/listener/ListenerCrackShot.java
================================================
package combatlogx.expansion.compatibility.crackshot.listener;
import org.jetbrains.annotations.NotNull;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import com.github.sirblobman.combatlogx.api.expansion.ExpansionListener;
import com.github.sirblobman.combatlogx.api.manager.ICombatManager;
import com.github.sirblobman.combatlogx.api.object.TagReason;
import com.github.sirblobman.combatlogx.api.object.TagType;
import com.shampaggon.crackshot.events.WeaponDamageEntityEvent;
import combatlogx.expansion.compatibility.crackshot.CrackShotExpansion;
public final class ListenerCrackShot extends ExpansionListener {
public ListenerCrackShot(@NotNull CrackShotExpansion expansion) {
super(expansion);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onAttack(WeaponDamageEntityEvent e) {
Entity entity = e.getVictim();
if (!(entity instanceof Player damaged)) {
return;
}
Player damager = e.getPlayer();
ICombatManager combatManager = getCombatManager();
combatManager.tag(damager, damaged, TagType.PLAYER, TagReason.ATTACKER);
combatManager.tag(damaged, damager, TagType.PLAYER, TagReason.ATTACKED);
}
}
================================================
FILE: expansion/compatibility/CrackShot/src/main/resources/expansion.yml
================================================
name: "${expansionName}"
prefix: "${expansionPrefix}"
description: "${expansionDescription}"
main: "combatlogx.expansion.compatibility.crackshot.CrackShotExpansion"
version: "17.1"
author: "SirBlobman"
plugin-depend:
- "CrackShot"
================================================
FILE: expansion/compatibility/CrashClaim/build.gradle.kts
================================================
repositories {
maven("https://nexus.sirblobman.xyz/proxy-public")
}
dependencies {
compileOnly("com.github.WhipDevelopment:CrashClaim:c697d3e9ef")
}
================================================
FILE: expansion/compatibility/CrashClaim/gradle.properties
================================================
expansion.name=CompatCrashClaim
expansion.prefix=CrashClaim Compatibility
================================================
FILE: expansion/compatibility/CrashClaim/src/main/java/combatlogx/expansion/compatibility/region/crash/claim/CrashClaimExpansion.java
================================================
package combatlogx.expansion.compatibility.region.crash.claim;
import org.jetbrains.annotations.NotNull;
import com.github.sirblobman.combatlogx.api.ICombatLogX;
import com.github.sirblobman.combatlogx.api.expansion.region.RegionExpansion;
import com.github.sirblobman.combatlogx.api.expansion.region.RegionHandler;
public final class CrashClaimExpansion extends RegionExpansion {
private RegionHandler> regionHandler;
public CrashClaimExpansion(ICombatLogX plugin) {
super(plugin);
this.regionHandler = null;
}
@Override
public boolean checkDependencies() {
return checkDependency("CrashClaim", true, "1.0");
}
@Override
public @NotNull RegionHandler> getRegionHandler() {
if (this.regionHandler == null) {
this.regionHandler = new CrashClaimRegionHandler(this);
}
return this.regionHandler;
}
}
================================================
FILE: expansion/compatibility/CrashClaim/src/main/java/combatlogx/expansion/compatibility/region/crash/claim/CrashClaimRegionHandler.java
================================================
package combatlogx.expansion.compatibility.region.crash.claim;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.github.sirblobman.combatlogx.api.expansion.region.RegionHandler;
import com.github.sirblobman.combatlogx.api.object.TagInformation;
import com.github.sirblobman.combatlogx.api.object.TagType;
import net.crashcraft.crashclaim.CrashClaim;
import net.crashcraft.crashclaim.api.CrashClaimAPI;
import net.crashcraft.crashclaim.claimobjects.Claim;
public final class CrashClaimRegionHandler extends RegionHandler