How freeze players

Hi everybody!

I’m a french amator developper and I would use Sponge to developp an HungerGames plugin. I’m now working on a command to freeze players but I’m wondering how I can do that. I was thinking about use a /freeze command that send a packet to all players to interact with a client mod. Have you a better idea ?

Thanks for reading and posting answers.

Yes. Just cancel the DisplaceEntityEvent.TargetPlayer event whenever the player moves.

Oh, thanks you a lot.
I’m going to try it now. I would post you my results.

@HassanS6000 already did this. He could help you I guess.

Hi !

Here is what I coded yesterday in the night:

public void onPlayerMove(DisplaceEntityEvent.TargetPlayer e){
    if(plugin.getIsFreezingPlayers() == Boolean.TRUE){
        e.getTargetEntity().sendMessage(Texts.of(TextColors.BLUE, "You can't move: you have been freeze"));

But it doesn’t work… Indeed, the player don’t receive the message “You can’t move: you have been freeze” and can move by the same time. What did I do wrong ?

1 Like

Just use true, not Boolean.TRUE

Also make sure you listener class is registered to the event manager (this is automatic for you plugin main class)


Thank for answer. I’ll try this change.
And yes, it is register in the main class:

public void onInit(GameInitializationEvent e){
    game.getCommandDispatcher().register(this, new FreezePlayersCommand(game.getServer(), this), "freeze", "gele");
    game.getEventManager().registerListeners(this, new FreezePlayerEvent(this));

Thanks a lot

EDIT : When I was changing, I found the real error: the /freeze command changed the isFreezingPlayers value to false, which is not right. It should change to true.

The problem is that DisplaceEntityEvent is not implemented yet.

Oh, yes it is I think, because it works now.

Okay, now that I actually look, it is implemented. Someone should update the event tracker.


Uhm, but if (someBoolean == true) isn’t the best either, is it? ^^
if (someBoolean) !! :slight_smile:

:stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue:

1 Like

@Blue has it right. If statements operate on booleans, there’s no need to specify, especially when you have the inverse operator -> !.

Thank for your answer. I will change this, I don’t know why I did that. But, I don’t think the gamemodes API is implemented… They are all equal to “null”…

Has your problem been solved? If so, do you mind marking this thread as solved? Also, if you’re having issues with the gamemodes API please create another thread with all the relevant information so community members can help you out :smile:

Did you check that at runtime?
Please notice that variables equal to null do not mean that they are not implemented. Most of them are null in the API but not null at runtime!

Thank you to answer… I’m just seeking for the “Solved” button :sweat_smile:
I’ll test if it works (the GameModes)

EDIT : Seems it diesn’t work…

public void onPlayerMove(DisplaceEntityEvent.TargetPlayer e){
    if(plugin.isFreezingPlayers() && e.getTargetEntity().getGameModeData().type() != GameModes.SPECTATOR){

Try editing the title ;-).


public void onPlayerMove(DisplaceEntityEvent.TargetPlayer e){
    if(plugin.isFreezingPlayers() && e.getTargetEntity().get(Keys.GAME_MODE).orElse(GameModes.NOT_SET) != GameModes.SPECTATOR){

That works for me.

Thanks a lot.
I’m just wondering about the “orElse(GameModes.NOT_SET)” part of the code.

get(Keys.GAME_MODE) returns an Optional<GameMode> opt so to get the actual GameMode we could eigter do this:

if (opt.isPresent()) {
    GameMode m = opt.get();
    //work with m further

or just let it return the GameMode object if present or a default value if not:

GameMode default = GameModes.NOT_SET;
GameMode m = opt.orElse(default);

That’s what i was doing, so if for some reason the GameModeData is not available it just uses GameModes.NOT_SET.
I hope that makes this clear :slight_smile: