Skip to content

Commit ab67f51

Browse files
committed
Restructured whole api
All classes moved to packages. Changed main class to NoteBlockAPI. Many lines of code to make new package structure compatible with old plugins.
1 parent ee63a7b commit ab67f51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2365
-188
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
<groupId>com.xxmicloxx</groupId>
88
<artifactId>NoteBlockAPI</artifactId>
9-
<version>1.2.0</version>
9+
<version>1.2.1</version>
1010
<name>NoteBlockAPI</name>
1111

1212
<properties>
1313
<maven.compiler.source>1.8</maven.compiler.source>
1414
<maven.compiler.target>1.8</maven.compiler.target>
15-
<mainClass>com.xxmicloxx.NoteBlockAPI.NoteBlockPlayerMain</mainClass>
15+
<mainClass>com.xxmicloxx.NoteBlockAPI.NoteBlockAPI</mainClass>
1616
</properties>
1717

1818
<repositories>

src/main/java/com/xxmicloxx/NoteBlockAPI/CompatibilityUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Fields/methods for reflection & version checking
1414
*
1515
*/
16+
@Deprecated
1617
public class CompatibilityUtils {
1718

1819
public static final String OBC_DIR = Bukkit.getServer().getClass().getPackage().getName();
@@ -83,7 +84,7 @@ protected static boolean isSoundCategoryCompatible() {
8384
* @param volume
8485
* @param pitch
8586
*/
86-
protected static void playSound(Player player, Location location, String sound,
87+
public static void playSound(Player player, Location location, String sound,
8788
SoundCategory category, float volume, float pitch) {
8889
try {
8990
if (isSoundCategoryCompatible()) {
@@ -165,5 +166,5 @@ public static ArrayList<CustomInstrument> get1_12Instruments(){
165166
instruments.add(new CustomInstrument((byte) 0, "Xylophone", "xylobone.ogg"));
166167
return instruments;
167168
}
168-
169+
169170
}
Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

3+
import com.xxmicloxx.NoteBlockAPI.model.Sound;
4+
35
/**
46
* Create custom instruments from a sound file
57
*
68
*/
7-
public class CustomInstrument {
8-
9+
@Deprecated
10+
public class CustomInstrument{
11+
912
private byte index;
1013
private String name;
1114
private String soundFileName;
1215
private org.bukkit.Sound sound;
1316

14-
/**
15-
* Creates a CustomInstrument
16-
* @deprecated Unused parameters
17-
*/
18-
@Deprecated
19-
public CustomInstrument(byte index, String name, String soundFileName, byte pitch, byte press) {
20-
this.index = index;
21-
this.name = name;
22-
this.soundFileName = soundFileName.replaceAll(".ogg", "");
23-
if (this.soundFileName.equalsIgnoreCase("pling")){
24-
this.sound = Sound.getFromBukkitName("BLOCK_NOTE_PLING");
25-
}
26-
}
27-
2817
/**
2918
* Creates a CustomInstrument
3019
* @param index
@@ -36,7 +25,7 @@ public CustomInstrument(byte index, String name, String soundFileName) {
3625
this.name = name;
3726
this.soundFileName = soundFileName.replaceAll(".ogg", "");
3827
if (this.soundFileName.equalsIgnoreCase("pling")){
39-
this.sound = Sound.getFromBukkitName("BLOCK_NOTE_PLING");
28+
this.sound = Sound.NOTE_PLING.bukkitSound();
4029
}
4130
}
4231

@@ -55,30 +44,21 @@ public byte getIndex() {
5544
public String getName() {
5645
return name;
5746
}
58-
47+
5948
/**
60-
* Gets file name of the sound
61-
* @deprecated misleading name
49+
* Gets the org.bukkit.Sound enum for this CustomInstrument
50+
* @return org.bukkit.Sound enum
6251
*/
63-
@Deprecated
64-
public String getSoundfile() {
65-
return getSoundFileName();
52+
public org.bukkit.Sound getSound() {
53+
return sound;
6654
}
67-
55+
6856
/**
6957
* Gets file name of the sound
70-
* @return file name
58+
* @deprecated misleading name
7159
*/
72-
public String getSoundFileName() {
60+
public String getSoundfile() {
7361
return soundFileName;
7462
}
7563

76-
/**
77-
* Gets the org.bukkit.Sound enum for this CustomInstrument
78-
* @return org.bukkit.Sound enum
79-
*/
80-
public org.bukkit.Sound getSound() {
81-
return sound;
82-
}
83-
8464
}

src/main/java/com/xxmicloxx/NoteBlockAPI/FadeType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

3+
@Deprecated
34
public enum FadeType {
45

56
FADE_LINEAR

src/main/java/com/xxmicloxx/NoteBlockAPI/Instrument.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

3+
import com.xxmicloxx.NoteBlockAPI.model.Sound;
4+
35
/**
46
* Various methods for working with instruments
57
* @deprecated Moved to InstrumentUtils
@@ -48,7 +50,7 @@ public static String getInstrumentName(byte instrument) {
4850
default:
4951
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_HARP").name();
5052
}
51-
}
53+
}
5254

5355
/**
5456
* Returns the name of the org.bukkit.Instrument enum for the current server version
@@ -71,15 +73,15 @@ public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
7173
if (CompatibilityUtils.isPost1_12()) {
7274
switch (instrument) {
7375
case 5:
74-
return org.bukkit.Instrument.GUITAR;
76+
return org.bukkit.Instrument.valueOf("GUITAR");
7577
case 6:
76-
return org.bukkit.Instrument.FLUTE;
78+
return org.bukkit.Instrument.valueOf("FLUTE");
7779
case 7:
78-
return org.bukkit.Instrument.BELL;
80+
return org.bukkit.Instrument.valueOf("BELL");
7981
case 8:
80-
return org.bukkit.Instrument.CHIME;
82+
return org.bukkit.Instrument.valueOf("CHIME");
8183
case 9:
82-
return org.bukkit.Instrument.XYLOPHONE;
84+
return org.bukkit.Instrument.valueOf("XYLOPHONE");
8385
}
8486
}
8587
return org.bukkit.Instrument.PIANO;
@@ -116,5 +118,5 @@ public static byte getCustomInstrumentFirstIndex() {
116118
}
117119
return 5;
118120
}
119-
121+
120122
}

src/main/java/com/xxmicloxx/NoteBlockAPI/Interpolator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* <font size="-1" color="#336699">Copyright 2002 MBARI.<br>
2121
* MBARI Proprietary Information. All rights reserved.</font><br><hr><br>
2222
*/
23+
@Deprecated
2324
public class Interpolator {
2425

2526
public static double[] interpLinear(double[] x, double[] y, double[] xi) throws IllegalArgumentException {

src/main/java/com/xxmicloxx/NoteBlockAPI/Layer.java

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,13 @@
77
* A Layer can have a maximum of one note per tick (20 ticks a second)
88
*
99
*/
10-
public class Layer {
10+
@Deprecated
11+
public class Layer{
1112

1213
private HashMap<Integer, Note> notesAtTicks = new HashMap<Integer, Note>();
1314
private byte volume = 100;
1415
private String name = "";
1516

16-
/**
17-
* Gets the notes in the Layer with the tick they are created as a hash map.
18-
* @return HashMap of notes with the tick they are played at
19-
* @Deprecated Method name is vague
20-
*/
21-
@Deprecated
22-
public HashMap<Integer, Note> getHashMap() {
23-
return getNotesAtTicks();
24-
}
25-
26-
/**
27-
* Sets the notes in the Layer with the tick they are created as a hash map
28-
* @Deprecated Method name is vague
29-
*/
30-
@Deprecated
31-
public void setHashMap(HashMap<Integer, Note> hashMap) {
32-
setNotesAtTicks(hashMap);
33-
}
34-
35-
/**
36-
* Gets the notes in the Layer with the tick they are created as a hash map
37-
* @return HashMap of notes with the tick they are played at
38-
*/
39-
public HashMap<Integer, Note> getNotesAtTicks() {
40-
return notesAtTicks;
41-
}
42-
43-
/**
44-
* Sets the notes in the Layer with the tick they are created as a hash map
45-
*/
46-
public void setNotesAtTicks(HashMap<Integer, Note> notesAtTicks) {
47-
this.notesAtTicks = notesAtTicks;
48-
}
49-
5017
/**
5118
* Gets the name of the Layer
5219
*/
@@ -90,5 +57,24 @@ public byte getVolume() {
9057
public void setVolume(byte volume) {
9158
this.volume = volume;
9259
}
93-
60+
61+
/**
62+
* Gets the notes in the Layer with the tick they are created as a hash map.
63+
* @return HashMap of notes with the tick they are played at
64+
* @Deprecated Method name is vague
65+
*/
66+
@Deprecated
67+
public HashMap<Integer, Note> getHashMap() {
68+
return notesAtTicks;
69+
}
70+
71+
/**
72+
* Sets the notes in the Layer with the tick they are created as a hash map
73+
* @Deprecated Method name is vague
74+
*/
75+
@Deprecated
76+
public void setHashMap(HashMap<Integer, Note> hashMap) {
77+
this.notesAtTicks = notesAtTicks;
78+
}
79+
9480
}

src/main/java/com/xxmicloxx/NoteBlockAPI/NBSDecoder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
import org.bukkit.Bukkit;
1515
import org.bukkit.ChatColor;
1616

17+
import com.xxmicloxx.NoteBlockAPI.utils.InstrumentUtils;
18+
1719
/**
1820
* Utils for reading Note Block Studio data
1921
*
2022
*/
23+
@Deprecated
2124
public class NBSDecoder {
22-
25+
2326
/**
2427
* Parses a Song from a Note Block Studio project file (.nbs)
2528
* @see Song

src/main/java/com/xxmicloxx/NoteBlockAPI/Note.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @see NotePitch
66
*
77
*/
8+
@Deprecated
89
public class Note {
910

1011
private byte instrument;
@@ -30,5 +31,5 @@ public byte getKey() {
3031
public void setKey(byte key) {
3132
this.key = key;
3233
}
33-
34+
3435
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.xxmicloxx.NoteBlockAPI;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.UUID;
8+
9+
import org.bstats.Metrics;
10+
import org.bukkit.Bukkit;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.plugin.java.JavaPlugin;
13+
14+
import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer;
15+
16+
public class NoteBlockAPI extends JavaPlugin {
17+
18+
public static NoteBlockAPI plugin;
19+
20+
private Map<UUID, ArrayList<SongPlayer>> playingSongs =
21+
Collections.synchronizedMap(new HashMap<UUID, ArrayList<SongPlayer>>());
22+
private Map<UUID, Byte> playerVolume = Collections.synchronizedMap(new HashMap<UUID, Byte>());
23+
24+
private boolean disabling = false;
25+
26+
/**
27+
* Returns true if a Player is currently receiving a song
28+
* @param player
29+
* @return is receiving a song
30+
*/
31+
public static boolean isReceivingSong(Player player) {
32+
return ((plugin.playingSongs.get(player.getUniqueId()) != null)
33+
&& (!plugin.playingSongs.get(player.getUniqueId()).isEmpty()));
34+
}
35+
36+
/**
37+
* Stops the song for a Player
38+
* @param player
39+
*/
40+
public static void stopPlaying(Player player) {
41+
if (plugin.playingSongs.get(player.getUniqueId()) == null) {
42+
return;
43+
}
44+
for (SongPlayer songPlayer : plugin.playingSongs.get(player.getUniqueId())) {
45+
songPlayer.removePlayer(player);
46+
}
47+
}
48+
49+
/**
50+
* Sets the volume for a given Player
51+
* @param player
52+
* @param volume
53+
*/
54+
public static void setPlayerVolume(Player player, byte volume) {
55+
plugin.playerVolume.put(player.getUniqueId(), volume);
56+
}
57+
58+
/**
59+
* Gets the volume for a given Player
60+
* @param player
61+
* @return volume (byte)
62+
*/
63+
public static byte getPlayerVolume(Player player) {
64+
Byte byteObj = plugin.playerVolume.get(player.getUniqueId());
65+
if (byteObj == null) {
66+
byteObj = 100;
67+
plugin.playerVolume.put(player.getUniqueId(), byteObj);
68+
}
69+
return byteObj;
70+
}
71+
72+
public static ArrayList<SongPlayer> getSongPlayersByPlayer(Player player){
73+
return plugin.playingSongs.get(player.getUniqueId());
74+
}
75+
76+
public static void setSongPlayersByPlayer(Player player, ArrayList<SongPlayer> songs){
77+
plugin.playingSongs.put(player.getUniqueId(), songs);
78+
}
79+
80+
@Override
81+
public void onEnable() {
82+
plugin = this;
83+
new Metrics(this);
84+
new NoteBlockPlayerMain().onEnable();
85+
}
86+
87+
@Override
88+
public void onDisable() {
89+
disabling = true;
90+
Bukkit.getScheduler().cancelTasks(this);
91+
NoteBlockPlayerMain.plugin.onDisable();
92+
}
93+
94+
public void doSync(Runnable runnable) {
95+
getServer().getScheduler().runTask(this, runnable);
96+
}
97+
98+
public void doAsync(Runnable runnable) {
99+
getServer().getScheduler().runTaskAsynchronously(this, runnable);
100+
}
101+
102+
public boolean isDisabling() {
103+
return disabling;
104+
}
105+
106+
}

0 commit comments

Comments
 (0)