本文整理汇总了Java中org.spongepowered.api.entity.living.player.gamemode.GameModes.CREATIVE属性的典型用法代码示例。如果您正苦于以下问题:Java GameModes.CREATIVE属性的具体用法?Java GameModes.CREATIVE怎么用?Java GameModes.CREATIVE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spongepowered.api.entity.living.player.gamemode.GameModes
的用法示例。
在下文中一共展示了GameModes.CREATIVE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultGameMode
@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
}
示例2: onItemUse
@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;
}
示例3: getBlockDigTimeWith
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;
}
示例4: handleCreativeClick
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));
}
示例5: getState
@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");
}
示例6: blockplace
@Listener
public void blockplace(final ChangeBlockEvent.Place event, @First Player player)
{
if (this.unlimitedPlayers.contains(player.getUniqueId()))
{
if (player.getGameModeData().type().get() == GameModes.CREATIVE)
{
return;
}
ItemStack item = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null);
if (item != null)
{
item.setQuantity(item.getQuantity() + 1);
player.setItemInHand(HandTypes.MAIN_HAND, item);
}
}
}
示例7: onCrateRightClick
@Listener
public void onCrateRightClick(InteractBlockEvent.Primary.MainHand event){
//System.out.println("primary interaction");
if(!(event.getCause().root() instanceof Player)) return;
Player plr = (Player) event.getCause().root();
if(!event.getTargetBlock().getLocation().isPresent()) return;
Location location = event.getTargetBlock().getLocation().get();
if(crateUtilities.physicalCrates.containsKey(location)){
if(!plr.hasPermission("huskycrates.tester") || plr.hasPermission("huskycrates.tester") && plr.getGameModeData().get(Keys.GAME_MODE).get() != GameModes.CREATIVE) {
event.setCancelled(true);
listRewards(plr,crateUtilities.physicalCrates.get(location).vc);
}
}
}
示例8: getSpongeGamemode
private org.spongepowered.api.entity.living.player.gamemode.GameMode getSpongeGamemode(GameMode gameMode) {
if (gameMode == GameMode.SURVIVAL) {
return GameModes.SURVIVAL;
} else if (gameMode == GameMode.ADVENTURE) {
return GameModes.ADVENTURE;
} else if (gameMode == GameMode.CREATIVE) {
return GameModes.CREATIVE;
} else if (gameMode == GameMode.SPECTATOR) {
return GameModes.SPECTATOR;
}
return GameModes.NOT_SET;
}
示例9: onEntityHit
@Override
public void onEntityHit(Entity entity, Player player, HandType currHand) {
remove();
Optional<String> dropRule = this.world.getGameRule("doEntityDrops");
if (player.gameMode().get() != GameModes.CREATIVE && (!dropRule.isPresent()
|| Boolean.parseBoolean(dropRule.get()))) {
dropAsItem();
}
}
示例10: onBlockBreak
@Override
public boolean onBlockBreak(CustomWorld world, Vector3i pos, Player player) {
getStructure(world, pos).remove();
((PipeTileData) world.getBlockData(pos)).onBreak();
if (player == null || player.gameMode().get() != GameModes.CREATIVE) {
fireDropItemEvent(world.getWorld(), pos);
}
ImplUtil.playBlockBreakSound(world.getWorld(), pos, BlockTypes.GLASS.getDefaultState(), player);
return true;
}
示例11: checkPvpProtectionNeeded
public void checkPvpProtectionNeeded(Player player) {
// if anti spawn camping feature is not enabled, do nothing
if (!GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().pvp.protectFreshSpawns) {
return;
}
GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
// if pvp rules are disabled in claim, do nothing
if (!claim.pvpRulesApply()) {
return;
}
// if player is in creative mode, do nothing
if (player.get(Keys.GAME_MODE).get() == GameModes.CREATIVE) {
return;
}
// if the player has the damage any player permission enabled, do nothing
if (player.hasPermission(GPPermissions.NO_PVP_IMMUNITY)) {
return;
}
// check inventory for well, anything
if (GriefPreventionPlugin.isInventoryEmpty(player)) {
// if empty, apply immunity
playerData.pvpImmune = true;
// inform the player after he finishes respawning
GriefPreventionPlugin.sendMessage(player, this.messageData.pvpImmunityStart.toText());
// start a task to re-check this player's inventory every minute
// until his immunity is gone
PvPImmunityValidationTask task = new PvPImmunityValidationTask(player);
Sponge.getGame().getScheduler().createTaskBuilder().delay(1, TimeUnit.MINUTES).execute(task).submit(this);
}
}
示例12: getDiggingDuration
private long getDiggingDuration(Vector3i pos) {
if (this.player.get(Keys.GAME_MODE).get() == GameModes.CREATIVE) {
return 0;
}
// Don't pass the players profile through, this avoids an
// unnecessary user lookup
return this.player.getWorld().getBlockDigTimeWith(pos.getX(), pos.getY(), pos.getZ(), null,
this.player.getItemInHand(HandTypes.MAIN_HAND).orElse(null));
}
示例13: handleMiddleClick
/**
* Handles a number key interaction.
*
* @param slotIndex The slot index that was clicked
*/
private void handleMiddleClick(int slotIndex) {
// Middle click is only used in creative,
// you can only do it if the cursor is empty
// and the target slot isn't empty.
if (slotIndex != -1 && this.cursor.getRaw().isEmpty() &&
!this.slots[slotIndex].getRaw().isEmpty() &&
(this.player != null && this.player.get(Keys.GAME_MODE).get() == GameModes.CREATIVE)) {
queueSlotChange(this.cursor);
}
tryProcessBehavior(behavior -> behavior.handleClick(this,
slotIndex == -1 ? null : this.slots[slotIndex], MouseButton.MIDDLE));
}
示例14: onInventoryClose
@Listener
public void onInventoryClose(InteractInventoryEvent.Close event, @First(typeFilter = {Player.class}) Player player) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (player.get(Keys.GAME_MODE).get() == GameModes.CREATIVE)
return;
inventoryService.initializeHotbar(character);
inventoryService.initializeArmor(character);
damageService.recalculateCharacterWeaponDamage(character);
}
示例15: onBlockChange
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (optLoc.isPresent() && isApplicable(optLoc.get())) {
boolean preventedFromBuilding = check(player, optLoc.get());
// Block players that are allowed to build, otherwise send the no build message
Text noEditMessage = Text.of(TextColors.RED, "You can't change blocks here!");
if (!preventedFromBuilding) {
if (player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.CREATIVE) {
preventedFromBuilding = true;
noEditMessage = Text.of(TextColors.RED, "You must be in creative mode to edit!");
}
}
if (preventedFromBuilding) {
if (event.getCause().root().equals(player)) {
player.sendMessage(noEditMessage);
}
event.setCancelled(true);
return;
}
}
}
}