Search in sources :

Example 1 with CraftPlayer

use of org.bukkit.craftbukkit.v.entity.CraftPlayer in project Arclight by IzzelAliz.

the class LivingEntityMixin method arclight$setScaled.

@Inject(method = "setHealth", cancellable = true, at = @At("HEAD"))
public void arclight$setScaled(float health, CallbackInfo ci) {
    if (this instanceof ServerPlayerEntityBridge) {
        CraftPlayer player = ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity();
        player.setRealHealth(MathHelper.clamp(health, 0.0F, player.getMaxHealth()));
        player.updateScaledHealth(false);
        ci.cancel();
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CraftPlayer

use of org.bukkit.craftbukkit.v.entity.CraftPlayer in project Arclight by IzzelAliz.

the class SaveHandlerMixin method arclight$lastSeenTime.

@Inject(method = "readPlayerData", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;contains(Ljava/lang/String;I)Z"))
public void arclight$lastSeenTime(PlayerEntity player, CallbackInfoReturnable<CompoundNBT> cir) {
    if (player instanceof ServerPlayerEntity) {
        CraftPlayer craftPlayer = ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity();
        // Only update first played if it is older than the one we have
        long modified = new File(this.playersDirectory, player.getUniqueID().toString() + ".dat").lastModified();
        if (modified < craftPlayer.getFirstPlayed()) {
            craftPlayer.setFirstPlayed(modified);
        }
    }
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) File(java.io.File) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with CraftPlayer

use of org.bukkit.craftbukkit.v.entity.CraftPlayer in project Arclight by IzzelAliz.

the class ServerPlayNetHandlerMixin method handleSlashCommand.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void handleSlashCommand(String s) {
    if (SpigotConfig.logCommands) {
        LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s);
    }
    CraftPlayer player = this.getPlayer();
    PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s, new LazyPlayerSet(this.minecraftServer));
    this.server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    try {
        minecraftServer.getCommandManager().handleCommand(((CraftPlayer) event.getPlayer()).getHandle().getCommandSource(), event.getMessage());
    } catch (CommandException ex) {
        player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command");
        java.util.logging.Logger.getLogger(ServerPlayNetHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) ServerPlayNetHandler(net.minecraft.network.play.ServerPlayNetHandler) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) LazyPlayerSet(org.bukkit.craftbukkit.v.util.LazyPlayerSet) CommandException(net.minecraft.command.CommandException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with CraftPlayer

use of org.bukkit.craftbukkit.v.entity.CraftPlayer in project Arclight by IzzelAliz.

the class EndGatewayTileEntityMixin method arclight$portal.

// @formatter:on
@Inject(method = "teleportEntity", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleportKeepLoaded(DDD)V"))
public void arclight$portal(Entity entityIn, CallbackInfo ci) {
    if (entityIn instanceof ServerPlayerEntity) {
        CraftPlayer player = ((ServerPlayerEntityBridge) entityIn).bridge$getBukkitEntity();
        Location location = new Location(((WorldBridge) world).bridge$getWorld(), pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D);
        location.setPitch(player.getLocation().getPitch());
        location.setYaw(player.getLocation().getYaw());
        PlayerTeleportEvent event = new PlayerTeleportEvent(player, player.getLocation(), location, PlayerTeleportEvent.TeleportCause.END_GATEWAY);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            ci.cancel();
            return;
        }
        ((ServerPlayNetHandlerBridge) (((ServerPlayerEntity) entityIn)).connection).bridge$teleport(event.getTo());
        // CraftBukkit - call at end of method
        this.isCoolingDown();
        ci.cancel();
    }
}
Also used : ServerPlayNetHandlerBridge(io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Location(org.bukkit.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with CraftPlayer

use of org.bukkit.craftbukkit.v.entity.CraftPlayer in project Arclight by IzzelAliz.

the class EntityTeleportEventDispatcher method onTeleport.

@SubscribeEvent(receiveCanceled = true)
public void onTeleport(EnderTeleportEvent event) {
    if (!(event.getEntity() instanceof EndermanEntity)) {
        if (event.getEntity() instanceof ServerPlayerEntity) {
            CraftPlayer player = ((ServerPlayerEntityBridge) event.getEntity()).bridge$getBukkitEntity();
            PlayerTeleportEvent bukkitEvent = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()), PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        } else {
            CraftEntity entity = ((EntityBridge) event.getEntity()).bridge$getBukkitEntity();
            EntityTeleportEvent bukkitEvent = new EntityTeleportEvent(entity, entity.getLocation(), new Location(entity.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()));
            Bukkit.getPluginManager().callEvent(bukkitEvent);
            event.setCanceled(bukkitEvent.isCancelled());
            event.setTargetX(bukkitEvent.getTo().getX());
            event.setTargetY(bukkitEvent.getTo().getY());
            event.setTargetZ(bukkitEvent.getTo().getZ());
        }
    }
}
Also used : EndermanEntity(net.minecraft.entity.monster.EndermanEntity) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) CraftEntity(org.bukkit.craftbukkit.v.entity.CraftEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Location(org.bukkit.Location) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

CraftPlayer (org.bukkit.craftbukkit.v.entity.CraftPlayer)5 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 Location (org.bukkit.Location)2 PlayerTeleportEvent (org.bukkit.event.player.PlayerTeleportEvent)2 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 ServerPlayNetHandlerBridge (io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge)1 File (java.io.File)1 CommandException (net.minecraft.command.CommandException)1 EndermanEntity (net.minecraft.entity.monster.EndermanEntity)1 ServerPlayNetHandler (net.minecraft.network.play.ServerPlayNetHandler)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 CraftEntity (org.bukkit.craftbukkit.v.entity.CraftEntity)1 LazyPlayerSet (org.bukkit.craftbukkit.v.util.LazyPlayerSet)1 EntityTeleportEvent (org.bukkit.event.entity.EntityTeleportEvent)1 PlayerCommandPreprocessEvent (org.bukkit.event.player.PlayerCommandPreprocessEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1