Add custom potion duration, Add cancel potion effects on warmup cancel option

This commit is contained in:
Jakub Kolář 2017-08-03 19:54:29 +02:00
parent ffac637904
commit c395e315f1
7 changed files with 31 additions and 24 deletions

View File

@ -63,8 +63,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>

View File

@ -315,19 +315,13 @@ public class BoosConfigManager {
return conf.getString("options.messages.paid_for_command", "Price of &command& was %s and you now have %s");
}
static Map<String, Integer> getPotionEffects(String regexCommand, Player player) {
static List<String> getPotionEffects(String regexCommand, Player player) {
String group = getCommandGroup(player);
Map<String, Integer> result = new HashMap<>();
List<String> temp = conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion");
temp.forEach(entry -> {
String[] item;
item = entry.split(",");
if (item.length == 2) {
result.put(item[0], Integer.valueOf(item[1]));
}
});
return conf.getStringList("commands.groups." + group + "." + regexCommand + ".potion");
}
return result;
public static boolean getCancelPotionsOnWarmupCancel() {
return conf.getBoolean("options.options.cancel_potions_on_warmup_cancel", false);
}
public static double getPrice(String regexCommand, Player player) {

View File

@ -6,6 +6,7 @@ import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import cz.boosik.boosCooldown.BoosCoolDown;
@ -17,18 +18,24 @@ public class BoosWarmUpManager {
private static final ConcurrentHashMap<String, BoosWarmUpTimer> playercommands = new ConcurrentHashMap<>();
private static void applyPotionEffect(Player player, String regexCommand, int warmUpSeconds) {
BoosConfigManager.getPotionEffects(regexCommand, player).forEach((potion, potionStrength) -> {
PotionEffectType effect = PotionEffectType.getByName(potion);
player.addPotionEffect(
effect.createEffect(warmUpSeconds * 20, potionStrength - 1),
true);
});
for (String potionUnparsed : BoosConfigManager.getPotionEffects(regexCommand, player)) {
String[] potionParsed = potionUnparsed.split(",");
PotionEffectType type = PotionEffectType.getByName(potionParsed[0]);
final int duration = potionParsed.length == 3 ? Integer.valueOf(potionParsed[2]) * 20 : warmUpSeconds * 20;
player.addPotionEffect(new PotionEffect(type, duration, Integer.valueOf(potionParsed[1]) - 1), true);
}
}
public static void cancelWarmUps(Player player) {
Iterator<String> iter = ((Map<String, BoosWarmUpTimer>) playercommands).keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getUniqueId() + "@")) {
final String key = iter.next();
if (key.startsWith(player.getUniqueId() + "@")) {
if (BoosConfigManager.getCancelPotionsOnWarmupCancel()) {
for (String potionUnparsed : BoosConfigManager.getPotionEffects(playercommands.get(key).getRegexCommand(), player)) {
player.removePotionEffect(PotionEffectType.getByName(potionUnparsed.split(",")[0]));
}
}
killTimer(player);
iter.remove();
}

View File

@ -53,4 +53,8 @@ public class BoosWarmUpTimer extends TimerTask {
}
}
}
public String getRegexCommand() {
return regexCommand;
}
}

View File

@ -28,6 +28,8 @@ options:
cancel_warmup_on_sprint: false
#should warmups be canceled when player changes gamemode?
cancel_warmup_on_gamemode_change: false
#should potion effects be cancelled when warmups are cancelled?
cancel_potions_on_warmup_cancel: false
#should container access be disable during warmups?
block_interact_during_warmup: false
#should cooldowns be cleared on server restart?
@ -146,10 +148,10 @@ commands:
#price of 10 money
price: 10.0
limit: 5
#potion effect and its strength that will affect player for the warmup time (5 seconds here) has to be one from this list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
#potion effect and its strength and its duration (duration is optional and defaults to warmup duration) that will affect player for the warmup time (5 seconds here) has to be one from this list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html
potion:
- WEAKNESS,3
- SLOW,5
- SLOW,5,10
/test:
#message that is sent to player when he uses this command
message: You just used /test!

View File

@ -1,6 +1,6 @@
name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.14.0
version: 3.14.1
authors: [LordBoos (boosik)]
softdepend: [Vault, PlayerPoints]
description: >

View File

@ -11,7 +11,7 @@
<packaging>pom</packaging>
<url>http://maven.apache.org</url>
<properties>
<boosCooldowns.version>3.14.0</boosCooldowns.version>
<boosCooldowns.version>3.14.1</boosCooldowns.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<minecraft.version>1.12</minecraft.version>