Java源码示例:org.spongepowered.api.entity.living.player.gamemode.GameMode
示例1
private void checkPlayerGodMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
if (user == null) {
return;
}
final Player player = user.getOnlinePlayer();
if (player == null || !player.get(Keys.INVULNERABLE).get()) {
// Most likely NPC
return;
}
if (!GDOptions.isOptionEnabled(Options.PLAYER_DENY_GODMODE)) {
return;
}
final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode gameMode = player.get(Keys.GAME_MODE).get();
if (gameMode == GameModes.CREATIVE || gameMode == GameModes.SPECTATOR || !player.get(Keys.INVULNERABLE).get()) {
return;
}
final Boolean noGodMode = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), playerData.getSubject(), Options.PLAYER_DENY_GODMODE, toClaim);
final boolean bypassOption = playerData.userOptionBypassPlayerDenyGodmode;
if (!bypassOption && noGodMode) {
player.offer(Keys.INVULNERABLE, false);
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().OPTION_APPLY_PLAYER_DENY_GODMODE);
}
}
示例2
private void checkPlayerGameMode(GDPermissionUser user, GDClaim fromClaim, GDClaim toClaim) {
if (user == null) {
return;
}
final Player player = user.getOnlinePlayer();
if (player == null) {
// Most likely Citizens NPC
return;
}
if (!GDOptions.isOptionEnabled(Options.PLAYER_GAMEMODE)) {
return;
}
final GDPlayerData playerData = user.getInternalPlayerData();
final GameMode currentGameMode = player.get(Keys.GAME_MODE).get();
final GameModeType gameModeType = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(GameModeType.class), playerData.getSubject(), Options.PLAYER_GAMEMODE, toClaim);
if (gameModeType == GameModeTypes.UNDEFINED && playerData.lastGameMode != GameModeTypes.UNDEFINED) {
player.offer(Keys.GAME_MODE, PlayerUtil.GAMEMODE_MAP.get(playerData.lastGameMode));
return;
}
final boolean bypassOption = playerData.userOptionBypassPlayerGamemode;
if (!bypassOption && gameModeType != null && gameModeType != GameModeTypes.UNDEFINED) {
final GameMode newGameMode = PlayerUtil.GAMEMODE_MAP.get(gameModeType);
if (currentGameMode != newGameMode) {
playerData.lastGameMode = PlayerUtil.GAMEMODE_MAP.inverse().get(gameModeType);
player.offer(Keys.GAME_MODE, PlayerUtil.GAMEMODE_MAP.get(gameModeType));
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.OPTION_APPLY_PLAYER_GAMEMODE,
ImmutableMap.of(
"gamemode", gameModeType.getName()));
GriefDefenderPlugin.sendMessage(player, message);
}
}
}
示例3
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
GameMode gamemode = ctx.<GameMode> getOne("gamemode").get();
Optional<String> worldName = ctx.<String> getOne("world");
World world = null;
if (worldName.isPresent())
{
world = Sponge.getServer().getWorld(worldName.get()).orElse(null);
}
else
{
if (src instanceof Player)
{
Player player = (Player) src;
world = player.getWorld();
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player or specify the world name to set its gamemode!"));
}
}
if (world != null)
{
world.getProperties().setGameMode(gamemode);
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Set gamemode of world."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!"));
}
return CommandResult.success();
}
示例4
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
World w = args.<World>getOne("world").get();
GameMode dif = args.<GameMode>getOne("gamemode").get();
w.getProperties().setGameMode(dif);
Messages.send(src, "world.command.world.setgamemode.success", "%world%", w.getName(), "%gamemode%", dif.getName());
return CommandResult.success();
}
示例5
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_BASE);
GameMode gm = args.<GameMode>getOne("gamemode").get();
if (!args.hasAny("player")) {
checkIfPlayer(sender);
Player p = (Player) sender;
//Perm check
if (gm == GameModes.SURVIVAL) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_ADVENTURE);
} else if (gm == GameModes.CREATIVE) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_CREATIVE);
} else if (gm == GameModes.ADVENTURE) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_ADVENTURE);
} else if (gm == GameModes.SPECTATOR) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_SELF_SPECTATOR);
}
p.offer(Keys.GAME_MODE, gm);
Messages.send(sender, "gamemode.command.gamemode.success", "%gamemode%", gm.getName());
return CommandResult.success();
} else {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_BASE);
Player t = args.<Player>getOne("player").get();
//Perm check
if (gm == GameModes.SURVIVAL) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_ADVENTURE);
} else if (gm == GameModes.CREATIVE) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_CREATIVE);
} else if (gm == GameModes.ADVENTURE) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_ADVENTURE);
} else if (gm == GameModes.SPECTATOR) {
checkPermission(sender, GamemodePermissions.UC_GAMEMODE_GAMEMODE_OTHERS_SPECTATOR);
}
t.offer(Keys.GAME_MODE, gm);
Messages.send(t, "gamemode.command.gamemode.success.others", "%sender%", sender, "%gamemode%", gm.getName());
Messages.send(sender, "gamemode.command.gamemode.success.self", "%player%", t, "%gamemode%", gm.getName());
return CommandResult.success();
}
}
示例6
@Nullable
@Override
public GameMode parseValue(CommandSource sender, CommandArgs args) throws ArgumentParseException {
String value = args.next();
try {
if (Sponge.getRegistry().getType(CatalogTypes.GAME_MODE, value).isPresent()) {
return Sponge.getRegistry().getType(CatalogTypes.GAME_MODE, value).get();
}
} catch (NullPointerException ignore) {
}
switch (value.toLowerCase()) {
case "survival":
case "0":
case "s":
return GameModes.SURVIVAL;
case "creative":
case "c":
case "1":
return GameModes.CREATIVE;
case "adventure":
case "2":
case "a":
return GameModes.ADVENTURE;
case "spectator":
case "3":
case "spec":
case "sp":
return GameModes.SPECTATOR;
default:
throw (args.createError(Messages.getFormatted(sender, "gamemode.command.gamemode.invalidgamemode", "%gamemode%", value)));
}
}
示例7
@Override
public void run() {
for (World world : Sponge.getServer().getWorlds()) {
for (Player player : world.getPlayers()) {
if (player.isRemoved()) {
continue;
}
final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
// send queued visuals
int count = 0;
final Iterator<BlockSnapshot> iterator = playerData.queuedVisuals.iterator();
while (iterator.hasNext()) {
final BlockSnapshot snapshot = iterator.next();
if (count > GriefDefenderPlugin.getGlobalConfig().getConfig().visual.clientVisualsPerTick) {
break;
}
player.sendBlockChange(snapshot.getPosition(), snapshot.getState());
iterator.remove();
count++;
}
// chat capture
playerData.updateRecordChat();
// health regen
if (world.getProperties().getTotalTime() % 100 == 0L) {
final GameMode gameMode = player.get(Keys.GAME_MODE).get();
// Handle player health regen
if (gameMode != GameModes.CREATIVE && gameMode != GameModes.SPECTATOR && GDOptions.isOptionEnabled(Options.PLAYER_HEALTH_REGEN)) {
final double maxHealth = player.get(Keys.MAX_HEALTH).get();
final double currentHealth = player.get(Keys.HEALTH).get();
if (currentHealth < maxHealth) {
final double regenAmount = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), playerData.getSubject(), Options.PLAYER_HEALTH_REGEN, claim);
if (regenAmount > 0) {
final double newHealth = currentHealth + regenAmount;
if (newHealth > maxHealth) {
player.offer(Keys.MAX_HEALTH, maxHealth);
} else {
player.offer(Keys.HEALTH, newHealth);
}
}
}
}
}
// teleport delay
if (world.getProperties().getTotalTime() % 20 == 0L) {
if (playerData.teleportDelay > 0) {
final int delay = playerData.teleportDelay - 1;
if (delay == 0) {
player.setLocation(playerData.teleportLocation);
playerData.teleportDelay = 0;
playerData.teleportLocation = null;
playerData.teleportSourceLocation = null;
continue;
}
TextAdapter.sendComponent(player, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.TELEPORT_DELAY_NOTICE,
ImmutableMap.of("delay", TextComponent.of(delay, TextColor.GOLD))));
playerData.teleportDelay = delay;
}
}
}
}
}
示例8
private void actOnJoinEvent(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
UUID playerUUID = player.getUniqueId();
UUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);
SpongeAFKListener.AFK_TRACKER.performedAction(playerUUID, time);
String world = player.getWorld().getName();
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetAddress address = player.getConnection().getAddress().getAddress();
String playerName = player.getName();
String displayName = player.getDisplayNameData().displayName().get().toPlain();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID));
Session session = new Session(playerUUID, serverUUID, time, world, gm);
session.putRawData(SessionKeys.NAME, playerName);
session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());
sessionCache.cacheSession(playerUUID, session)
.ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction(
playerUUID, new Nickname(displayName, time, serverUUID),
(uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)
));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
示例9
private String getGameMode(Player player) {
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
return gameMode.map(gm -> gm.getName().toUpperCase()).orElse("ADVENTURE");
}
示例10
@ApiModelProperty(value = "Which game mode the world defaults to")
public Optional<GameMode> getGameMode() {
return gameMode != null ? gameMode.getLive(GameMode.class) : Optional.empty();
}
示例11
@ApiModelProperty(dataType = "string", value = "The game mode of the player")
public CachedCatalogType<GameMode> getGameMode() {
return gameMode;
}
示例12
public GameModeView(GameMode value) {
super(value);
this.id = value.getId();
this.name = value.getTranslation().get();
}
示例13
@JsonDetails
@ApiModelProperty(value = "The game mode of the world", required = true)
public CachedCatalogType<GameMode> getGameMode() {
return gameMode;
}
示例14
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
String name = ctx.<String> getOne("name").get();
String dimensionInput = ctx.<String> getOne("dimension").get();
String generatorInput = ctx.<String> getOne("generator").get();
String difficultyInput = ctx.<String> getOne("difficulty").get();
GameMode gamemode = ctx.<GameMode> getOne("gamemode").get();
Difficulty difficulty = null;
DimensionType dimension = null;
GeneratorType generator = null;
if (Sponge.getRegistry().getType(DimensionType.class, dimensionInput).isPresent())
{
dimension = Sponge.getRegistry().getType(DimensionType.class, dimensionInput).get();
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Dimension type specified not found."));
return CommandResult.success();
}
if (Sponge.getRegistry().getType(GeneratorType.class, generatorInput).isPresent())
{
generator = Sponge.getRegistry().getType(GeneratorType.class, generatorInput).get();
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Generator type specified not found."));
return CommandResult.success();
}
if (Sponge.getRegistry().getType(Difficulty.class, difficultyInput).isPresent())
{
difficulty = Sponge.getRegistry().getType(Difficulty.class, difficultyInput).get();
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Difficulty specified not found."));
return CommandResult.success();
}
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Beginning creation of world."));
WorldArchetype worldSettings = WorldArchetype.builder()
.enabled(true)
.loadsOnStartup(true)
.keepsSpawnLoaded(true)
.dimension(dimension)
.generator(generator)
.gameMode(gamemode)
.build(name.toLowerCase(), name);
try
{
WorldProperties worldProperties = Sponge.getGame().getServer().createWorldProperties(name, worldSettings);
Optional<World> world = Sponge.getGame().getServer().loadWorld(worldProperties);
if (world.isPresent())
{
world.get().getProperties().setDifficulty(difficulty);
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "World ", TextColors.GRAY, name, TextColors.GOLD, " has been created."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world could not be created."));
}
}
catch (IOException e)
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world properties could not be created."));
}
return CommandResult.success();
}
示例15
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
String name = ctx.<String> getOne("name").get();
Optional<String> dimensionInput = ctx.<String> getOne("dimension");
Optional<String> generatorInput = ctx.<String> getOne("generator");
Optional<String> difficultyInput = ctx.<String> getOne("difficulty");
Optional<GameMode> gamemode = ctx.<GameMode> getOne("gamemode");
Difficulty difficulty = Difficulties.NORMAL;
DimensionType dimension = DimensionTypes.OVERWORLD;
GeneratorType generator = GeneratorTypes.OVERWORLD;
if (dimensionInput.isPresent() && Sponge.getRegistry().getType(DimensionType.class, dimensionInput.get()).isPresent())
{
dimension = Sponge.getRegistry().getType(DimensionType.class, dimensionInput.get()).get();
}
else if (dimensionInput.isPresent())
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Dimension type specified not found."));
}
if (generatorInput.isPresent() && Sponge.getRegistry().getType(GeneratorType.class, generatorInput.get()).isPresent())
{
generator = Sponge.getRegistry().getType(GeneratorType.class, generatorInput.get()).get();
}
else if (generatorInput.isPresent())
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Generator type specified not found."));
}
if (difficultyInput.isPresent() && Sponge.getRegistry().getType(Difficulty.class, difficultyInput.get()).isPresent())
{
difficulty = Sponge.getRegistry().getType(Difficulty.class, difficultyInput.get()).get();
}
else if (difficultyInput.isPresent())
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Difficulty specified not found."));
}
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Beginning loading of world."));
WorldArchetype worldSettings = WorldArchetype.builder()
.enabled(true)
.loadsOnStartup(true)
.keepsSpawnLoaded(true)
.dimension(dimension)
.generator(generator)
.gameMode(gamemode.orElse(GameModes.SURVIVAL))
.build(name.toLowerCase(), name);
try
{
WorldProperties worldProperties = Sponge.getGame().getServer().createWorldProperties(name, worldSettings);
Optional<World> world = Sponge.getGame().getServer().loadWorld(worldProperties);
if (world.isPresent())
{
world.get().getProperties().setDifficulty(difficulty);
src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "World ", TextColors.GRAY, name, TextColors.GOLD, " has been loaded."));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world could not be created."));
}
}
catch (IOException e)
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world properties could not be created."));
}
return CommandResult.success();
}
示例16
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
String name = (String) args.getOne("name").get();
Optional<DimensionType> dimension = args.getOne("dimension");
Optional<GeneratorType> generator = args.getOne("generator");
Collection<WorldGeneratorModifier> wgm = args.getAll("wgm");
Optional<Long> seed = args.getOne("seed");
Optional<GameMode> gm = args.getOne("gamemode");
Optional<Difficulty> diff = args.getOne("difficulty");
boolean nostructures = args.hasAny("n");
boolean load = args.<Boolean>getOne("l").orElse(true);
boolean keepspawnloaded = args.<Boolean>getOne("k").orElse(true);
boolean allowcommands = args.<Boolean>getOne("c").orElse(true);
boolean bonuschest = args.<Boolean>getOne("b").orElse(true);
Path path = Sponge.getGame().getSavesDirectory();
if (Files.exists(path.resolve(name.toLowerCase())) || Files.exists(path.resolve(name)) || Sponge.getServer().getAllWorldProperties().stream().anyMatch(x -> x.getWorldName().equalsIgnoreCase(name))) {
throw new ErrorMessageException(Messages.getFormatted(sender, "world.exists", "%name%", name));
}
Messages.send(sender, "world.command.world.create.starting", "%name%", name);
WorldArchetype.Builder archetype = WorldArchetype.builder().enabled(true);
dimension.ifPresent(archetype::dimension);
generator.ifPresent(archetype::generator);
archetype.generatorModifiers(wgm.toArray(new WorldGeneratorModifier[wgm.size()]));
seed.ifPresent(archetype::seed);
gm.ifPresent(archetype::gameMode);
diff.ifPresent(archetype::difficulty);
archetype.usesMapFeatures(!nostructures);
archetype.loadsOnStartup(load);
archetype.keepsSpawnLoaded(keepspawnloaded);
archetype.commandsAllowed(allowcommands);
archetype.generateBonusChest(bonuschest);
WorldProperties props;
try {
props = Sponge.getServer().createWorldProperties(name.toLowerCase(), archetype.build(name.toLowerCase(), name));
} catch (IOException e) {
throw new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.fileerror", "%error%", e.getMessage()));
}
Sponge.getServer().saveWorldProperties(props);
World world = Sponge.getServer().loadWorld(props).orElseThrow(() -> new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.loaderror")));
Messages.send(sender, "world.command.world.create.success", "%name%", world.getName());
return CommandResult.success();
}