Files
Applied-Energistics-2-Unoff…/src/main/java/appeng/hooks/CraftingNotificationManager.java
T

58 lines
2.1 KiB
Java

package appeng.hooks;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.S29PacketSoundEffect;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCraftingCompleteNotification;
import appeng.me.cluster.implementations.CraftingCPUCluster.CraftNotification;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
public class CraftingNotificationManager {
private static final List<Map<String, List<CraftNotification>>> notificationMaps = new ArrayList<>();
@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent event) {
final EntityPlayer player = event.player;
final String playerName = player.getCommandSenderName();
for (Map<String, List<CraftNotification>> map : notificationMaps) {
if (map.containsKey(playerName)) {
List<CraftNotification> notifications = map.remove(playerName);
for (CraftNotification notification : notifications) {
try {
NetworkHandler.instance
.sendTo(new PacketCraftingCompleteNotification(notification), (EntityPlayerMP) player);
} catch (IOException e) {
AELog.debug(e);
}
player.addChatMessage(notification.createMessage());
}
((EntityPlayerMP) player).playerNetServerHandler.sendPacket(
new S29PacketSoundEffect("random.levelup", player.posX, player.posY, player.posZ, 1f, 1f));
}
}
}
public static void register(Map<String, List<CraftNotification>> map) {
notificationMaps.add(map);
}
public static void unregister(Map<String, List<CraftNotification>> map) {
notificationMaps.remove(map);
}
public static void clear() {
notificationMaps.clear();
}
}