Skip to content

Commit 988575a

Browse files
Switch to Early-Return
1 parent c16b026 commit 988575a

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

src/main/java/me/entity303/serversystem/utils/interceptors/invsee/InvseeSetItemInterceptor.java

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -66,56 +66,56 @@ public void intercept(@This Object obj, @AllArguments Object[] allArguments, @Mo
6666
}
6767
}
6868

69-
if (allArguments[0] instanceof Integer) {
70-
var index = (int) allArguments[0];
71-
72-
if (index > 45 - 5)
73-
if (allArguments[1] != null) {
74-
75-
if (this._setCountMethod == null)
76-
try {
77-
this._setCountMethod = allArguments[1].getClass().getDeclaredMethod("setCount", int.class);
78-
} catch (NoSuchMethodException ignored) {
79-
}
69+
if (!(allArguments[0] instanceof Integer))
70+
return;
8071

72+
var index = (int) allArguments[0];
8173

74+
if (index > 45 - 5)
75+
if (allArguments[1] != null) {
76+
if (this._setCountMethod == null)
8277
try {
83-
var itemStack = (ItemStack) this._asCraftMirrorMethod.invoke(null, allArguments[1]);
84-
if (!itemStack.getType().name().contains("AIR"))
85-
this._victim.getWorld()
86-
.dropItem(this._victim.getEyeLocation().add(0, -0.33, 0), itemStack)
87-
.setVelocity(new Vector(0.0, 0.0, 0.0).add(this._victim.getLocation().getDirection().multiply(0.35)));
88-
} catch (IllegalAccessException | InvocationTargetException exception) {
89-
exception.printStackTrace();
90-
return;
78+
this._setCountMethod = allArguments[1].getClass().getDeclaredMethod("setCount", int.class);
79+
} catch (NoSuchMethodException ignored) {
9180
}
9281

93-
var timer = new Timer();
94-
timer.schedule(new MyTimerTask(allArguments), 1000L / 20);
82+
83+
try {
84+
var itemStack = (ItemStack) this._asCraftMirrorMethod.invoke(null, allArguments[1]);
85+
if (!itemStack.getType().name().contains("AIR"))
86+
this._victim.getWorld()
87+
.dropItem(this._victim.getEyeLocation().add(0, -0.33, 0), itemStack)
88+
.setVelocity(new Vector(0.0, 0.0, 0.0).add(this._victim.getLocation().getDirection().multiply(0.35)));
89+
} catch (IllegalAccessException | InvocationTargetException exception) {
90+
exception.printStackTrace();
9591
return;
9692
}
9793

98-
if (this._setItemMethod == null)
99-
this._setItemMethod = Arrays.stream(this._masterInventoryNms.getClass().getDeclaredMethods())
100-
.filter(method1 -> method1.getName().equalsIgnoreCase("setItem"))
101-
.findFirst()
102-
.orElse(null);
103-
104-
if (this._setItemMethod == null)
105-
for (var declaredMethod : this._masterInventoryNms.getClass().getDeclaredMethods())
106-
if (declaredMethod.getReturnType().getName().equalsIgnoreCase(void.class.getName()))
107-
if (declaredMethod.getParameters().length == 2)
108-
if (declaredMethod.getParameters()[0].getType().getName().equalsIgnoreCase(int.class.getName()))
109-
if (declaredMethod.getParameters()[1].getType().getName().toLowerCase(Locale.ROOT).contains("itemstack")) {
110-
this._setItemMethod = declaredMethod;
111-
break;
112-
}
113-
114-
try {
115-
this._setItemMethod.invoke(this._masterInventoryNms, allArguments[0], allArguments[1]);
116-
} catch (IllegalAccessException | InvocationTargetException exception) {
117-
exception.printStackTrace();
94+
var timer = new Timer();
95+
timer.schedule(new MyTimerTask(allArguments), 1000L / 20);
96+
return;
11897
}
98+
99+
if (this._setItemMethod == null)
100+
this._setItemMethod = Arrays.stream(this._masterInventoryNms.getClass().getDeclaredMethods())
101+
.filter(method1 -> method1.getName().equalsIgnoreCase("setItem"))
102+
.findFirst()
103+
.orElse(null);
104+
105+
if (this._setItemMethod == null)
106+
for (var declaredMethod : this._masterInventoryNms.getClass().getDeclaredMethods())
107+
if (declaredMethod.getReturnType().getName().equalsIgnoreCase(void.class.getName()))
108+
if (declaredMethod.getParameters().length == 2)
109+
if (declaredMethod.getParameters()[0].getType().getName().equalsIgnoreCase(int.class.getName()))
110+
if (declaredMethod.getParameters()[1].getType().getName().toLowerCase(Locale.ROOT).contains("itemstack")) {
111+
this._setItemMethod = declaredMethod;
112+
break;
113+
}
114+
115+
try {
116+
this._setItemMethod.invoke(this._masterInventoryNms, allArguments[0], allArguments[1]);
117+
} catch (IllegalAccessException | InvocationTargetException exception) {
118+
exception.printStackTrace();
119119
}
120120
}
121121

@@ -130,7 +130,7 @@ public MyTimerTask(Object... allArguments) {
130130
public void run() {
131131
if (InvseeSetItemInterceptor.this._setCountMethod != null)
132132
try {
133-
InvseeSetItemInterceptor.this._setCountMethod.invoke(_allArguments[1], 0);
133+
InvseeSetItemInterceptor.this._setCountMethod.invoke(this._allArguments[1], 0);
134134
} catch (IllegalAccessException | InvocationTargetException exception) {
135135
if (exception instanceof InvocationTargetException) {
136136
if (!(exception.getCause() instanceof AssertionError))
@@ -140,7 +140,7 @@ public void run() {
140140
}
141141

142142
try {
143-
var itemStack = (ItemStack) InvseeSetItemInterceptor.this._asCraftMirrorMethod.invoke(null, _allArguments[1]);
143+
var itemStack = (ItemStack) InvseeSetItemInterceptor.this._asCraftMirrorMethod.invoke(null, this._allArguments[1]);
144144
itemStack.setAmount(0);
145145
} catch (IllegalAccessException | InvocationTargetException exception) {
146146
exception.printStackTrace();

0 commit comments

Comments
 (0)