本文整理汇总了Java中org.spongepowered.api.entity.living.player.gamemode.GameModes类的典型用法代码示例。如果您正苦于以下问题:Java GameModes类的具体用法?Java GameModes怎么用?Java GameModes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GameModes类属于org.spongepowered.api.entity.living.player.gamemode包,在下文中一共展示了GameModes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildContent
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
protected Optional<ViewerData> buildContent(DataView dataView) {
return Optional.of(new ViewerData(
dataView.getString(VigilateKeys.CAMERA.getQuery()).orElse(""),
dataView.getString(VigilateKeys.OLD_LOCATION_WORLD.getQuery()).orElse("world"),
dataView.getDouble(VigilateKeys.OLD_LOCATION_X.getQuery()).orElse(0.0),
dataView.getDouble(VigilateKeys.OLD_LOCATION_Y.getQuery()).orElse(0.0),
dataView.getDouble(VigilateKeys.OLD_LOCATION_Z.getQuery()).orElse(0.0),
dataView.getCatalogType(VigilateKeys.OLD_GAME_MODE.getQuery(), CatalogTypes.GAME_MODE).orElse(GameModes.NOT_SET),
dataView.getBoolean(VigilateKeys.OLD_IS_FLYING.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_AFFECTS_SPAWNING.getQuery()).orElse(true),
dataView.getBoolean(VigilateKeys.OLD_VANISH.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_VANISH_PREVENTS_TARGETING.getQuery()).orElse(false),
dataView.getBoolean(VigilateKeys.OLD_VANISH_IGNORES_COLLISION.getQuery()).orElse(false),
dataView.getDouble(VigilateKeys.OLD_FLYING_SPEED.getQuery()).orElse(0.02)
));
}
示例2: getDefaultGameMode
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
public GameMode getDefaultGameMode() {
if (!Sponge.isServerAvailable()) {
return GameMode.SURVIVAL;
}
Optional<WorldProperties>properties = Sponge.getServer().getDefaultWorld();
if (!properties.isPresent()) {
return GameMode.SURVIVAL;
}
org.spongepowered.api.entity.living.player.gamemode.GameMode gameMode = properties.get().getGameMode();
if (gameMode == GameModes.SURVIVAL) {
return GameMode.SURVIVAL;
} else if (gameMode == GameModes.ADVENTURE) {
return GameMode.ADVENTURE;
} else if (gameMode == GameModes.CREATIVE) {
return GameMode.CREATIVE;
} else if (gameMode == GameModes.SPECTATOR) {
return GameMode.SPECTATOR;
}
return GameMode.SURVIVAL; // Unimplemented gamemode's and NOT_SET
}
示例3: onPlayerLeftClickProtect
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerLeftClickProtect(InteractBlockEvent.Primary.MainHand event, @First Player player)
{
if (!player.gameMode().get().equals(GameModes.CREATIVE))
return;
Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
if (!optLoc.isPresent())
return;
Optional<List<Shop>> shop = ShopsData.getShops(optLoc.get());
if (shop.isPresent()) {
Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItem.isPresent() || (!optItem.get().getItem().equals(ItemTypes.BEDROCK) && !optItem.get().getItem().equals(ItemTypes.REDSTONE) && !optItem.get().getItem().equals(ItemTypes.STICK))) {
event.setCancelled(true);
}
}
}
示例4: getName
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
public static Text getName(final GameMode gamemode) {
if (gamemode == null) return Text.EMPTY;
if (gamemode.equals(GameModes.SURVIVAL)){
return EAMessages.GAMEMODE_SURVIVAL.getText();
} else if (gamemode.equals(GameModes.CREATIVE)) {
return EAMessages.GAMEMODE_CREATIVE.getText();
} else if (gamemode.equals(GameModes.ADVENTURE)) {
return EAMessages.GAMEMODE_ADVENTURE.getText();
} else if (gamemode.equals(GameModes.SPECTATOR)) {
return EAMessages.GAMEMODE_SPECTATOR.getText();
} else if (gamemode.equals(GameModes.NOT_SET)) {
return EAMessages.GAMEMODE_NOT_SET.getText();
}
return Text.EMPTY;
}
示例5: getGameMode
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
public static Optional<GameMode> getGameMode(final String arg) {
if (arg == null) return Optional.empty();
switch (arg) {
case "0":
case "s":
return Optional.of(GameModes.SURVIVAL);
case "1":
case "c":
return Optional.of(GameModes.CREATIVE);
case "2":
case "a":
return Optional.of(GameModes.ADVENTURE);
case "3":
case "sp":
return Optional.of(GameModes.SPECTATOR);
case "-1":
return Optional.of(GameModes.NOT_SET);
default:
return Sponge.getGame().getRegistry().getType(GameMode.class, arg);
}
}
示例6: commandTop
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
private CompletableFuture<Boolean> commandTop(final EPlayer player) {
final Optional<Transform<World>> transform = this.plugin.getEverAPI().getManagerUtils().getLocation().getMaxBlock(
player.getTransform(),
!(player.isGod() || player.getGameMode().equals(GameModes.CREATIVE)));
if (!transform.isPresent()) {
EEMessages.TOP_TELEPORT_ERROR.sendTo(player);
return CompletableFuture.completedFuture(false);
}
long delay = this.plugin.getConfigs().getTeleportDelay(player);
if (delay > 0) {
EEMessages.TOP_DELAY.sender()
.replace("{delay}", this.plugin.getEverAPI().getManagerUtils().getDate().formatDate(System.currentTimeMillis() + delay))
.sendTo(player);
}
player.setTeleport(delay, () -> this.teleport(player, transform.get()), player.hasPermission(EEPermissions.TELEPORT_BYPASS_MOVE.get()));
return CompletableFuture.completedFuture(true);
}
示例7: onItemUse
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
public boolean onItemUse(ItemStack itemStack, Player player, HandType currHand, BlockSnapshot clickedBlock,
Direction side, Vector3d hitPoint) {
CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
Vector3d pos;
if (hitPoint == null) {
pos = clickedBlock.getPosition().add(side.asBlockOffset()).toDouble().add(0.5, 0, 0.5);
} else {
pos = clickedBlock.getPosition().toDouble().add(hitPoint);
}
TurtleEntity turtle = new TurtleEntity(player.getWorld());
turtle.setPosition(pos);
Vector3d r = player.getHeadRotation();
turtle.setRotation(new Vector3d(r.getX(), r.getY() + 180, r.getZ()));
if (world.spawnEntity(turtle)) {
if (player.gameMode().get() != GameModes.CREATIVE) {
itemStack.setQuantity(itemStack.getQuantity() - 1);
if (itemStack.getQuantity() == 0) {
itemStack = null;
}
player.setItemInHand(currHand, itemStack);
}
}
return false;
}
示例8: reset
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
public LanternWorldArchetypeBuilder reset() {
this.usesMapFeatures = true;
this.gameMode = GameModes.SURVIVAL;
this.difficulty = Difficulties.NORMAL;
this.portalAgentType = (LanternPortalAgentType) PortalAgentTypes.DEFAULT;
this.hardcore = false;
this.keepsSpawnLoaded = null;
this.loadsOnStartup = false;
this.generateSpawnOnLoad = true;
this.enabled = true;
this.generateBonusChest = false;
this.commandsAllowed = true;
this.dimensionType = null;
this.generatorModifiers = Collections.emptySet();
this.seed = null;
this.generatorType = null;
this.generatorSettings = null;
this.waterEvaporates = null;
this.buildHeight = 256;
this.serializationBehavior = SerializationBehaviors.AUTOMATIC;
return this;
}
示例9: getBlockDigTimeWith
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
public int getBlockDigTimeWith(int x, int y, int z, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
// Check if the user has the creative game mode
if (profile != null) {
final Optional<User> optUser = Lantern.getGame().getUserStorageService().get(profile);
if (optUser.isPresent()) {
final User user = optUser.get();
if (user.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET) == GameModes.CREATIVE) {
return 0;
}
}
}
final Optional<UnbreakableProperty> optUnbreakableProperty = getProperty(x, y, z, UnbreakableProperty.class);
if (optUnbreakableProperty.isPresent() && optUnbreakableProperty.get().getValue() == Boolean.TRUE) {
return -1;
}
final Optional<HardnessProperty> optHardnessProperty = getProperty(x, y, z, HardnessProperty.class);
if (optHardnessProperty.isPresent()) {
final Double value = optHardnessProperty.get().getValue();
double hardness = value == null ? 0 : value;
// TODO: Calculate the duration
return hardness <= 0 ? 0 : 1;
}
return 0;
}
示例10: handleEvent
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
protected void handleEvent(EntityProtocolUpdateContext context, EntityEvent event) {
if (event instanceof SpectateEntityEvent) {
final Entity entity = ((SpectateEntityEvent) event).getSpectatedEntity().orElse(null);
if (entity == null) {
context.sendToSelf(() -> new MessagePlayOutSetCamera(getRootEntityId()));
} else {
context.getId(entity).ifPresent(id -> context.sendToSelf(() -> new MessagePlayOutSetCamera(id)));
}
} else if (event instanceof RefreshAbilitiesPlayerEvent) {
final GameMode gameMode = this.entity.get(Keys.GAME_MODE).get();
final float flySpeed = getFlySpeed();
final float fov = getFovModifier();
context.sendToSelf(() -> new MessagePlayOutPlayerAbilities(
this.entity.get(Keys.IS_FLYING).orElse(false), canFly(), false, gameMode == GameModes.CREATIVE, flySpeed, fov));
} else {
super.handleEvent(context, event);
}
}
示例11: handleCreativeClick
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
public void handleCreativeClick(int slotIndex, @Nullable ItemStack itemStack) {
populate();
// You can only use this in creative mode
if (this.player == null || this.player.get(Keys.GAME_MODE).get() != GameModes.CREATIVE) {
return;
}
// Convert the slot index
slotIndex = clientSlotIndexToServer(slotIndex);
// Update the target slot and cursor
if (slotIndex != -1) {
queueSilentSlotChange(this.slots[slotIndex]);
}
// queueSlotChange(this.cursor);
final int slotIndex1 = slotIndex;
tryProcessBehavior(behavior -> behavior.handleCreativeClick(this,
slotIndex1 == -1 ? null : this.slots[slotIndex1], itemStack));
}
示例12: onItemPickup
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup event, @First(typeFilter = {Player.class}) Player player) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (character.isStub()) {
return;
}
if (player.get(Keys.GAME_MODE).get() != GameModes.SURVIVAL)
return;
for (SlotTransaction slotTransaction : event.getTransactions()) {
Slot i = slotTransaction.getSlot();
int index = ((SlotAdapter) i).getOrdinal();
if (Utils.isHotbar(index)) {
ItemStack a = slotTransaction.getFinal().createStack();
if (inventoryService.canUse(a, character) != CannotUseItemReson.OK) {
event.setCancelled(true);
return;
} else {
inventoryService.initializeHotbar(character, index, a);
}
}
}
}
示例13: getState
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
public PlayerState getState() {
Player player = getPlayer().orElseThrow(IllegalStateException::new);
ImmutableList.Builder<WarItem> builder = ImmutableList.builder();
for (Inventory inventory : player.getInventory().slots()) {
Optional<ItemStack> peek = inventory.peek();
if (peek.isPresent()) {
builder.add(plugin.getWarItem(peek.get()));
}
}
int gameMode = 0;
GameMode gameMode1 = player.getGameModeData().getValue(Keys.GAME_MODE).orElseThrow(IllegalStateException::new).get();
if (gameMode1 == GameModes.CREATIVE)
gameMode = WarGameMode.CREATIVE;
// return new PlayerState(gameMode, (WarItem[]) builder.build().toArray(),
// null, null, null, null,
// player.getHealthData().getValue(Keys.HEALTH).orElseThrow(IllegalStateException::new).get(),
// player.getS);
throw new UnsupportedOperationException("Not implemented yet");
}
示例14: run
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
@Override
public void run() {
PotionEffect speedEffect = PotionEffect.builder()
.duration(3 * 20)
.amplifier(5)
.particles(false)
.potionType(PotionEffectTypes.SPEED)
.build();
for (World world : getWorlds()) {
for (Entity entity : world.getEntities(p -> p.getType().equals(EntityTypes.PLAYER))) {
if (entity.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) != GameModes.SURVIVAL) {
continue;
}
List<PotionEffect> potionEffects = entity.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(speedEffect);
entity.offer(Keys.POTION_EFFECTS, potionEffects);
}
}
}
示例15: aquireSpec
import org.spongepowered.api.entity.living.player.gamemode.GameModes; //导入依赖的package包/类
public static CommandSpec aquireSpec() {
Map<String, GameMode> map = new HashMap<>();
map.put("survival", GameModes.SURVIVAL);
map.put("creative", GameModes.CREATIVE);
map.put("adventure", GameModes.ADVENTURE);
map.put("spectator", GameModes.SPECTATOR);
return CommandSpec.builder()
.description(Text.of("Change gamemode"))
.permission("skree.gamemode")
.arguments(
flags().flag("f").buildWith(
seq(
onlyOne(choices(Text.of("mode"), map)),
onlyOne(playerOrSource(Text.of("target")))
)
)
).executor(new GameModeCommand()).build();
}