use of net.minecraft.entity.player.ServerPlayerEntity in project Overloaded by CJ-MC-Mods.
the class PlayerMessageHandler method accept.
@Override
public void accept(T message, Supplier<NetworkEvent.Context> ctx) {
ServerPlayerEntity player = ctx.get().getSender();
if (player == null) {
return;
}
ctx.get().enqueueWork(() -> method.handleMessage(player, message));
ctx.get().setPacketHandled(true);
}
use of net.minecraft.entity.player.ServerPlayerEntity in project NetherEx by LogicTechCorp.
the class PlayerHandler method onPlayerRespawn.
@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
World world = event.getPlayer().getEntityWorld();
PlayerEntity player = event.getPlayer();
PlayerInventory playerInventory = player.inventory;
if (!world.isRemote) {
ItemStack mirrorStack = ItemStack.EMPTY;
for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
ItemStack stack = playerInventory.getStackInSlot(i);
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
mirrorStack = stack;
break;
}
}
if (!mirrorStack.isEmpty()) {
if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
if (spawnDimension != null && player.dimension != spawnDimension) {
MinecraftServer server = world.getServer();
if (server != null) {
BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
}
}
}
}
}
}
}
use of net.minecraft.entity.player.ServerPlayerEntity in project AgriCraft by AgriCraft.
the class JsonSyncHandler method onConnect.
@SubscribeEvent
@SuppressWarnings("unused")
public void onConnect(PlayerEvent.PlayerLoggedInEvent event) {
if (event.getPlayer() instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
MinecraftServer server = player.getServer();
if (server != null) {
if (server.isDedicatedServer()) {
// always sync on dedicated servers
this.syncJsons(player);
} else if (server.getPublic()) {
// only sync when the server is open to LAN on integrated servers
this.syncJsons(player);
}
}
}
}
use of net.minecraft.entity.player.ServerPlayerEntity in project AgriCraft by AgriCraft.
the class GuiPlugin method onSeedAnalyzerRightClick.
public void onSeedAnalyzerRightClick(PlayerInteractEvent.RightClickBlock event) {
BlockPos pos = event.getPos();
BlockState state = event.getWorld().getBlockState(pos);
if (event.getPlayer().isSneaking()) {
return;
}
if (state.getBlock() != AgriCraft.instance.getModBlockRegistry().seed_analyzer.getBlock()) {
return;
}
event.setCancellationResult(ActionResultType.SUCCESS);
event.setCanceled(true);
if (event.getPlayer().world.isRemote) {
return;
}
INamedContainerProvider containerProvider = new INamedContainerProvider() {
@Nonnull
@Override
public ITextComponent getDisplayName() {
return new TranslationTextComponent("screen.agricraft.seed_analyzer");
}
@Override
public Container createMenu(int id, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity player) {
return new SeedAnalyzerContainer(id, event.getWorld(), playerInventory, pos);
}
};
NetworkHooks.openGui((ServerPlayerEntity) event.getPlayer(), containerProvider, pos);
}
use of net.minecraft.entity.player.ServerPlayerEntity in project RealisticArmorTiers by IsakViste.
the class EventEquipmentSets method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent evt) {
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
List<ServerPlayerEntity> playerList = Lists.newArrayList(server.getPlayerList().getPlayers());
IArmor armors = null;
List<PotionEffect> setEffects = new ArrayList<>();
boolean foundWhole = false;
for (ServerPlayerEntity serverPlayerEntity : playerList) {
int m;
List<ItemStack> stacks;
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
armors = (IArmor) serverPlayerEntity.getCapability(ArmorProvider.Armor);
stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
int numberOfStack = 0;
for (ItemStack stack : stacks) {
if (!stack.isEmpty()) {
numberOfStack++;
}
}
if (numberOfStack == armors.getItems().size()) {
foundWhole = true;
for (ItemStack stack : stacks) {
boolean found = false;
if (!stack.isEmpty()) {
for (int l = 0; l < armors.getItems().size(); l++) {
if (stack.getItem().equals(armors.getItems().get(l).getItem())) {
found = true;
break;
}
}
if (!found) {
foundWhole = false;
break;
}
}
}
}
}
if (foundWhole) {
setEffects = armors.getPotionEffects();
} else {
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
if (armors != null) {
m = 0;
setEffects = armors.getPotionEffects();
while (m < setEffects.size()) {
RegistryObject<Effect> potionEffect = RegistryObject.of(new ResourceLocation(setEffects.get(m).id), ForgeRegistries.POTIONS);
if (potionEffect.isPresent()) {
serverPlayerEntity.removeEffect(potionEffect.get());
}
m++;
}
armors.removeAllItems();
Collection<EffectInstance> potionEffectsPlayer = serverPlayerEntity.getActiveEffects();
Iterator<EffectInstance> potionEffects = potionEffectsPlayer.iterator();
while (potionEffects.hasNext()) {
EffectInstance o = potionEffects.next();
ResourceLocation effectResLoc = o.getEffect().getRegistryName();
if (effectResLoc == null) {
RealisticArmorTiers.LOGGER.warn("Could not find ResourceLocation of " + o.getDescriptionId());
continue;
}
PotionEffect usedPotion = new PotionEffect(effectResLoc.getNamespace() + ":" + o.getEffect().getRegistryName().getPath(), o.getAmplifier(), o.getDuration());
armors.addUsedPotionEffect(usedPotion);
potionEffects.remove();
}
stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
for (ItemStack stack : stacks) {
if (!stack.isEmpty()) {
armors.addItem(stack.copy());
}
}
}
} else {
serverPlayerEntity.removeAllEffects();
}
int setNumber = sets.armors.checkIfSet(serverPlayerEntity);
if (setNumber != -1) {
setEffects = sets.armors.getPotionEffects(setNumber);
}
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
if (setEffects != null && armors != null) {
armors.addPotionEffectList(setEffects);
}
}
}
if (armors != null) {
if (setEffects != null) {
m = 0;
while (m < setEffects.size()) {
Equiped.addPotionEffect(serverPlayerEntity, armors.getPotionEffects().get(m));
m++;
}
}
if (!foundWhole) {
setEffects = armors.getUsedPotionEffects();
Equiped.addUsedPotionEffect(serverPlayerEntity, setEffects, armors);
}
}
}
}
Aggregations