Skip to content

Commit

Permalink
Config update and general fixes
Browse files Browse the repository at this point in the history
- Add more config options and remove UseBloodbendingAbilityConfig, which wasn't working anyway.
- Now ignoring invincible (`/b invincible`) and creative/spectator mode players.
- OPs can now bloodbend anytime.
  • Loading branch information
CozmycDev committed Jul 29, 2024
1 parent 2614fac commit ebc3be5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 38 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ The ability can be configured in the ProjectKorra `config.yml` file under `Extra
ExtraAbilities:
Cozmyc:
BloodShock:
ControlMovements: true # whether you can control entities movements while holding shift and before clicking
Cooldown: 5000 # milliseconds
ControlMovements: true
Cooldown: 5000
Duration: 6000
LiftHeight: 2.5
LaunchPower: 2.0
LaunchHeight: 0.7
ThrowPower: 2.0
ThrowHeight: 0.7
Range: 10
UseBloodbendingAbilityConfig: true
Language:
Description: Extremely skilled bloodbenders have demonstrated the ability
of taking full control of any living being in their surrounding area. This
ability grants the user mass crowd control, allowing them to forcefully
make entities mimic the bender's movements until they are lifted into the
air and launched away upon release.
Instructions: Hold Shift to activate, Left Click to lift entities, release
Shift to launch.
NightOnly: true
FullMoonOnly: false
UndeadMobs: true
OtherBloodbenders: false
Bloodless: false
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.doodcraft.cozmyc</groupId>
<artifactId>bloodshock</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<packaging>jar</packaging>

<name>BloodShock</name>
Expand Down
58 changes: 35 additions & 23 deletions src/main/java/net/doodcraft/cozmyc/bloodshock/BloodShock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import com.projectkorra.projectkorra.ability.AddonAbility;
import com.projectkorra.projectkorra.ability.BloodAbility;
import com.projectkorra.projectkorra.ability.ElementalAbility;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.region.RegionProtection;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
Expand All @@ -36,7 +38,6 @@ public class BloodShock extends BloodAbility implements AddonAbility {
private double range;
private double throwPower;
private double throwHeight;
private boolean useGlobalConfig;

private AbilityState currentState;
private boolean expired;
Expand All @@ -60,7 +61,6 @@ private void initializeFields() {
this.range = ConfigManager.defaultConfig.get().getDouble("ExtraAbilities.Cozmyc.BloodShock.Range");
this.throwPower = ConfigManager.defaultConfig.get().getDouble("ExtraAbilities.Cozmyc.BloodShock.ThrowPower");
this.throwHeight = ConfigManager.defaultConfig.get().getDouble("ExtraAbilities.Cozmyc.BloodShock.ThrowHeight");
this.useGlobalConfig = ConfigManager.defaultConfig.get().getBoolean("ExtraAbilities.Cozmyc.BloodShock.UseBloodbendingAbilityConfig");

this.currentState = AbilityState.START;
this.expired = false;
Expand All @@ -82,12 +82,12 @@ public static boolean isInProtectedRegion(Player player, Entity entity) {

@Override
public String getInstructions() {
return "Hold Shift to activate, Left Click to lift entities, release Shift to launch.";
return ConfigManager.defaultConfig.get().getString("ExtraAbilities.Cozmyc.BloodShock.Language.Instructions");
}

@Override
public String getDescription() {
return "Extremely skilled bloodbenders have demonstrated the ability of taking full control of any living being in their surrounding area. This ability grants the user mass crowd control, allowing them to forcefully make entities mimic the bender's movements until they are lifted into the air and launched away upon release.";
return ConfigManager.defaultConfig.get().getString("ExtraAbilities.Cozmyc.BloodShock.Language.Description");
}

@Override
Expand All @@ -101,7 +101,15 @@ public void load() {
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.ThrowPower", 2.0);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.ThrowHeight", 0.7);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.Range", 10);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.UseBloodbendingAbilityConfig", true);

ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.NightOnly", true);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.FullMoonOnly", false);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.UndeadMobs", true);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.OtherBloodbenders", false);
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.Bloodless", false);

ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.Language.Description", "Extremely skilled bloodbenders have demonstrated the ability of taking full control of any living being in their surrounding area. This ability grants the user mass crowd control, allowing them to forcefully make entities mimic the bender's movements until they are lifted into the air and launched away upon release.");
ConfigManager.defaultConfig.get().addDefault("ExtraAbilities.Cozmyc.BloodShock.Language.Instructions", "Hold Shift to activate, Left Click to lift entities, release Shift to launch.");

ConfigManager.defaultConfig.save();
}
Expand All @@ -117,7 +125,7 @@ public String getAuthor() {

@Override
public String getVersion() {
return "1.0.5";
return "1.0.6";
}

@Override
Expand Down Expand Up @@ -234,37 +242,41 @@ private void bloodbendEntitiesInRange() {
List<Entity> entities = GeneralMethods.getEntitiesAroundPoint(this.player.getLocation(), this.range);

boolean canBendUndead = ConfigManager.defaultConfig.get()
.getBoolean("Abilities.Water.Bloodbending.CanBeUsedOnUndeadMobs")
&& this.useGlobalConfig;
.getBoolean("ExtraAbilities.Cozmyc.BloodShock.UndeadMobs");

boolean canBendOtherBloodbenders = ConfigManager.defaultConfig.get()
.getBoolean("Abilities.Water.Bloodbending.CanBloodbendOtherBloodbenders")
&& this.useGlobalConfig;
.getBoolean("ExtraAbilities.Cozmyc.BloodShock.OtherBloodbenders");

boolean canBendBloodless = ConfigManager.defaultConfig.get()
.getBoolean("ExtraAbilities.Cozmyc.BloodShock.Bloodless");

for (Entity entity : entities) {
if (entity == null) continue;
if (entity.isDead()) continue;
if (!(entity instanceof LivingEntity)) continue;
if (entity.getUniqueId() == this.player.getUniqueId()) continue;
if (isBloodless(entity)) continue;
if (!canBendUndead && GeneralMethods.isUndead(entity)) continue;
if (isInProtectedRegion(this.player, entity)) continue;

UUID uuid = entity.getUniqueId();

if (!bloodBent.containsKey(uuid)) {
if (entity instanceof Player) {
BendingPlayer targetPlayer = BendingPlayer.getBendingPlayer((Player) entity);
if (bloodBent.containsKey(uuid)) continue;
if (uuid.equals(this.player.getUniqueId())) continue;
if (!canBendBloodless && isBloodless(entity)) continue;
if (!canBendUndead && GeneralMethods.isUndead(entity)) continue;
if (isInProtectedRegion(this.player, entity)) continue;

if (targetPlayer.canBloodbend() && !canBendOtherBloodbenders) continue;
if (!targetPlayer.canBeBloodbent()) continue;
}
double distance = entity.getLocation().distance(this.player.getLocation());
if (distance > this.range - 0.5) continue;

double distance = entity.getLocation().distance(this.player.getLocation());
if (distance > this.range - 0.5) continue;
if (entity instanceof Player) {
Player targetPlayer = (Player) entity;
BendingPlayer targetBendingPlayer = BendingPlayer.getBendingPlayer(targetPlayer);

bloodbendEntity((LivingEntity) entity);
if (Commands.invincible.contains(targetPlayer.getName())) continue;
if (targetPlayer.getGameMode() == GameMode.SPECTATOR || targetPlayer.getGameMode() == GameMode.CREATIVE) continue;
if (targetBendingPlayer.canBloodbend() && !canBendOtherBloodbenders) continue;
if (!targetBendingPlayer.canBeBloodbent()) continue;
}

bloodbendEntity((LivingEntity) entity);
}

removeOutOfRangeEntities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void onBendingReload(BendingReloadEvent event) {
@EventHandler
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (noPermission(player)) return;
if (!hasPermission(player)) return;

if (event.isSneaking()) {
new BloodShock(player);
} else {
Expand All @@ -72,17 +73,32 @@ public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
}
}

private boolean noPermission(Player player) {
private boolean hasPermission(Player player) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
if (!bPlayer.getBoundAbilityName().equalsIgnoreCase("BloodShock")) return true;
boolean useGlobalConfig = ConfigManager.defaultConfig.get().getBoolean("ExtraAbilities.Cozmyc.BloodShock.UseBloodbendingAbilityConfig");
boolean onlyAtNight = ConfigManager.defaultConfig.get().getBoolean("Abilities.Water.Bloodbending.CanOnlyBeUsedAtNight") && useGlobalConfig;
boolean onlyDuringFullMoon = ConfigManager.defaultConfig.get().getBoolean("Abilities.Water.Bloodbending.CanOnlyBeUsedDuringFullMoon") && useGlobalConfig;

if (!bPlayer.getBoundAbilityName().equalsIgnoreCase("BloodShock")) {
return false;
}

if (player.isOp()) {
return true;
}

boolean onlyAtNight = ConfigManager.defaultConfig.get().getBoolean("ExtraAbilities.Cozmyc.BloodShock.NightOnly");
boolean onlyDuringFullMoon = ConfigManager.defaultConfig.get().getBoolean("ExtraAbilities.Cozmyc.BloodShock.FullMoonOnly");

boolean isFullMoon = ElementalAbility.isFullMoon(player.getWorld());
boolean isDay = ElementalAbility.isDay(player.getWorld());
if (!isFullMoon && onlyDuringFullMoon) return true;
if (isDay && onlyAtNight) return true;
return BloodShock.isInProtectedRegion(player, player);

if (onlyDuringFullMoon && !isFullMoon) {
return false;
}

if (onlyAtNight && isDay) {
return false;
}

return !BloodShock.isInProtectedRegion(player, player);
}

@EventHandler
Expand Down

0 comments on commit ebc3be5

Please sign in to comment.