Skip to content

Commit c5e7395

Browse files
committed
1.13 instrument support
1 parent 6230f35 commit c5e7395

File tree

5 files changed

+181
-80
lines changed

5 files changed

+181
-80
lines changed

pom.xml

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,85 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
7-
<groupId>com.xxmicloxx</groupId>
8-
<artifactId>NoteBlockAPI</artifactId>
9-
<version>1.2.0</version>
10-
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.xxmicloxx</groupId>
8+
<artifactId>NoteBlockAPI</artifactId>
9+
<version>1.2.0</version>
10+
1111
<properties>
1212
<maven.compiler.source>1.8</maven.compiler.source>
1313
<maven.compiler.target>1.8</maven.compiler.target>
1414
</properties>
15-
15+
1616
<repositories>
17-
<repository>
18-
<id>spigot-repo</id>
19-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
20-
</repository>
21-
<repository>
22-
<id>bstats-repo</id>
23-
<url>http://repo.bstats.org/content/repositories/releases/</url>
17+
<repository>
18+
<id>spigot-repo</id>
19+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
2420
</repository>
25-
</repositories>
26-
<dependencies>
27-
<dependency>
28-
<groupId>org.bukkit</groupId>
29-
<artifactId>bukkit</artifactId>
30-
<version>1.12-R0.1-SNAPSHOT</version>
31-
<scope>provided</scope>
32-
</dependency>
33-
<dependency>
34-
<groupId>org.bstats</groupId>
35-
<artifactId>bstats-bukkit</artifactId>
36-
<version>1.1</version>
21+
<repository>
22+
<id>bstats-repo</id>
23+
<url>http://repo.bstats.org/content/repositories/releases/</url>
24+
</repository>
25+
</repositories>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.bukkit</groupId>
30+
<artifactId>bukkit</artifactId>
31+
<version>1.12-R0.1-SNAPSHOT</version>
32+
<scope>provided</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.bstats</groupId>
36+
<artifactId>bstats-bukkit</artifactId>
37+
<version>1.1</version>
3738
</dependency>
38-
</dependencies>
39-
<distributionManagement>
40-
<repository>
41-
<id>sinndev-repo</id>
42-
<name>Releases</name>
43-
<url>http://repo.sinndev.com/content/repositories/releases/</url>
44-
</repository>
45-
<snapshotRepository>
46-
<id>sinndev-repo</id>
47-
<name>Snapshots</name>
48-
<url>http://repo.sinndev.com/content/repositories/snapshots/</url>
49-
</snapshotRepository>
50-
</distributionManagement>
51-
<build>
52-
<plugins>
53-
<plugin>
54-
<groupId>org.apache.maven.plugins</groupId>
55-
<artifactId>maven-shade-plugin</artifactId>
56-
<version>2.3</version>
57-
<configuration>
58-
<artifactSet>
59-
<includes>
60-
<include>org.bstats:*</include>
61-
</includes>
62-
</artifactSet>
63-
<relocations>
64-
<relocation>
65-
<pattern>org.bstats</pattern>
66-
<shadedPattern>com.xxmicloxx.NoteBlockAPI</shadedPattern>
67-
</relocation>
68-
</relocations>
69-
</configuration>
70-
<executions>
71-
<execution>
72-
<phase>package</phase>
73-
<goals>
74-
<goal>shade</goal>
75-
</goals>
76-
</execution>
77-
</executions>
78-
</plugin>
79-
</plugins>
80-
</build>
39+
</dependencies>
40+
41+
<distributionManagement>
42+
<repository>
43+
<id>sinndev-repo</id>
44+
<name>Releases</name>
45+
<url>http://repo.sinndev.com/content/repositories/releases/</url>
46+
</repository>
47+
<snapshotRepository>
48+
<id>sinndev-repo</id>
49+
<name>Snapshots</name>
50+
<url>http://repo.sinndev.com/content/repositories/snapshots/</url>
51+
</snapshotRepository>
52+
</distributionManagement>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-shade-plugin</artifactId>
59+
<version>2.3</version>
60+
<configuration>
61+
<artifactSet>
62+
<includes>
63+
<include>org.bstats:*</include>
64+
</includes>
65+
</artifactSet>
66+
<relocations>
67+
<relocation>
68+
<pattern>org.bstats</pattern>
69+
<shadedPattern>com.xxmicloxx.NoteBlockAPI</shadedPattern>
70+
</relocation>
71+
</relocations>
72+
</configuration>
73+
<executions>
74+
<execution>
75+
<phase>package</phase>
76+
<goals>
77+
<goal>shade</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
8185
</project>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ public static Class<?> getCraftBukkitClass(String name){
3535
public static class NoteBlockCompatibility{
3636
public static final int pre1_9 = 0;
3737
public static final int pre1_12 = 1;
38-
public static final int post1_12 = 2;
38+
public static final int v1_12 = 2;
39+
public static final int post1_12 = 3;
40+
public static final int post1_13 = 4;
3941
}
4042

4143
protected static int getCompatibility(){
4244
if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.7")){
4345
return NoteBlockCompatibility.pre1_9;
4446
} else if (Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11")){
4547
return NoteBlockCompatibility.pre1_12;
48+
} else if (Bukkit.getVersion().contains("1.12")){
49+
return NoteBlockCompatibility.v1_12;
4650
} else {
47-
return NoteBlockCompatibility.post1_12;
51+
return NoteBlockCompatibility.post1_13;
4852
}
4953
}
5054

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ public CustomInstrument(byte index, String name, String soundfile, byte pitch, b
2323
this.sound = Sound.valueOf("NOTE_PLING");
2424
break;
2525
case CompatibilityUtils.NoteBlockCompatibility.pre1_12:
26-
case NoteBlockCompatibility.post1_12:
26+
case NoteBlockCompatibility.v1_12:
2727
this.sound = Sound.valueOf("BLOCK_NOTE_PLING");
2828
break;
29+
case NoteBlockCompatibility.post1_13:
30+
this.sound = Sound.valueOf("BLOCK_NOTE_BLOCK_PLING");
31+
break;
2932
}
3033
}
3134
this.pitch = pitch;

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public static Sound getInstrument(byte instrument) {
2222
default:
2323
return Sound.valueOf("NOTE_PIANO");
2424
}
25-
} else {
25+
26+
} else if (CompatibilityUtils.getCompatibility() == NoteBlockCompatibility.pre1_12 ||
27+
CompatibilityUtils.getCompatibility() == NoteBlockCompatibility.v1_12){
2628
switch (instrument) {
2729
case 0:
2830
return Sound.valueOf("BLOCK_NOTE_HARP");
@@ -35,8 +37,7 @@ public static Sound getInstrument(byte instrument) {
3537
case 4:
3638
return Sound.valueOf("BLOCK_NOTE_HAT");
3739
}
38-
39-
if (CompatibilityUtils.getCompatibility() == NoteBlockCompatibility.post1_12){
40+
if (CompatibilityUtils.getCompatibility() == NoteBlockCompatibility.v1_12){
4041
switch (instrument) {
4142
case 5:
4243
return Sound.valueOf("BLOCK_NOTE_GUITAR");
@@ -50,10 +51,33 @@ public static Sound getInstrument(byte instrument) {
5051
return Sound.valueOf("BLOCK_NOTE_XYLOPHONE");
5152
}
5253
}
53-
54-
return Sound.valueOf("BLOCK_NOTE_HARP");
55-
54+
55+
} else if (CompatibilityUtils.getCompatibility() == NoteBlockCompatibility.post1_13) {
56+
switch (instrument) {
57+
case 0:
58+
return Sound.valueOf("BLOCK_NOTE_BLOCK_HARP");
59+
case 1:
60+
return Sound.valueOf("BLOCK_NOTE_BLOCK_BASS");
61+
case 2:
62+
return Sound.valueOf("BLOCK_NOTE_BLOCK_BASEDRUM");
63+
case 3:
64+
return Sound.valueOf("BLOCK_NOTE_BLOCK_SNARE");
65+
case 4:
66+
return Sound.valueOf("BLOCK_NOTE_BLOCK_HAT");
67+
case 5:
68+
return Sound.valueOf("BLOCK_NOTE_BLOCK_GUITAR");
69+
case 6:
70+
return Sound.valueOf("BLOCK_NOTE_BLOCK_FLUTE");
71+
case 7:
72+
return Sound.valueOf("BLOCK_NOTE_BLOCK_BELL");
73+
case 8:
74+
return Sound.valueOf("BLOCK_NOTE_BLOCK_CHIME");
75+
case 9:
76+
return Sound.valueOf("BLOCK_NOTE_BLOCK_XYLOPHONE");
77+
}
5678
}
79+
80+
return Sound.valueOf("BLOCK_NOTE_BLOCK_HARP");
5781
}
5882

5983
public static org.bukkit.Instrument getBukkitInstrument(byte instrument) {
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.xxmicloxx.NoteBlockAPI;
2+
3+
/**
4+
* Version independent Spigot sounds.
5+
*
6+
* Enum mapping to sound names for different
7+
* Minecraft versions.
8+
*
9+
* @see https://gist.github.com/NiklasEi/7bd0ffd136f8459df0940e4501d47a8a
10+
* @author NiklasEi
11+
*/
12+
public enum Sound {
13+
14+
NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"),
15+
NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"),
16+
NOTE_BELL("NOTE_BELL", "BLOCK_NOTE_BELL", "BLOCK_NOTE_BLOCK_BELL"),
17+
NOTE_CHIME("NOTE_CHIME", "BLOCK_NOTE_CHIME", "BLOCK_NOTE_BLOCK_CHIME"),
18+
NOTE_FLUTE("NOTE_FLUTE", "BLOCK_NOTE_FLUTE", "BLOCK_NOTE_BLOCK_FLUTE"),
19+
NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR"),
20+
NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"),
21+
NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"),
22+
NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"),
23+
NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"),
24+
NOTE_XYLOPHONE("NOTE_XYLOPHONE", "BLOCK_NOTE_XYLOPHONE", "BLOCK_NOTE_BLOCK_XYLOPHONE");
25+
26+
private String[] versionDependentNames;
27+
private org.bukkit.Sound cached = null;
28+
29+
Sound(String... versionDependentNames) {
30+
this.versionDependentNames = versionDependentNames;
31+
}
32+
33+
public static org.bukkit.Sound getFromBukkitName(String bukkitSoundName) {
34+
for (Sound sound : values()) {
35+
org.bukkit.Sound bukkitSound = sound.getSound();
36+
if (bukkitSound != null) return bukkitSound;
37+
}
38+
return org.bukkit.Sound.valueOf(bukkitSoundName);
39+
}
40+
41+
private org.bukkit.Sound getSound() {
42+
if (cached != null) return cached;
43+
for (String name : versionDependentNames) {
44+
try {
45+
return cached = org.bukkit.Sound.valueOf(name);
46+
} catch (IllegalArgumentException ignore2) {
47+
// try next
48+
}
49+
}
50+
return null;
51+
}
52+
53+
/**
54+
* Get the bukkit sound for current server version
55+
*
56+
* Caches sound on first call
57+
* @return corresponding {@link org.bukkit.Sound}
58+
*/
59+
public org.bukkit.Sound bukkitSound() {
60+
if (getSound() != null) {
61+
return getSound();
62+
}
63+
throw new IllegalArgumentException("Found no valid sound name for " + this.name());
64+
}
65+
66+
}

0 commit comments

Comments
 (0)