-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic NBS song playing system
- Loading branch information
1 parent
e3444ec
commit 6f326e1
Showing
22 changed files
with
1,143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/iantapply/wynncraft/command/commands/nbs/NbsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.iantapply.wynncraft.command.commands.nbs; | ||
|
||
import com.iantapply.wynncraft.command.WynncraftCommand; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class NbsCommand extends WynncraftCommand { | ||
@Override | ||
public String name() { | ||
return "nbs"; | ||
} | ||
|
||
@Override | ||
public String syntax() { | ||
return "nbs <play|stop> <args>"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Handles the testing and playing of NBS files."; | ||
} | ||
|
||
@Override | ||
public ArrayList<WynncraftCommand> subcommands() { | ||
ArrayList<WynncraftCommand> subcommands = new ArrayList<>(); | ||
subcommands.add(new NbsPlayCommand()); | ||
subcommands.add(new NbsStopCommand()); | ||
|
||
return subcommands; | ||
} | ||
|
||
@Override | ||
public int minArgs() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public int maxArgs() { | ||
return 2; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) {} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/iantapply/wynncraft/command/commands/nbs/NbsCore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.iantapply.wynncraft.command.commands.nbs; | ||
|
||
import com.iantapply.wynncraft.Wynncraft; | ||
import com.iantapply.wynncraft.nbs.players.PlayerOrientedSongPlayer; | ||
|
||
public class NbsCore { | ||
public static PlayerOrientedSongPlayer player; | ||
|
||
public void initialize() { | ||
Wynncraft.getInstance().getCommandCore().stageCommand(new NbsCommand()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/iantapply/wynncraft/command/commands/nbs/NbsPlayCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.iantapply.wynncraft.command.commands.nbs; | ||
|
||
import com.iantapply.wynncraft.Wynncraft; | ||
import com.iantapply.wynncraft.command.WynncraftCommand; | ||
import com.iantapply.wynncraft.nbs.handling.NBSFormatDecoder; | ||
import com.iantapply.wynncraft.nbs.handling.NBSSong; | ||
import com.iantapply.wynncraft.nbs.players.PlayerOrientedSongPlayer; | ||
import org.bukkit.SoundCategory; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
|
||
public class NbsPlayCommand extends WynncraftCommand { | ||
@Override | ||
public String name() { | ||
return "play"; | ||
} | ||
|
||
@Override | ||
public String syntax() { | ||
return "play <file name>"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Plays an NBS file from the plugins folder."; | ||
} | ||
|
||
@Override | ||
public int minArgs() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public int maxArgs() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
try { | ||
Player player = (Player) sender; | ||
File songFile = new File("./plugins/" + args[0]); | ||
InputStream inputStreamSong = new FileInputStream(songFile); | ||
NBSSong song = NBSFormatDecoder.parse(inputStreamSong); | ||
NbsCore.player = new PlayerOrientedSongPlayer(Wynncraft.getInstance().getNbsCore(), song); | ||
NbsCore.player.setPlayer(player); | ||
NbsCore.player.setSoundCategory(SoundCategory.RECORDS); | ||
|
||
NbsCore.player.addPlayer(player); | ||
NbsCore.player.setPlaying(true); | ||
sender.sendMessage("Started playing NBS song: " + args[0]); | ||
} catch (Exception e) { | ||
sender.sendMessage("The provided file does not exist. Please provide a valid NBS file in the plugins directory."); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/iantapply/wynncraft/command/commands/nbs/NbsStopCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.iantapply.wynncraft.command.commands.nbs; | ||
|
||
import com.iantapply.wynncraft.command.WynncraftCommand; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class NbsStopCommand extends WynncraftCommand { | ||
@Override | ||
public String name() { | ||
return "stop"; | ||
} | ||
|
||
@Override | ||
public String syntax() { | ||
return "stop"; | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Stops playing the currently playing NBS song."; | ||
} | ||
|
||
@Override | ||
public int minArgs() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int maxArgs() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
try { | ||
NbsCore.player.destroy(); | ||
sender.sendMessage("Stopped playing NBS song."); | ||
} catch(Exception e) { | ||
sender.sendMessage("Could not stop playing NBS song."); | ||
} | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
src/main/java/com/iantapply/wynncraft/event/PlayerJoinEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package com.iantapply.wynncraft.event; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
|
||
public class PlayerJoinEvent { | ||
public class PlayerJoinEvent implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) { | ||
// TODO: Create a model that will store the players data upon joining, that including the stats from DB and NBS player instance | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/iantapply/wynncraft/nbs/CustomInstrument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.iantapply.wynncraft.nbs; | ||
|
||
import com.iantapply.wynncraft.nbs.enums.Sound; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomInstrument{ | ||
private final byte index; | ||
private final String name; | ||
private final String soundFileName; | ||
private org.bukkit.Sound sound; | ||
|
||
public CustomInstrument(byte index, String name, String soundFileName) { | ||
this.index = index; | ||
this.name = name; | ||
this.soundFileName = soundFileName.replaceAll(".ogg", ""); | ||
if (this.soundFileName.equalsIgnoreCase("pling")){ | ||
this.sound = Sound.NOTE_PLING.bukkitSound(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.iantapply.wynncraft.nbs; | ||
|
||
import com.iantapply.wynncraft.nbs.utils.InstrumentUtils; | ||
|
||
public class Instrument { | ||
|
||
public static org.bukkit.Sound getInstrument(byte instrument) { | ||
return org.bukkit.Sound.valueOf(getInstrumentName(instrument)); | ||
} | ||
|
||
public static String getInstrumentName(byte instrument) { | ||
return InstrumentUtils.getInstrumentName(instrument); | ||
} | ||
|
||
public static org.bukkit.Instrument getBukkitInstrument(byte instrument) { | ||
return InstrumentUtils.getBukkitInstrument(instrument); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.iantapply.wynncraft.nbs; | ||
|
||
import com.iantapply.wynncraft.nbs.players.NBSSongPlayer; | ||
import lombok.Getter; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
@Getter | ||
public class NBSCore { | ||
public HashMap<String, ArrayList<NBSSongPlayer>> playingSongs = new HashMap<>(); | ||
public HashMap<String, Byte> playerVolume = new HashMap<>(); | ||
public NBSCore instance; | ||
|
||
public NBSCore() { | ||
this.instance = this; | ||
} | ||
|
||
public boolean isReceivingSong(Player p) { | ||
return ((this.playingSongs.get(p.getName()) != null) && (!this.playingSongs.get(p.getName()).isEmpty())); | ||
} | ||
|
||
public void stopPlaying(Player p) { | ||
if (this.playingSongs.get(p.getName()) == null) { | ||
return; | ||
} | ||
for (NBSSongPlayer s : this.playingSongs.get(p.getName())) { | ||
s.removePlayer(p); | ||
} | ||
} | ||
|
||
public void setPlayerVolume(Player p, byte volume) { | ||
this.playerVolume.put(p.getName(), volume); | ||
} | ||
|
||
public byte getPlayerVolume(Player p) { | ||
Byte b = this.playerVolume.get(p.getName()); | ||
if (b == null) { | ||
b = 100; | ||
playerVolume.put(p.getName(), b); | ||
} | ||
return b; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/iantapply/wynncraft/nbs/enums/NotePitch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.iantapply.wynncraft.nbs.enums; | ||
|
||
public enum NotePitch { | ||
|
||
NOTE_0(0, 0.5F), | ||
NOTE_1(1, 0.53F), | ||
NOTE_2(2, 0.56F), | ||
NOTE_3(3, 0.6F), | ||
NOTE_4(4, 0.63F), | ||
NOTE_5(5, 0.67F), | ||
NOTE_6(6, 0.7F), | ||
NOTE_7(7, 0.76F), | ||
NOTE_8(8, 0.8F), | ||
NOTE_9(9, 0.84F), | ||
NOTE_10(10, 0.9F), | ||
NOTE_11(11, 0.94F), | ||
NOTE_12(12, 1.0F), | ||
NOTE_13(13, 1.06F), | ||
NOTE_14(14, 1.12F), | ||
NOTE_15(15, 1.18F), | ||
NOTE_16(16, 1.26F), | ||
NOTE_17(17, 1.34F), | ||
NOTE_18(18, 1.42F), | ||
NOTE_19(19, 1.5F), | ||
NOTE_20(20, 1.6F), | ||
NOTE_21(21, 1.68F), | ||
NOTE_22(22, 1.78F), | ||
NOTE_23(23, 1.88F), | ||
NOTE_24(24, 2.0F); | ||
|
||
public final int note; | ||
public final float pitch; | ||
|
||
NotePitch(int note, float pitch) { | ||
this.note = note; | ||
this.pitch = pitch; | ||
} | ||
|
||
public static float getPitch(int note) { | ||
for (NotePitch notePitch : values()) { | ||
if (notePitch.note == note) { | ||
return notePitch.pitch; | ||
} | ||
} | ||
|
||
return 0.0F; | ||
} | ||
} |
Oops, something went wrong.