1.15.2 Creating Custom modes or scenarios

Discussion in 'Spigot Plugin Development' started by acebelowzero, Jan 25, 2020.

  1. Hi, so I am making a Custom UHC plugin, but how do i approach creating different scenarios or game modes?
    I was gonna make a separate package and have each scenario in different classes. is this appropriate?
     
  2. I would make an enum called GameType or Mode to store each one. Then you choose which one you go with and can change your rules accordingly:
    Code (Text):
    if(currentMode == GameType.SPEED) {
    no fall damage
    } else if(currentMode == GameType.EXTRA_FALL) {
    2x fall damage
    }
    all other modes fall dmg will be normal
     
    Just some POC pseudo code, hope it helps
     
  3. I would go for making an interface.
    Code (Java):
    public interface UHCGame {
        void handleDrops(BlockBreakEvent e);
    }
    Then some classes implementing the interface
    Code (Java):
    public class SpeedUHCGame implements UHCGame {
        @Override
        handleDrops(BlockBreakEvent e {
        // Double drops ?
        }
    }
    Then in the listener you will get the instance of the current game as UHCGame and call the method with the event itself as a parameter.
    Code (Text):
    public class BlockBreakListener implements Listener {
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            UHCGame game = // Get the instance
            game.handleDrops(e);
        }
    }