Add event for player changing game mode (#7355)

This commit is contained in:
Ocelot authored and GitHub committed 2020-10-15 10:15:06 -07:00
1 parent 5f292895cb
commit 51fa230e7b
8 files changed
+176 -7

No files matched your search

@@ -25,6 +25,7 @@ import net.minecraft.entity.item.ItemEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
@@ -510,4 +511,40 @@ public class PlayerEvent extends LivingEvent
return this.toDim;
}
}
/**
* Fired when the game type of a server player is changed to a different value than what it was previously. Eg Creative to Survival, not Survival to Survival.
* If the event is cancelled the game mode of the player is not changed and the value of <code>newGameMode</code> is ignored.
*/
@Cancelable
public static class PlayerChangeGameModeEvent extends PlayerEvent
{
private final GameType currentGameMode;
private GameType newGameMode;
public PlayerChangeGameModeEvent(PlayerEntity player, GameType currentGameMode, GameType newGameMode)
{
super(player);
this.currentGameMode = currentGameMode;
this.newGameMode = newGameMode;
}
public GameType getCurrentGameMode()
{
return currentGameMode;
}
public GameType getNewGameMode()
{
return newGameMode;
}
/**
* Sets the game mode the player will be changed to if this event is not cancelled.
*/
public void setNewGameMode(GameType newGameMode)
{
this.newGameMode = newGameMode;
}
}
}