Skip to content

Commit

Permalink
Remake sound signs. Resolves #366
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Apr 21, 2018
1 parent e68afb8 commit a207333
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
*/
package io.github.dre2n.dungeonsxl.sign.message;

import de.erethon.commons.misc.EnumUtil;
import de.erethon.commons.misc.NumberUtil;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.sign.DSignType;
import io.github.dre2n.dungeonsxl.sign.DSignTypeDefault;
import io.github.dre2n.dungeonsxl.world.DGameWorld;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Material;
import org.bukkit.SoundCategory;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;

Expand All @@ -35,7 +37,10 @@ public class SoundMessageSign extends DSign {

// Variables
private boolean initialized;
private String msg;
private String sound;
private SoundCategory category;
private float volume;
private float pitch;
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<>();

public SoundMessageSign(Sign sign, String[] lines, DGameWorld gameWorld) {
Expand All @@ -54,32 +59,49 @@ public boolean check() {
@Override
public void onInit() {
if (!lines[1].isEmpty()) {
String msg = getGame().getRules().getMessage(NumberUtil.parseInt(lines[1]));
if (msg != null) {
this.msg = msg;
getSign().getBlock().setType(Material.AIR);
sound = lines[1];
if (!lines[2].isEmpty()) {
String[] args = lines[2].split(",");
if (args.length >= 1) {
category = EnumUtil.getEnumIgnoreCase(SoundCategory.class, args[0]);
if (category == null) {
category = SoundCategory.MASTER;
}
}
if (args.length == 3) {
volume = (float) NumberUtil.parseDouble(args[1], 5.0);
pitch = (float) NumberUtil.parseDouble(args[2], 1.0);
}
}
getSign().getBlock().setType(Material.AIR);
initialized = true;
} else {
markAsErroneous();
}

initialized = true;
}

@Override
public void onTrigger() {
if (initialized) {
for (Player player : getGameWorld().getWorld().getPlayers()) {
player.playSound(getSign().getLocation(), sound, category, volume, pitch);
}
remove();
}
}

@Override
public boolean onPlayerTrigger(Player player) {
if (initialized) {
remove();
if (!done.contains(player)) {
done.add(player);
player.playSound(getSign().getLocation(), sound, category, volume, pitch);
}

if (done.size() >= getGameWorld().getWorld().getPlayers().size()) {
remove();
}
}

return true;
}

Expand Down

0 comments on commit a207333

Please sign in to comment.