Skip to content

Commit

Permalink
add allyPotion
Browse files Browse the repository at this point in the history
  • Loading branch information
matsu1213 committed Aug 5, 2024
1 parent 8179fbc commit e5236a6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/main/java/net/azisaba/leoncsaddon/WeaponConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -53,8 +55,31 @@ public void init(){
double reduceDamage = configuration.getDouble(key + ".reduceDamage",0);
double projectileSizeXZ = configuration.getDouble(key + ".projectileSize.xz",0);
double projectileSizeY = configuration.getDouble(key + ".projectileSize.y",0);
String[] allyPotion = configuration.getString(key + ".allypotion").split(",");
List<PotionEffect> potionEffectList = new ArrayList<>();

weaponsMap.put(key,new WeaponConfigData(key, type, isMain, requirements, damage, headshotBonusDamage, criticalBonusDamage, guardMult, walkSpeed, canSprint, reduceStartTick, reduceEndTick, reduceDamage, projectileSizeXZ, projectileSizeY));
for(int i = 0; i < allyPotion.length; ++i) {
String potFX = allyPotion[i];
potFX = potFX.replace(" ", "");
String[] args = potFX.split("-");
if (args.length == 3) {
try {
PotionEffectType potionType = PotionEffectType.getByName(args[0].toUpperCase());
int duration = Integer.parseInt(args[1]);
if (potionType.getDurationModifier() != 1.0) {
double maths = (double)duration * (1.0 / potionType.getDurationModifier());
duration = (int)maths;
}
potionEffectList.add(potionType.createEffect(duration, Integer.parseInt(args[2]) - 1));
} catch (Exception var15) {
System.out.println("[LeonCSAddon] '" + potFX + "' of weapon '" + key + "' has an incorrect potion type, duration or level!");
}
} else {
System.out.println("[LeonCSAddon] '" + potFX + "' of weapon '" + key + "' has an invalid format! The correct format is: Potion-Duration-Level!");
}
}

weaponsMap.put(key,new WeaponConfigData(key, type, isMain, requirements, damage, headshotBonusDamage, criticalBonusDamage, guardMult, walkSpeed, canSprint, reduceStartTick, reduceEndTick, reduceDamage, projectileSizeXZ, projectileSizeY, potionEffectList));

});
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/azisaba/leoncsaddon/WeaponConfigData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.azisaba.leoncsaddon;

import org.bukkit.potion.PotionEffect;

import java.util.List;

public class WeaponConfigData {
Expand All @@ -14,6 +16,8 @@ public class WeaponConfigData {
public final double projectileSizeXZ;
public final double projectileSizeY;

public final List<PotionEffect> allyPotion;

public final double guardMult;
public final float walkSpeed;
public final boolean canSprint;
Expand All @@ -22,7 +26,7 @@ public class WeaponConfigData {
public final int reduceEndTick;
public final double reduceDamage;

public WeaponConfigData(String name, List<String> type, boolean isMain, List<String> requirements, double damage, double headshotBonusDamage, double criticalBonusDamage, double guardMult, float walkSpeed, boolean canSprint, int reduceStartTick, int reduceEndTick, double reduceDamage, double projectileSizeXZ, double projectileSizeY){
public WeaponConfigData(String name, List<String> type, boolean isMain, List<String> requirements, double damage, double headshotBonusDamage, double criticalBonusDamage, double guardMult, float walkSpeed, boolean canSprint, int reduceStartTick, int reduceEndTick, double reduceDamage, double projectileSizeXZ, double projectileSizeY, List<PotionEffect> potionEffectList){
this.type = type;
this.isMain = isMain;
this.requirements = requirements;
Expand All @@ -38,6 +42,7 @@ public WeaponConfigData(String name, List<String> type, boolean isMain, List<Str
this.reduceDamage = reduceDamage;
this.projectileSizeXZ = projectileSizeXZ;
this.projectileSizeY = projectileSizeY;
this.allyPotion = potionEffectList;
}

}
31 changes: 31 additions & 0 deletions src/main/java/net/azisaba/leoncsaddon/WeaponPotionListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.azisaba.leoncsaddon;

import com.shampaggon.crackshot.events.WeaponDamageEntityEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.potion.PotionEffect;

public class WeaponPotionListener implements Listener {

@EventHandler
public void onDamage(WeaponDamageEntityEvent e){
if(!(e.getVictim() instanceof Player)) return;

WeaponConfigData data = LeonCSAddon.INSTANCE.getWeaponConfig().getWeaponConfigData(e.getWeaponTitle());

if(data == null) return;

Player victimPlayer = ((Player) e.getVictim());

if(e.getPlayer().getScoreboard().getEntryTeam(e.getPlayer().getName())
== victimPlayer.getScoreboard().getEntryTeam(e.getVictim().getName())){
for(PotionEffect effect: data.allyPotion){
victimPlayer.removePotionEffect(effect.getType());
victimPlayer.addPotionEffect(effect);
}
}

}

}

0 comments on commit e5236a6

Please sign in to comment.