Skip to content

Commit

Permalink
World Effect Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jan 2, 2022
1 parent 67c8431 commit 51e34f5
Show file tree
Hide file tree
Showing 2 changed files with 27 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.3</version>
<version>6.3.4</version>

<name>servertools</name>
<url>https://reece.sh</url>
Expand Down
34 changes: 26 additions & 8 deletions src/main/java/sh/reece/events/WorldEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WorldEffects implements Listener {// CommandExecutor
private String Section;

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

public WorldEffects(Main instance) {
Expand All @@ -45,13 +45,25 @@ public WorldEffects(Main instance) {
}
}

// gets or creates a list of effects & values to add too
List<List<Object>> eff = world_effect.get(wEffSplit[0]);
if(eff == null) {
eff = new ArrayList<List<Object>>();
}

// creates a single effect & its strength value
List<Object> potionEffect = new ArrayList<Object>();
potionEffect.add(wEffSplit[1]); // NIGHT_VISION
potionEffect.add(value); // 1

world_effect.put(wEffSplit[0], potionEffect);
// adds the potion to the eff list, which is a list of all effects for a given world
eff.add(potionEffect);

// saves the new list to the world_effect map
world_effect.put(wEffSplit[0], eff);
Main.logging("WorldEffect: " + wEffSplit[0] + " " + wEffSplit[1] + " " + value);
}

}

}
Expand All @@ -74,13 +86,19 @@ public void addEffect(Player p) {

if(world_effect.containsKey(w)) {

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

PotionEffectType potion = PotionEffectType.getByName(worldname.toUpperCase());
p.addPotionEffect(new PotionEffect(potion, Integer.MAX_VALUE, value));
affectedPlayers.put(p, potion);
// iterates through all effects for a given world
for (List<Object> list : potionEffect) {
String worldname = (String) list.get(0);
int value = (int) list.get(1);

PotionEffectType potion = PotionEffectType.getByName(worldname.toUpperCase());
p.addPotionEffect(new PotionEffect(potion, Integer.MAX_VALUE, value));
affectedPlayers.put(p, potion);
}


}
}

Expand Down

0 comments on commit 51e34f5

Please sign in to comment.