Skip to content

Commit 11249ef

Browse files
committed
Code cleanup
1 parent 2b5a001 commit 11249ef

File tree

4 files changed

+11
-199
lines changed

4 files changed

+11
-199
lines changed

pom.xml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.xxmicloxx</groupId>
77
<artifactId>NoteBlockAPI</artifactId>
8-
<version>1.3-SNAPSHOT</version>
8+
<version>1.3</version>
99
<name>NoteBlockAPI</name>
1010

1111
<properties>
@@ -19,10 +19,6 @@
1919
<id>spigot-repo</id>
2020
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
2121
</repository>
22-
<repository>
23-
<id>jitpack.io</id>
24-
<url>https://jitpack.io</url>
25-
</repository>
2622
<repository>
2723
<id>CodeMC</id>
2824
<url>https://repo.codemc.org/repository/maven-public</url>
@@ -44,19 +40,6 @@
4440
</dependency>
4541
</dependencies>
4642

47-
<distributionManagement>
48-
<repository>
49-
<id>sinndev-repo</id>
50-
<name>Releases</name>
51-
<url>http://repo.sinndev.com/content/repositories/releases/</url>
52-
</repository>
53-
<snapshotRepository>
54-
<id>sinndev-repo</id>
55-
<name>Snapshots</name>
56-
<url>http://repo.sinndev.com/content/repositories/snapshots/</url>
57-
</snapshotRepository>
58-
</distributionManagement>
59-
6043
<build>
6144
<plugins>
6245
<plugin>

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

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ public class CompatibilityUtils {
2424
* @return Class of given name
2525
*/
2626
public static Class<?> getMinecraftClass(String name) {
27-
try {
28-
return Class.forName(NMS_DIR + "." + name);
29-
} catch (ClassNotFoundException e) {
30-
e.printStackTrace();
31-
return null;
32-
}
27+
return com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.getMinecraftClass(name);
3328
}
3429

3530
/**
@@ -38,23 +33,15 @@ public static Class<?> getMinecraftClass(String name) {
3833
* @return Class of given name
3934
*/
4035
public static Class<?> getCraftBukkitClass(String name) {
41-
try {
42-
return Class.forName(OBC_DIR + "." + name);
43-
} catch (ClassNotFoundException e) {
44-
e.printStackTrace();
45-
return null;
46-
}
36+
return com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.getCraftBukkitClass(name);
4737
}
4838

4939
/**
5040
* Returns whether the version of Bukkit is or is after 1.12
5141
* @return version is after 1.12
5242
*/
5343
public static boolean isPost1_12() {
54-
if (!isSoundCategoryCompatible() || Bukkit.getVersion().contains("1.11")) {
55-
return false;
56-
}
57-
return true;
44+
return com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.isPost1_12();
5845
}
5946

6047
/**
@@ -64,14 +51,7 @@ public static boolean isPost1_12() {
6451
* @return can use SoundCategory
6552
*/
6653
protected static boolean isSoundCategoryCompatible() {
67-
if (Bukkit.getVersion().contains("1.7")
68-
|| Bukkit.getVersion().contains("1.8")
69-
|| Bukkit.getVersion().contains("1.9")
70-
|| Bukkit.getVersion().contains("1.10")) {
71-
return false;
72-
} else {
73-
return true;
74-
}
54+
return com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.getServerVersion() >= 0.0111f;
7555
}
7656

7757
/**
@@ -85,32 +65,7 @@ protected static boolean isSoundCategoryCompatible() {
8565
*/
8666
public static void playSound(Player player, Location location, String sound,
8767
SoundCategory category, float volume, float pitch) {
88-
try {
89-
if (isSoundCategoryCompatible()) {
90-
Method method = Player.class.getMethod("playSound", Location.class, String.class,
91-
Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
92-
Class<? extends Enum> soundCategory =
93-
(Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
94-
Enum<?> soundCategoryEnum = Enum.valueOf(soundCategory, category.name());
95-
method.invoke(player, location, sound, soundCategoryEnum, volume, pitch);
96-
} else {
97-
Method method = Player.class.getMethod("playSound", Location.class,
98-
String.class, float.class, float.class);
99-
method.invoke(player, location, sound, volume, pitch);
100-
}
101-
} catch (NoSuchMethodException e) {
102-
e.printStackTrace();
103-
} catch (SecurityException e) {
104-
e.printStackTrace();
105-
} catch (IllegalAccessException e) {
106-
e.printStackTrace();
107-
} catch (IllegalArgumentException e) {
108-
e.printStackTrace();
109-
} catch (InvocationTargetException e) {
110-
e.printStackTrace();
111-
} catch (ClassNotFoundException e) {
112-
e.printStackTrace();
113-
}
68+
com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.playSound(player, location, sound, com.xxmicloxx.NoteBlockAPI.model.SoundCategory.valueOf(category.name()), volume, pitch);
11469
}
11570

11671
/**
@@ -124,32 +79,7 @@ public static void playSound(Player player, Location location, String sound,
12479
*/
12580
public static void playSound(Player player, Location location, Sound sound,
12681
SoundCategory category, float volume, float pitch) {
127-
try {
128-
if (isSoundCategoryCompatible()) {
129-
Method method = Player.class.getMethod("playSound", Location.class, Sound.class,
130-
Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
131-
Class<? extends Enum> soundCategory =
132-
(Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
133-
Enum<?> soundCategoryEnum = Enum.valueOf(soundCategory, category.name());
134-
method.invoke(player, location, sound, soundCategoryEnum, volume, pitch);
135-
} else {
136-
Method method = Player.class.getMethod("playSound", Location.class,
137-
Sound.class, float.class, float.class);
138-
method.invoke(player, location, sound, volume, pitch);
139-
}
140-
} catch (NoSuchMethodException e) {
141-
e.printStackTrace();
142-
} catch (SecurityException e) {
143-
e.printStackTrace();
144-
} catch (IllegalAccessException e) {
145-
e.printStackTrace();
146-
} catch (IllegalArgumentException e) {
147-
e.printStackTrace();
148-
} catch (InvocationTargetException e) {
149-
e.printStackTrace();
150-
} catch (ClassNotFoundException e) {
151-
e.printStackTrace();
152-
}
82+
com.xxmicloxx.NoteBlockAPI.utils.CompatibilityUtils.playSound(player, location, sound, com.xxmicloxx.NoteBlockAPI.model.SoundCategory.valueOf(category.name()), volume, pitch);
15383
}
15484

15585
/**

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,7 @@ public static org.bukkit.Sound getInstrument(byte instrument) {
2626
* @return Sound enum name (for the current server version)
2727
*/
2828
public static String getInstrumentName(byte instrument) {
29-
switch (instrument) {
30-
case 0:
31-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_HARP").name();
32-
case 1:
33-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BASS").name();
34-
case 2:
35-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BASEDRUM").name();
36-
case 3:
37-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_SNARE").name();
38-
case 4:
39-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_HAT").name();
40-
case 5:
41-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_GUITAR").name();
42-
case 6:
43-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_FLUTE").name();
44-
case 7:
45-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BELL").name();
46-
case 8:
47-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_CHIME").name();
48-
case 9:
49-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_XYLOPHONE").name();
50-
case 10:
51-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_IRON_XYLOPHONE").name();
52-
case 11:
53-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_COW_BELL").name();
54-
case 12:
55-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_DIDGERIDOO").name();
56-
case 13:
57-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BIT").name();
58-
case 14:
59-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_BANJO").name();
60-
case 15:
61-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_PLING").name();
62-
default:
63-
return Sound.getFromBukkitName("BLOCK_NOTE_BLOCK_HARP").name();
64-
}
29+
return InstrumentUtils.getInstrumentName(instrument);
6530
}
6631

6732
/**

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

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -23,81 +23,15 @@
2323
public class Interpolator {
2424

2525
public static double[] interpLinear(double[] x, double[] y, double[] xi) throws IllegalArgumentException {
26-
if (x.length != y.length) {
27-
throw new IllegalArgumentException("X and Y must be the same length");
28-
}
29-
if (x.length == 1) {
30-
throw new IllegalArgumentException("X must contain more than one value");
31-
}
32-
33-
double[] dx = new double[x.length - 1];
34-
double[] dy = new double[x.length - 1];
35-
double[] slope = new double[x.length - 1];
36-
double[] intercept = new double[x.length - 1];
37-
38-
// Calculate the line equation (i.e. slope and intercept) between each point
39-
for (int i = 0; i < x.length - 1; i++) {
40-
dx[i] = x[i + 1] - x[i];
41-
if (dx[i] == 0) {
42-
throw new IllegalArgumentException("X must be montotonic. A duplicate " + "x-value was found");
43-
}
44-
if (dx[i] < 0) {
45-
throw new IllegalArgumentException("X must be sorted");
46-
}
47-
dy[i] = y[i + 1] - y[i];
48-
slope[i] = dy[i] / dx[i];
49-
intercept[i] = y[i] - x[i] * slope[i];
50-
}
51-
52-
// Perform the interpolation here
53-
double[] yi = new double[xi.length];
54-
for (int i = 0; i < xi.length; i++) {
55-
if ((xi[i] > x[x.length - 1]) || (xi[i] < x[0])) {
56-
yi[i] = Double.NaN;
57-
} else {
58-
int loc = Arrays.binarySearch(x, xi[i]);
59-
if (loc < -1) {
60-
loc = -loc - 2;
61-
yi[i] = slope[loc] * xi[i] + intercept[loc];
62-
} else {
63-
yi[i] = y[loc];
64-
}
65-
}
66-
}
67-
68-
return yi;
26+
return com.xxmicloxx.NoteBlockAPI.utils.Interpolator.interpLinear(x, y, xi);
6927
}
7028

7129
public static double[] interpLinear(long[] x, double[] y, long[] xi) throws IllegalArgumentException {
72-
double[] xd = new double[x.length];
73-
for (int i = 0; i < x.length; i++) {
74-
xd[i] = (double) x[i];
75-
}
76-
77-
double[] xid = new double[xi.length];
78-
for (int i = 0; i < xi.length; i++) {
79-
xid[i] = (double) xi[i];
80-
}
81-
82-
return interpLinear(xd, y, xid);
30+
return com.xxmicloxx.NoteBlockAPI.utils.Interpolator.interpLinear(x, y, xi);
8331
}
8432

8533
public static double interpLinear(double[] xy, double xx) {
86-
if (xy.length % 2 != 0) {
87-
throw new IllegalArgumentException("XY must be divisible by two.");
88-
}
89-
90-
double[] x = new double[xy.length/2];
91-
double[] y = new double[x.length];
92-
93-
for (int i = 0; i < xy.length; i++) {
94-
if (i % 2 == 0) {
95-
x[i/2] = xy[i];
96-
} else {
97-
y[i/2] = xy[i];
98-
}
99-
}
100-
return interpLinear(x, y, new double[] {xx})[0];
34+
return com.xxmicloxx.NoteBlockAPI.utils.Interpolator.interpLinear(xy, xx);
10135
}
10236

10337
}

0 commit comments

Comments
 (0)