/**
 * Aeronica's mxTune MOD
 * Copyright {2016} Paul Boese a.k.a. Aeronica
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.aeronica.mods.mxtune.handler;

import net.aeronica.mods.mxtune.MXTuneMain;
import net.aeronica.mods.mxtune.config.ModConfig;
import net.aeronica.mods.mxtune.groups.PlayManager;
import net.aeronica.mods.mxtune.inventory.IInstrument;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;
import net.minecraftforge.fml.relauncher.Side;

public enum CommonEventHandler
{
    
    INSTANCE;
    private CommonEventHandler() {}
    
    @SubscribeEvent
    public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs)
    {
        if (eventArgs.getModID().equals(MXTuneMain.MODID)) ModConfig.syncConfig();
    }
    
    /* 
     * Stops a playing instrument if it's placed into a container and the container is closed.
     */
    @SubscribeEvent
    public void onEvent(PlayerContainerEvent.Close event)
    {
        if (event.getEntityPlayer().getEntityWorld().isRemote) return;
        for(Slot slot: event.getContainer().inventorySlots)
        {
            if(slot != null && slot.inventory != null && slot.inventory.getName() != null &&
                    !(slot.inventory.getName().contentEquals("container.inventory") ||
                    slot.inventory.getName().contentEquals("container.crafting") ||
                    slot.inventory.getName().contentEquals("Result") ||
                    slot.inventory.getName().contentEquals("container.mxtune.instrument")))
            {                
                ItemStack stack = slot.getStack();
                if (slot.getHasStack() && stack.getItem() instanceof IInstrument)
                {
                    if (stack.getRepairCost() > -1)
                    {
                        stack.getItem().onUpdate(stack, event.getEntityPlayer().getEntityWorld(), event.getEntityPlayer(), 0, false );
                    }
                }
            }
        }
    }
    
    private static int count = 0;
    @SubscribeEvent
    public void onEvent(ServerTickEvent event)
    {
        /* Fired once every two seconds */
        if (event.side == Side.SERVER && event.phase == TickEvent.Phase.END && (count++ % 40 == 0)) {
            PlayManager.testStopDistance(ModConfig.getGroupPlayAbortDistance());
        }
    }
    
}
@@ -871,24 +871,73 @@
 Instrument;%0A
+import net.minecraft.entity.player.EntityPlayer;%0A
 import net.m
@@ -1706,78 +1706,41 @@
 ing 
-instrument if it's placed into a container and the container is closed
+player if they open any inventory
 .%0A  
@@ -1814,13 +1814,12 @@
 ent.
-Close
+Open
  eve
@@ -1840,1022 +1840,63 @@
     
-if (event.getEntityPlayer().getEntityWorld().isRemote) return;%0A        for(Slot slot: event.getContainer().inventorySlots)%0A        %7B%0A            if(slot != null && slot.inventory != null && slot.inventory.getName() != null &&%0A                    !(slot.inventory.getName().contentEquals(%22container.inventory%22) %7C%7C%0A                    slot.inventory.getName().contentEquals(%22container.crafting%22) %7C%7C%0A                    slot.inventory.getName().contentEquals(%22Result%22) %7C%7C%0A                    slot.inventory.getName().contentEquals(%22container.mxtune.instrument%22)))%0A            %7B                %0A                ItemStack stack = slot.getStack();%0A                if (slot.getHasStack() && stack.getItem() instanceof IInstrument)%0A                %7B%0A                    if (stack.getRepairCost() %3E -1)%0A                    %7B%0A                        stack.getItem().onUpdate(stack, event.getEntityPlayer().getEntityWorld(), event.getEntityPlayer(), 0, false );%0A                    %7D%0A                %7D%0A            %7D%0A        %7D
+PlayManager.stopPlayingPlayer(event.getEntityLiving());
 %0A   

Simplify stopping music when a player interacts with an inventory (Read: the way I did it before was really dumb)