Skip to content

Commit 9c1bdca

Browse files
committed
refactor styling
use tabs instead of spaces, use consistent curly brace spacing, add some variables to lessen duplicate code
1 parent 454ac92 commit 9c1bdca

20 files changed

+1183
-1129
lines changed

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

Lines changed: 88 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,76 @@
1010
import org.bukkit.entity.Player;
1111

1212
public class CompatibilityUtils {
13-
13+
1414
public static final String OBC_DIR = Bukkit.getServer().getClass().getPackage().getName();
15-
public static final String NMS_DIR = OBC_DIR.replaceFirst("org.bukkit.craftbukkit", "net.minecraft.server");
16-
17-
public static Class<?> getMinecraftClass(String name){
18-
try {
19-
return Class.forName(NMS_DIR + "." + name);
20-
} catch (ClassNotFoundException e) {
21-
e.printStackTrace();
22-
return null;
23-
}
24-
}
15+
public static final String NMS_DIR = OBC_DIR.replaceFirst("org.bukkit.craftbukkit", "net.minecraft.server");
16+
17+
public static Class<?> getMinecraftClass(String name) {
18+
try {
19+
return Class.forName(NMS_DIR + "." + name);
20+
} catch (ClassNotFoundException e) {
21+
e.printStackTrace();
22+
return null;
23+
}
24+
}
2525

26-
public static Class<?> getCraftBukkitClass(String name){
27-
try {
28-
return Class.forName(OBC_DIR + "." + name);
29-
} catch (ClassNotFoundException e) {
30-
e.printStackTrace();
31-
return null;
32-
}
33-
}
34-
35-
public static class NoteBlockCompatibility{
36-
public static final int pre1_9 = 0;
37-
public static final int pre1_12 = 1;
38-
public static final int v1_12 = 2;
39-
public static final int post1_12 = 3;
40-
public static final int post1_13 = 4;
41-
}
42-
43-
protected static int getCompatibility(){
44-
if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.7")){
45-
return NoteBlockCompatibility.pre1_9;
46-
} else if (Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10") || Bukkit.getVersion().contains("1.11")){
47-
return NoteBlockCompatibility.pre1_12;
48-
} else if (Bukkit.getVersion().contains("1.12")){
49-
return NoteBlockCompatibility.v1_12;
50-
} else {
51-
return NoteBlockCompatibility.post1_13;
52-
}
53-
}
54-
55-
protected static boolean isSoundCategoryCompatible(){
56-
if (Bukkit.getVersion().contains("1.7") || Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.9") || Bukkit.getVersion().contains("1.10")){
57-
return false;
58-
} else {
59-
return true;
60-
}
61-
}
62-
63-
protected static void playSound(Player p, Location location, String sound, SoundCategory category, float volume, float pitch){
64-
try {
65-
if (isSoundCategoryCompatible()){
66-
Method m = Player.class.getMethod("playSound", Location.class, String.class, Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
67-
Class<? extends Enum> sc = (Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
68-
Enum<?> scenum = Enum.valueOf(sc, category.name());
69-
m.invoke(p, location, sound, scenum, volume, pitch);
70-
} else {
71-
Method m = Player.class.getMethod("playSound", Location.class, String.class, float.class, float.class);
72-
m.invoke(p, location, sound, volume, pitch);
73-
}
26+
public static Class<?> getCraftBukkitClass(String name) {
27+
try {
28+
return Class.forName(OBC_DIR + "." + name);
29+
} catch (ClassNotFoundException e) {
30+
e.printStackTrace();
31+
return null;
32+
}
33+
}
34+
35+
public static class NoteBlockCompatibility {
36+
public static final int pre1_9 = 0;
37+
public static final int pre1_12 = 1;
38+
public static final int v1_12 = 2;
39+
public static final int post1_12 = 3;
40+
public static final int post1_13 = 4;
41+
}
42+
43+
protected static int getCompatibility() {
44+
if (Bukkit.getVersion().contains("1.8") || Bukkit.getVersion().contains("1.7")) {
45+
return NoteBlockCompatibility.pre1_9;
46+
} else if (Bukkit.getVersion().contains("1.9")
47+
|| Bukkit.getVersion().contains("1.10")
48+
|| Bukkit.getVersion().contains("1.11")) {
49+
return NoteBlockCompatibility.pre1_12;
50+
} else if (Bukkit.getVersion().contains("1.12")) {
51+
return NoteBlockCompatibility.v1_12;
52+
} else {
53+
return NoteBlockCompatibility.post1_13;
54+
}
55+
}
56+
57+
protected static boolean isSoundCategoryCompatible() {
58+
if (Bukkit.getVersion().contains("1.7")
59+
|| Bukkit.getVersion().contains("1.8")
60+
|| Bukkit.getVersion().contains("1.9")
61+
|| Bukkit.getVersion().contains("1.10")) {
62+
return false;
63+
} else {
64+
return true;
65+
}
66+
}
67+
68+
protected static void playSound(Player player, Location location, String sound,
69+
SoundCategory category, float volume, float pitch) {
70+
try {
71+
if (isSoundCategoryCompatible()) {
72+
Method method = Player.class.getMethod("playSound", Location.class, String.class,
73+
Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
74+
Class<? extends Enum> soundCategory =
75+
(Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
76+
Enum<?> soundCategoryEnum = Enum.valueOf(soundCategory, category.name());
77+
method.invoke(player, location, sound, soundCategoryEnum, volume, pitch);
78+
} else {
79+
Method method = Player.class.getMethod("playSound", Location.class,
80+
String.class, float.class, float.class);
81+
method.invoke(player, location, sound, volume, pitch);
82+
}
7483
} catch (NoSuchMethodException e) {
7584
e.printStackTrace();
7685
} catch (SecurityException e) {
@@ -84,20 +93,23 @@ protected static void playSound(Player p, Location location, String sound, Sound
8493
} catch (ClassNotFoundException e) {
8594
e.printStackTrace();
8695
}
87-
}
96+
}
8897

89-
public static void playSound(Player p, Location location, Sound sound, SoundCategory category, float volume, float pitch) {
98+
public static void playSound(Player player, Location location, Sound sound,
99+
SoundCategory category, float volume, float pitch) {
90100
try {
91-
if (isSoundCategoryCompatible()){
92-
Method m = Player.class.getMethod("playSound", Location.class, Sound.class, Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
93-
Class<? extends Enum> sc = (Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
94-
Enum<?> scenum = Enum.valueOf(sc, category.name());
95-
m.invoke(p, location, sound, scenum, volume, pitch);
101+
if (isSoundCategoryCompatible()) {
102+
Method method = Player.class.getMethod("playSound", Location.class, Sound.class,
103+
Class.forName("org.bukkit.SoundCategory"), float.class, float.class);
104+
Class<? extends Enum> soundCategory =
105+
(Class<? extends Enum>) Class.forName("org.bukkit.SoundCategory");
106+
Enum<?> soundCategoryEnum = Enum.valueOf(soundCategory, category.name());
107+
method.invoke(player, location, sound, soundCategoryEnum, volume, pitch);
96108
} else {
97-
Method m = Player.class.getMethod("playSound", Location.class, Sound.class, float.class, float.class);
98-
m.invoke(p, location, sound, volume, pitch);
109+
Method method = Player.class.getMethod("playSound", Location.class,
110+
Sound.class, float.class, float.class);
111+
method.invoke(player, location, sound, volume, pitch);
99112
}
100-
101113
} catch (NoSuchMethodException e) {
102114
e.printStackTrace();
103115
} catch (SecurityException e) {
@@ -112,14 +124,15 @@ public static void playSound(Player p, Location location, Sound sound, SoundCate
112124
e.printStackTrace();
113125
}
114126
}
115-
127+
116128
public static ArrayList<CustomInstrument> get1_12Instruments(){
117129
ArrayList<CustomInstrument> instruments = new ArrayList<>();
118-
instruments.add(new CustomInstrument((byte) 0, "Guitar", "guitar.ogg", (byte) 0, (byte) 0));
119-
instruments.add(new CustomInstrument((byte) 0, "Flute", "flute.ogg", (byte) 0, (byte) 0));
120-
instruments.add(new CustomInstrument((byte) 0, "Bell", "bell.ogg", (byte) 0, (byte) 0));
121-
instruments.add(new CustomInstrument((byte) 0, "Chime", "icechime.ogg", (byte) 0, (byte) 0));
122-
instruments.add(new CustomInstrument((byte) 0, "Xylophone", "xylobone.ogg", (byte) 0, (byte) 0));
130+
instruments.add(new CustomInstrument((byte) 0, "Guitar", "guitar.ogg"));
131+
instruments.add(new CustomInstrument((byte) 0, "Flute", "flute.ogg"));
132+
instruments.add(new CustomInstrument((byte) 0, "Bell", "bell.ogg"));
133+
instruments.add(new CustomInstrument((byte) 0, "Chime", "icechime.ogg"));
134+
instruments.add(new CustomInstrument((byte) 0, "Xylophone", "xylobone.ogg"));
123135
return instruments;
124136
}
137+
125138
}
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

33
public class CustomInstrument {
4-
4+
55
private byte index;
66
private String name;
7-
private String soundfile;
8-
private byte pitch;
9-
private byte press;
7+
private String soundFileName;
108
private org.bukkit.Sound sound;
11-
12-
public CustomInstrument(byte index, String name, String soundfile, byte pitch, byte press){
9+
10+
@Deprecated
11+
public CustomInstrument(byte index, String name, String soundFileName, byte pitch, byte press) {
12+
this.index = index;
13+
this.name = name;
14+
this.soundFileName = soundFileName.replaceAll(".ogg", "");
15+
if (this.soundFileName.equalsIgnoreCase("pling")){
16+
this.sound = Sound.getFromBukkitName("BLOCK_NOTE_PLING");
17+
}
18+
}
19+
20+
public CustomInstrument(byte index, String name, String soundFileName) {
1321
this.index = index;
1422
this.name = name;
15-
this.soundfile = soundfile.replaceAll(".ogg", "");
16-
if (this.soundfile.equalsIgnoreCase("pling")){
23+
this.soundFileName = soundFileName.replaceAll(".ogg", "");
24+
if (this.soundFileName.equalsIgnoreCase("pling")){
1725
this.sound = Sound.getFromBukkitName("BLOCK_NOTE_PLING");
1826
}
19-
this.pitch = pitch;
20-
this.press = press;
2127
}
2228

2329
public byte getIndex() {
@@ -28,11 +34,17 @@ public String getName() {
2834
return name;
2935
}
3036

37+
@Deprecated
3138
public String getSoundfile() {
32-
return soundfile;
39+
return getSoundFileName();
40+
}
41+
42+
public String getSoundFileName() {
43+
return soundFileName;
3344
}
34-
45+
3546
public org.bukkit.Sound getSound() {
3647
return sound;
3748
}
49+
3850
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.xxmicloxx.NoteBlockAPI;
22

33
public enum FadeType {
4-
FADE_LINEAR
4+
5+
FADE_LINEAR
6+
57
}

0 commit comments

Comments
 (0)