Skip to content

Commit 54f3634

Browse files
authored
Merge pull request #28 from ChafficPlugins/customisable-addiction-and-overdose-effects
feat: made overdose and addiction effects customisable
2 parents d18eb79 + 0ed62de commit 54f3634

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/main/java/de/chafficplugins/mytrip/MyTrip.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.bukkit.plugin.java.JavaPlugin;
2020

2121
import java.io.IOException;
22+
import java.util.List;
2223
import java.util.logging.Logger;
2324

2425
public final class MyTrip extends JavaPlugin {
@@ -80,6 +81,8 @@ public void loadConfig() {
8081
getConfig().addDefault(ConfigStrings.SETTING_PERMISSIONS, false);
8182
getConfig().addDefault(ConfigStrings.SETTING_ALERTS, true);
8283
getConfig().addDefault(ConfigStrings.DISABLE_DRUG_SET, false);
84+
getConfig().addDefault(ConfigStrings.ADDICTION_EFFECTS, List.of("CONFUSION:0"));
85+
getConfig().addDefault(ConfigStrings.OVERDOSE_EFFECTS, List.of("BLINDNESS:0", "NAUSEA:0", "SLOW:0", "SLOW_DIGGING:0", "WEAKNESS:0"));
8386
getConfig().options().header("MyTrip config file");
8487
getConfig().set("version", getDescription().getVersion());
8588
getConfig().options().copyDefaults(true);
@@ -100,6 +103,10 @@ public String getConfigString(String path) {
100103
return getConfig().getString(path);
101104
}
102105

106+
public List<String> getConfigStringList(String path) {
107+
return getConfig().getStringList(path);
108+
}
109+
103110
public void log(String message) {
104111
logger.info(message);
105112
}

src/main/java/de/chafficplugins/mytrip/drugs/objects/Addiction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.bukkit.potion.PotionEffectType;
1313
import org.bukkit.scheduler.BukkitRunnable;
1414

15+
import java.util.Objects;
1516
import java.util.UUID;
1617

1718
import static de.chafficplugins.mytrip.utils.ConfigStrings.*;
@@ -63,7 +64,10 @@ public void run() {
6364

6465
player.damage(intensity);
6566
if(intensity > 5) {
66-
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 60 * intensity, 0));
67+
for(String type: plugin.getConfigStringList(ADDICTION_EFFECTS)) {
68+
String[] split = type.split(":");
69+
player.addPotionEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(split[0])), 60 * intensity, Integer.parseInt(split[2])));
70+
}
6771
}
6872

6973
player.sendTitle(getLocalized(ADDICTION), getLocalized(ADDICTED_TO, CrucialItem.getById(drugId).getName()), 10, 40, 10);

src/main/java/de/chafficplugins/mytrip/drugs/objects/MyDrug.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ public static void doDrug(Player p, ItemStack stack) {
202202
DrugPlayer.addPlayer(dp);
203203
}
204204
if(dp.consume(drug)) {
205-
p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 100*20, 0));
205+
for (String effect : plugin.getConfigStringList(OVERDOSE_EFFECTS)) {
206+
String[] split = effect.split(":");
207+
p.addPotionEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(split[0])), 100*20, Integer.parseInt(split[1])));
208+
}
206209
}
207210
doEffects(p, drug, duration, delay);
208211
}

src/main/java/de/chafficplugins/mytrip/utils/ConfigStrings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class ConfigStrings {
1919
//Messages
2020
public final static String ONLY_PLAYERS_CMD = "only_players_cmd"; //Only players can use this command
2121
public final static String DISABLE_DRUG_SET = "disable_drug_set"; //Only players can use this command
22+
public final static String ADDICTION_EFFECTS = "addiction_effects";
23+
public final static String OVERDOSE_EFFECTS = "overdose_effects";
2224
public final static String UNKNOWN_CMD = "unknown_cmd"; //Unknown command: {0}
2325
public final static String PLAYER_NOT_FOUND = "player_not_found"; //The player {0} was not found
2426
public final static String NO_PERMISSION = "no_permission"; //You don't have the permission to use this command.

0 commit comments

Comments
 (0)