use of net.minecraft.server.level.ServerPlayer in project SpongeCommon by SpongePowered.
the class CommandsMixin method impl$preventPutIntoMapIfNodeIsComplex.
@SuppressWarnings("unchecked")
@Redirect(method = "fillUsableCommands", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", remap = false))
private <K, V> V impl$preventPutIntoMapIfNodeIsComplex(final Map<K, V> map, final K key, final V value, final CommandNode<CommandSourceStack> rootCommandSource, final CommandNode<SharedSuggestionProvider> rootSuggestion, final CommandSourceStack source, final Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> commandNodeToSuggestionNode) {
if (!map.containsKey(key)) {
// done here because this check is applicable
final ServerPlayer e = (ServerPlayer) source.getEntity();
final Map<CommandNode<CommandSourceStack>, List<CommandNode<SharedSuggestionProvider>>> playerNodes = this.impl$playerNodeCache.get(e);
if (!playerNodes.containsKey(key)) {
final List<CommandNode<SharedSuggestionProvider>> children = new ArrayList<>();
children.add((CommandNode<SharedSuggestionProvider>) value);
playerNodes.put((CommandNode<CommandSourceStack>) key, children);
}
// we need to swap it out.
if (value instanceof ArgumentCommandNode && CommandUtil.checkForCustomSuggestions(rootSuggestion)) {
rootSuggestion.addChild(this.impl$cloneArgumentCommandNodeWithoutSuggestions((ArgumentCommandNode<SharedSuggestionProvider, ?>) value));
} else {
rootSuggestion.addChild((CommandNode<SharedSuggestionProvider>) value);
}
return map.put(key, value);
}
// it's ignored anyway.
return null;
}
use of net.minecraft.server.level.ServerPlayer in project Tropicraft by Tropicraft.
the class ScubaData method onPlayerTick.
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
Level world = event.player.level;
if (event.phase == Phase.END) {
// TODO support more than chest slot?
ItemStack chestStack = event.player.getItemBySlot(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
if (chestItem instanceof ScubaArmorItem) {
LazyOptional<ScubaData> data = event.player.getCapability(CAPABILITY);
if (!world.isClientSide) {
underwaterPlayers.add((ServerPlayer) event.player);
}
if (isUnderWater(event.player)) {
data.ifPresent(d -> {
d.tick(event.player);
if (!world.isClientSide) {
d.updateClient((ServerPlayer) event.player, false);
}
});
((ScubaArmorItem) chestItem).tickAir(event.player, EquipmentSlot.CHEST, chestStack);
if (!world.isClientSide && world.getGameTime() % 60 == 0) {
// TODO this effect could be better, custom packet?
Vec3 eyePos = event.player.getEyePosition(0);
Vec3 motion = event.player.getDeltaMovement();
Vec3 particlePos = eyePos.add(motion.reverse());
((ServerLevel) world).sendParticles(ParticleTypes.BUBBLE, particlePos.x(), particlePos.y(), particlePos.z(), 4 + world.random.nextInt(3), 0.25, 0.25, 0.25, motion.length());
}
} else if (!world.isClientSide && underwaterPlayers.remove(event.player)) {
// Update client state as they leave the water
data.ifPresent(d -> d.updateClient((ServerPlayer) event.player, false));
}
}
}
}
use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method onClone.
/**
* This occurs when a player dies and is used to make sure that a player does not get a duplicate starting house.
*
* @param event The player clone event.
*/
@SubscribeEvent
public static void onClone(PlayerEvent.Clone event) {
if (event.getPlayer() instanceof ServerPlayer) {
// Don't add the tag unless the house item was added. This way it can be added if the feature is turned on.
// When the player is cloned, make sure to copy the tag. If this is not done the item can be given to the
// player again if they die before the log out and log back in.
CompoundTag originalTag = event.getOriginal().getPersistentData();
// Use the server configuration to determine if the house should be added for this player.
String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
if (startingItem != null && !startingItem.equalsIgnoreCase("Nothing")) {
if (originalTag.contains(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)) {
CompoundTag newPlayerTag = event.getPlayer().getPersistentData();
newPlayerTag.put(EntityPlayerConfiguration.PLAYER_ENTITY_TAG, originalTag.get(EntityPlayerConfiguration.PLAYER_ENTITY_TAG));
// Send the persist tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(originalTag.getCompound(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
}
}
use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.
the class StructureModerateHouse method AfterBuilding.
/**
* This method is used after the main building is build for any additional structures or modifications.
*
* @param configuration The structure configuration.
* @param world The current world.
* @param originalPos The original position clicked on.
* @param player The player which initiated the construction.
*/
@Override
public void AfterBuilding(StructureConfiguration configuration, ServerLevel world, BlockPos originalPos, Player player) {
ModerateHouseConfiguration houseConfig = (ModerateHouseConfiguration) configuration;
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
BuildingMethods.FillFurnaces(world, this.furnacePosition);
if (this.chestPosition != null && !playerConfig.builtStarterHouse && houseConfig.addChestContents) {
// Fill the chest if the player hasn't generated the starting house yet.
BuildingMethods.FillChest(world, this.chestPosition);
}
int minimumHeightForMineshaft = world.getMinBuildHeight() + 21;
if (this.trapDoorPosition != null && this.trapDoorPosition.getY() > minimumHeightForMineshaft && houseConfig.addMineshaft) {
// Build the mineshaft.
BuildingMethods.PlaceMineShaft(world, this.trapDoorPosition.below(), houseConfig.houseFacing, false);
}
// Make sure to set this value so the player cannot fill the chest a second time.
playerConfig.builtStarterHouse = true;
playerConfig.saveToPlayer(player);
// Make sure to send a message to the client to sync up the server player information and the client player
// information.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), ((ServerPlayer) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
use of net.minecraft.server.level.ServerPlayer in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method PlayerLoggedIn.
/**
* This event is used to determine if the player should be given the starting house item when they log in.
*
* @param event The event object.
*/
@SubscribeEvent
public static void PlayerLoggedIn(PlayerLoggedInEvent event) {
if (!event.getPlayer().level.isClientSide() && event.getPlayer() instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) event.getPlayer();
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
if (!playerConfig.givenHouseBuilder && startingItem != null) {
ItemStack stack = ItemStack.EMPTY;
switch(startingItem.toLowerCase()) {
case "starting house":
{
stack = new ItemStack(ModRegistry.StartHouse.get());
break;
}
case "moderate house":
{
stack = new ItemStack(ModRegistry.ModerateHouse.get());
break;
}
}
if (!stack.isEmpty()) {
System.out.println(player.getDisplayName().getString() + " joined the game for the first time. Giving them starting item.");
player.getInventory().add(stack);
player.containerMenu.broadcastChanges();
// Make sure to set the tag for this player so they don't get the item again.
playerConfig.givenHouseBuilder = true;
playerConfig.saveToPlayer(player);
}
}
// Send the tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
Aggregations