Skip to content

Commit

Permalink
Change WorldEffect level (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jan 2, 2022
1 parent 728df74 commit 67c8431
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>sh.reece</groupId>
<artifactId>servertools</artifactId>
<version>6.3.2</version>
<version>6.3.3</version>

<name>servertools</name>
<url>https://reece.sh</url>
Expand Down
41 changes: 34 additions & 7 deletions src/main/java/sh/reece/events/WorldEffects.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sh.reece.events;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand All @@ -18,7 +21,9 @@ public class WorldEffects implements Listener {// CommandExecutor
private static Main plugin;
//private FileConfiguration config;
private String Section;
private HashMap<String, String> world_effect = new HashMap<String, String>();

// WorldName, <PotionEffect, LevelEffect>
private Map<String, List<Object>> world_effect = new HashMap<String, List<Object>>();
private HashMap<Player, PotionEffectType> affectedPlayers = new HashMap<Player, PotionEffectType>();;

public WorldEffects(Main instance) {
Expand All @@ -29,9 +34,26 @@ public WorldEffects(Main instance) {
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);

for(String wEff : plugin.getConfig().getStringList(Section+".worlds")) {
world_effect.put(wEff.split(":")[0], wEff.split(":")[1]);
}
}
String[] wEffSplit = wEff.split(":");

int value = 1;
if(wEffSplit.length > 2) {
try { // effect value level
value = Integer.valueOf(wEffSplit[2]);
} catch (Exception e) {
Main.logging(wEffSplit[2] + " is not a valid number");
}
}

List<Object> potionEffect = new ArrayList<Object>();
potionEffect.add(wEffSplit[1]); // NIGHT_VISION
potionEffect.add(value); // 1

world_effect.put(wEffSplit[0], potionEffect);
Main.logging("WorldEffect: " + wEffSplit[0] + " " + wEffSplit[1] + " " + value);
}
}

}

@EventHandler
Expand All @@ -50,9 +72,14 @@ public void addEffect(Player p) {

removeEffect(p);// removes precious effect from last world change, if any

if(world_effect.containsKey(w)) {
PotionEffectType potion = PotionEffectType.getByName(world_effect.get(w).toUpperCase());
p.addPotionEffect(new PotionEffect(potion, Integer.MAX_VALUE, 1));
if(world_effect.containsKey(w)) {

List<Object> potionEffect = world_effect.get(w);
String worldname = (String) potionEffect.get(0);
int value = (int) potionEffect.get(1);

PotionEffectType potion = PotionEffectType.getByName(worldname.toUpperCase());
p.addPotionEffect(new PotionEffect(potion, Integer.MAX_VALUE, value));
affectedPlayers.put(p, potion);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Events:
Enabled: true
# https://helpch.at/docs/1.12.2/index.html?org/bukkit/potion/PotionEffectType.html
worlds:
- 'world:NIGHT_VISION'
- 'world:NIGHT_VISION:1'
ChatJoinMOTD:
Enabled: true
Expand Down

0 comments on commit 67c8431

Please sign in to comment.