ClumsyAlien / TimelessandClassics_Reforged

A forked version of CGM, based around adding significant amounts of more realistic improvement, while maintaining the same simplicity and customization
Other
77 stars 32 forks source link

Try to cancel the event of gun damage to glass in the Spigot plugin #107

Open GAA775 opened 1 year ago

GAA775 commented 1 year ago

Hello, everyone I am an ordinary Mincreft player in China and also a plug-in maker. I like TAC very much and opened a server for it. And around TAC as the core, make plug-ins that simulate various competitive modes of cod.

Now I have a problem, that is, I don't want the gun to be harmful to the glass of the main world. In fact, I noticed that TAC has a configuration file that can disable the damage of the gun to the glass, but for our game mode, We may need to enable bullets to destroy glass in some worlds (the world is dynamically generated, can be destroyed, and resets after the game is completed).

I've tried all the detectable events and they don't work

    @EventHandler
    public void onTest(BlockBreakEvent event) {
        log.info(event + "方块破坏事件");
    }

    @EventHandler
    public void onTest2(BlockExplodeEvent event) {
        log.info(event + "方块爆炸事件" );
    }

    @EventHandler
    public void onTest3(EntityExplodeEvent event) {
        log.info(event + "实体爆炸事件" );
    }

    @EventHandler
    public void onTest4(BlockPhysicsEvent event) {
        if(event.getBlock() instanceof BlockGlass){
            log.info(event + "方块物理事件" );
        }
    }

I noticed that the relevant code implementation in 1.16 is as follows

if(Config.COMMON.gameplay.enableGunGriefing.get() && (block instanceof BreakableBlock || block instanceof PaneBlock) && state.getMaterial() == Material.GLASS)
{
    this.world.destroyBlock(blockRayTraceResult.getPos(), false);
}

It triggers the world#destroyBlock method, which I thought was caught by the #BlockBreakEvent event in spigot, but it doesn't work. Is there an event in spigot that can capture the event of firearms breaking glass? Thanks😊

qyl27 commented 1 year ago

It should fire BlockEvent.BreakEvent, then some mixed-server implementation can process it correctly. Other mod can also process it by this way.

BlackScaryZ commented 1 year ago

https://github.com/ClumsyAlien/TimelessandClassics_Reforged/issues/111 I think my issue and pull request can solve your problem https://github.com/ClumsyAlien/TimelessandClassics_Reforged/issues/111

qyl27 commented 1 year ago

111 I think my issue and pull request can solve your problem #111

It didn't call forge event. Other compatible mod are usually process by Forge event.
(I haven't found some way to listen game event.) And the issue occurs on mixed-server implementation, there are some different in plain forge.