Skip to content

Commit

Permalink
Merge pull request #460 from j10a1n15/technical/event
Browse files Browse the repository at this point in the history
Backend: Use new Event System
  • Loading branch information
Su386yt authored Sep 17, 2024
2 parents 4d2d651 + f328733 commit 106aaf0
Show file tree
Hide file tree
Showing 46 changed files with 225 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package me.partlysanestudios.partlysaneskies.features.dungeons.party;

import me.partlysanestudios.partlysaneskies.PartlySaneSkies;
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent;
import me.partlysanestudios.partlysaneskies.commands.PSSCommand;
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent;
import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent;
import me.partlysanestudios.partlysaneskies.utils.StringUtils;

Expand Down Expand Up @@ -57,7 +57,7 @@ public static void partyAll() {
}
}

@SubscribePSSEvent
@PSSEvent.Subscribe
public void onChat(PSSChatEvent event) {
if (!isWaitingForMembers) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
package me.partlysanestudios.partlysaneskies.features.dungeons.party.partymanager;

import me.partlysanestudios.partlysaneskies.PartlySaneSkies;
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent;
import me.partlysanestudios.partlysaneskies.commands.PSSCommand;
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent;
import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent;
import me.partlysanestudios.partlysaneskies.utils.ChatUtils;
import me.partlysanestudios.partlysaneskies.utils.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -165,7 +163,7 @@ public static void reparty(List<PartyMember> partyMembers) {
}
}

@SubscribePSSEvent
@PSSEvent.Subscribe
public void onChatMemberJoin(PSSChatEvent event) {
if (!PartlySaneSkies.Companion.getConfig().getGetDataOnJoin()) {
return;
Expand All @@ -192,60 +190,60 @@ public void onChatMemberJoin(PSSChatEvent event) {
}

// Upon chat message receives, it will check to see if it is the party list
@SubscribeEvent
public void getMembers(ClientChatReceivedEvent event) {
@PSSEvent.Subscribe
public void getMembers(PSSChatEvent event) {
// If it's not waiting for party members, it returns
if (!isWaitingForMembers) {
return;
}

// If the message says "leader"
if (event.message.getUnformattedText().startsWith("Party Leader: ")) {
if (event.getComponent().getUnformattedText().startsWith("Party Leader: ")) {
// Hides the message
event.setCanceled(true);
event.cancel();

// Gets the message contents
String text = event.message.getUnformattedText();
String text = event.getComponent().getUnformattedText();
// Removes the header
text = text.replace("Party Leader: ", "");
// Processes the list
processList(text, PartyMember.PartyRank.MEMBER);
}

// If the message says "Party Moderators: "
else if (event.message.getUnformattedText().startsWith("Party Moderators: ")) {
else if (event.getComponent().getUnformattedText().startsWith("Party Moderators: ")) {
// Hides the message
event.setCanceled(true);
String text = event.message.getUnformattedText();
event.cancel();
String text = event.getComponent().getUnformattedText();

// Removes the header
text = text.replace("Party Moderators: ", "");
processList(text, PartyMember.PartyRank.MODERATOR);
}

// If the message says "Party Members: "
else if (event.message.getUnformattedText().startsWith("Party Members: ")) {
else if (event.getComponent().getUnformattedText().startsWith("Party Members: ")) {
// Hides the message
event.setCanceled(true);
event.cancel();

// Gets the message contents
String text = event.message.getUnformattedText();
String text = event.getComponent().getUnformattedText();
// Removes the header
text = text.replace("Party Members: ", "");
// Processes the list
processList(text, PartyMember.PartyRank.MEMBER);
}

// Hides the beginning of the "Party Members" list
else if (event.message.getUnformattedText().startsWith("Party Members (")) {
event.setCanceled(true);
else if (event.getComponent().getUnformattedText().startsWith("Party Members (")) {
event.cancel();
}

// Detects the closing line -----
// when all the members have been listed and the bar appears, its end of the message
else if (isMembersListed && event.message.getUnformattedText().startsWith("-----------------------------------------------------")) {
else if (isMembersListed && event.getComponent().getUnformattedText().startsWith("-----------------------------------------------------")) {
// Hides the message
event.setCanceled(true);
event.cancel();
// Resets
isMembersListed = false;
isWaitingForMembers = false;
Expand All @@ -254,14 +252,14 @@ else if (isMembersListed && event.message.getUnformattedText().startsWith("-----
}

// Hides the ---------------------
else if (event.message.getUnformattedText().startsWith("-----------------------------------------------------")) {
event.setCanceled(true);
else if (event.getComponent().getUnformattedText().startsWith("-----------------------------------------------------")) {
event.cancel();
}

// If the player is not in the party
else if (event.message.getUnformattedText().startsWith("You are not currently in a party.")) {
else if (event.getComponent().getUnformattedText().startsWith("You are not currently in a party.")) {
// Hides message
event.setCanceled(true);
event.cancel();
// Sends an error message
ChatUtils.INSTANCE.sendClientMessage(("§9§m-----------------------------------------------------\n " +
"§r§cError: Could not run Party Manager." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent;
import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager;
import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager;
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent;
import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent;
import me.partlysanestudios.partlysaneskies.utils.MathUtils;
import me.partlysanestudios.partlysaneskies.utils.StringUtils;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static LinkedHashMap<Minion, Double> sortMap(HashMap<Minion, Double> map)
}

// Runs after the request
@SubscribePSSEvent
@PSSEvent.Subscribe
public void init(LoadPublicDataEvent event) {
String str = PublicDataManager.INSTANCE.getFile(MINIONS_DATA_URL);
// Creates a json object from the request response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package me.partlysanestudios.partlysaneskies.mixin.minecraft;

import me.partlysanestudios.partlysaneskies.events.minecraft.player.PlayerBreakBlockEvent;
import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
Expand All @@ -19,6 +20,6 @@ public class MixinPlayerControllerMP {

@Inject(method = "onPlayerDestroyBlock", at = @At("HEAD"))
private void onPlayerDestroyBlock(BlockPos pos, EnumFacing side, CallbackInfoReturnable<Boolean> cir) {
PlayerBreakBlockEvent.Companion.onPlayerBreakBlock$Partly_Sane_Skies(pos, side);
new PlayerBreakBlockEvent(Point3d.Companion.toPoint3d(pos), side).post();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package me.partlysanestudios.partlysaneskies

import com.google.gson.JsonObject
import com.google.gson.JsonParser
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent
import me.partlysanestudios.partlysaneskies.api.events.PSSEvents
import me.partlysanestudios.partlysaneskies.config.Keybinds
import me.partlysanestudios.partlysaneskies.config.OneConfigScreen
Expand All @@ -34,7 +35,6 @@ import me.partlysanestudios.partlysaneskies.data.cache.VisitorLogbookData
import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager
import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager
import me.partlysanestudios.partlysaneskies.events.EventManager
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent
import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent
import me.partlysanestudios.partlysaneskies.features.chat.ChatAlertsManager
import me.partlysanestudios.partlysaneskies.features.chat.ChatManager
Expand Down Expand Up @@ -352,7 +352,7 @@ class PartlySaneSkies {
} catch (e: IOException) {
e.printStackTrace()
}
LoadPublicDataEvent.onDataLoad()
LoadPublicDataEvent().post()

// Loads user player data for PartyManager
Thread(
Expand All @@ -379,7 +379,6 @@ class PartlySaneSkies {

private fun registerEvent(obj: Any) {
runCatching { EVENT_BUS.register(obj) }.onFailure { it.printStackTrace() }
runCatching { EventManager.register(obj) }.onFailure { it.printStackTrace() }
runCatching { PSSEvents.register(obj) }.onFailure { it.printStackTrace() }
}

Expand All @@ -401,7 +400,7 @@ class PartlySaneSkies {
EventManager.tick()
}

@SubscribePSSEvent
@PSSEvent.Subscribe
fun loadMainMenuJson(event: LoadPublicDataEvent) {
val data = PublicDataManager.getFile("main_menu.json")
val jsonObj = JsonParser().parse(data).asJsonObject
Expand Down Expand Up @@ -454,7 +453,7 @@ class PartlySaneSkies {
}

@SubscribeEvent
fun onClientConnectedToServer(event: ClientConnectedToServerEvent?) {
fun onClientConnectedToServer(event: ClientConnectedToServerEvent) {
if (DOGFOOD) {
Thread {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Written by Su386.
// See LICENSE for copyright and license notices.
//

package me.partlysanestudios.partlysaneskies.api

import me.partlysanestudios.partlysaneskies.render.waypoint.Waypoint
import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d.Companion.toPoint3d
import net.minecraft.client.Minecraft

class WaypointRenderPipeline {
private val waypointsToRender = ArrayList<Waypoint>()

/**
* Adds a waypoint to the render pipeline
*
* @param waypoint the waypoint to be rendered
*/
fun add(waypoint: Waypoint) {
waypointsToRender.add(waypoint)
}

// Written partially by j10a1n15
/**
* Renders all the waypoints in the pipeline
*
* @param partialTicks the amount of partial ticks since the last frame that rendered
*/
internal fun renderAll(partialTicks: Float) {
val mc = Minecraft.getMinecraft()

for (waypoint in waypointsToRender) {
val waypointPos = waypoint.position.toPoint3d()
val distance = waypointPos.distanceToPlayer()

waypoint.render(distance)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ abstract class PSSEvent protected constructor() {
var isCancelled = false
private set

fun post() {
open fun post(): Boolean {
PSSEvents.post(this)
return isCancelled
}

interface Cancellable {

fun cancel() {
(this as PSSEvent).isCancelled = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Keybinds {
}

@SubscribeEvent
fun checkKeyBinds(event: InputEvent.KeyInputEvent?) {
fun checkKeyBinds(event: InputEvent.KeyInputEvent) {
if (OneConfigScreen.debugKeybind.isActive()) {
onDebugKeyPress()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.annotations.Expose
import me.partlysanestudios.partlysaneskies.PartlySaneSkies
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent
import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity
import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent
import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent
import me.partlysanestudios.partlysaneskies.events.minecraft.TablistUpdateEvent
import me.partlysanestudios.partlysaneskies.utils.MathUtils
Expand Down Expand Up @@ -107,7 +107,7 @@ object PetData {
*/
fun getCurrentPetRarity() = petDataJson?.currentPetRarity ?: Rarity.UNKNOWN

@SubscribePSSEvent
@PSSEvent.Subscribe
fun onChat(event: PSSChatEvent) {
// Parse despawn message
if (event.component.unformattedText.startsWith("You despawned your")) {
Expand Down Expand Up @@ -163,7 +163,7 @@ object PetData {
}
}

@SubscribePSSEvent
@PSSEvent.Subscribe
fun parsePetFromTablist(event: TablistUpdateEvent) {
val pet = event.list.nextAfter("§e§lPet:")?.removeResets()?.trim() ?: return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ object PublicDataManager {
)
fileCache.clear()
sendClientMessage(chatcomponent)
LoadPublicDataEvent.onDataLoad()
LoadPublicDataEvent().post()
}.register()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ package me.partlysanestudios.partlysaneskies.data.skyblockdata
import com.google.gson.JsonParser
import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config
import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time
import me.partlysanestudios.partlysaneskies.api.events.PSSEvent
import me.partlysanestudios.partlysaneskies.data.api.GetRequest
import me.partlysanestudios.partlysaneskies.data.api.Request
import me.partlysanestudios.partlysaneskies.data.api.RequestRunnable
import me.partlysanestudios.partlysaneskies.data.api.RequestsManager.newRequest
import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager.getFile
import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent
import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent
import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes
import java.io.IOException
import java.net.MalformedURLException

object SkyblockDataManager {
@SubscribePSSEvent
fun onDataLoad(event: LoadPublicDataEvent?) {
@PSSEvent.Subscribe
fun onDataLoad(event: LoadPublicDataEvent) {
try {
initBitValues()
} catch (e: IOException) {
Expand Down
Loading

0 comments on commit 106aaf0

Please sign in to comment.