--- a/net/minecraft/world/level/block/DetectorRailBlock.java
+++ b/net/minecraft/world/level/block/DetectorRailBlock.java
@@ -54,6 +_,7 @@
 
     @Override
     protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
+        if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(level, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
         if (!level.isClientSide) {
             if (!state.getValue(POWERED)) {
                 this.checkPressed(level, pos, state);
@@ -84,6 +_,7 @@
 
     private void checkPressed(Level level, BlockPos pos, BlockState state) {
         if (this.canSurvive(state, level, pos)) {
+            if (!state.is(this)) { return; } // Paper - Fix some rails connecting improperly
             boolean poweredValue = state.getValue(POWERED);
             boolean flag = false;
             List<AbstractMinecart> interactingMinecartOfType = this.getInteractingMinecartOfType(level, pos, AbstractMinecart.class, entity -> true);
@@ -91,6 +_,16 @@
                 flag = true;
             }
 
+            // CraftBukkit start
+            if (poweredValue != flag) {
+                org.bukkit.block.Block block = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+
+                org.bukkit.event.block.BlockRedstoneEvent eventRedstone = new org.bukkit.event.block.BlockRedstoneEvent(block, flag ? 15 : 0, flag ? 15 : 0);
+                level.getCraftServer().getPluginManager().callEvent(eventRedstone);
+
+                flag = eventRedstone.getNewCurrent() > 0;
+            }
+            // CraftBukkit end
             if (flag && !poweredValue) {
                 BlockState blockState = state.setValue(POWERED, Boolean.valueOf(true));
                 level.setBlock(pos, blockState, 3);
