This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
generated from LabyMod/1.16.5-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from rettichlp/develop
v1.0.0-beta.2
- Loading branch information
Showing
10 changed files
with
128 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 3 additions & 11 deletions
14
src/main/java/com/rettichlp/UnicacityAddon/base/event/UCEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/rettichlp/UnicacityAddon/base/reflection/ReflectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.rettichlp.UnicacityAddon.base.reflection; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class ReflectionUtils { | ||
|
||
private String inPackage; | ||
|
||
public ReflectionUtils(String inPackage) { | ||
this.inPackage = inPackage; | ||
} | ||
|
||
public List<Class> getClassesAnnotatedWith(Class<?> annotation) { | ||
return getAllClasses().stream().filter(aClass -> { | ||
Arrays.stream(aClass.getAnnotations()).filter(annotation1 -> annotation1.annotationType().equals(annotation)); | ||
return true; | ||
}).collect(Collectors.toList()); | ||
} | ||
|
||
public List<Method> getMethodsAnnotatedWith(Class<?> annotation) { | ||
List<Method> methods = new ArrayList<>(); | ||
getAllClasses().forEach(clazz -> Arrays.asList(clazz.getMethods()).forEach(method -> { | ||
if (Arrays.asList(method.getAnnotations()).contains(annotation)) | ||
methods.add(method); | ||
})); | ||
return methods; | ||
} | ||
|
||
private Set<Class> getAllClasses() { | ||
InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(inPackage.replaceAll("[.]", "/")); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); | ||
return reader.lines().filter(line -> line.endsWith(".class")).map(line -> getClass(line, inPackage)).collect(Collectors.toSet()); | ||
} | ||
|
||
private Class getClass(String className, String packageName) { | ||
try { | ||
return Class.forName(packageName + "." + className.substring(0, className.lastIndexOf('.'))); | ||
} catch (ClassNotFoundException e) { | ||
e.getCause().printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/rettichlp/UnicacityAddon/events/BombTimerEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.rettichlp.UnicacityAddon.events; | ||
|
||
import com.rettichlp.UnicacityAddon.base.event.UCEvent; | ||
import com.rettichlp.UnicacityAddon.base.text.ColorCode; | ||
import com.rettichlp.UnicacityAddon.base.text.PatternHandler; | ||
import com.rettichlp.UnicacityAddon.modules.BombTimerModule; | ||
import net.labymod.api.event.Subscribe; | ||
import net.labymod.api.event.events.client.TickEvent; | ||
import net.labymod.api.event.events.client.chat.MessageReceiveEvent; | ||
import net.labymod.utils.ModUtils; | ||
|
||
@UCEvent | ||
public class BombTimerEventHandler { | ||
|
||
@Subscribe | ||
public void onTick(TickEvent event) { | ||
if (event.getPhase() != TickEvent.Phase.POST) return; | ||
|
||
if (!BombTimerModule.isBomb || ++BombTimerModule.currentTick != 20) return; | ||
BombTimerModule.currentTick = 0; | ||
|
||
if (BombTimerModule.currentCount++ >= 780) BombTimerModule.timer = ColorCode.RED.getCode() + ModUtils.parseTimer(BombTimerModule.currentCount); | ||
else BombTimerModule.timer = ModUtils.parseTimer(BombTimerModule.currentCount); | ||
} | ||
|
||
@Subscribe | ||
public void onMesageReceive(MessageReceiveEvent e) { | ||
String msg = e.getComponent().getString(); | ||
|
||
if (PatternHandler.BOMB_PLACED_PATTERN.matcher(msg).find()) { | ||
BombTimerModule.isBomb = true; | ||
BombTimerModule.timer = "00:00"; | ||
return; | ||
} | ||
|
||
if (PatternHandler.BOMB_REMOVED_PATTERN.matcher(msg).find()) { | ||
BombTimerModule.isBomb = false; | ||
BombTimerModule.currentCount = 0; | ||
BombTimerModule.timer = ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters