Search in sources :

Example 1 with CraftServer

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

the class BlockPlaceEventDispatcher method onMultiPlace.

@SubscribeEvent(receiveCanceled = true)
public void onMultiPlace(BlockEvent.EntityMultiPlaceEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof ServerPlayerEntity) {
        ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity;
        Player player = ((CraftServer) Bukkit.getServer()).getPlayer(playerEntity);
        Direction direction = ArclightCaptures.getPlaceEventDirection();
        if (direction != null) {
            Hand hand = ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND);
            List<BlockState> placedBlocks = new ArrayList<>(event.getReplacedBlockSnapshots().size());
            for (BlockSnapshot snapshot : event.getReplacedBlockSnapshots()) {
                placedBlocks.add(ArclightBlockSnapshot.fromBlockSnapshot(snapshot, true).getState());
            }
            CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().offset(direction.getOpposite()));
            ItemStack bukkitStack;
            if (hand == Hand.MAIN_HAND) {
                bukkitStack = player.getInventory().getItemInMainHand();
            } else {
                bukkitStack = player.getInventory().getItemInOffHand();
            }
            BlockPlaceEvent placeEvent = new BlockMultiPlaceEvent(placedBlocks, againstBlock, bukkitStack, player, !event.isCanceled());
            placeEvent.setCancelled(event.isCanceled());
            Bukkit.getPluginManager().callEvent(placeEvent);
            event.setCanceled(placeEvent.isCancelled() || !placeEvent.canBuild());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Player(org.bukkit.entity.Player) BlockMultiPlaceEvent(org.bukkit.event.block.BlockMultiPlaceEvent) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) ArrayList(java.util.ArrayList) ArclightBlockSnapshot(io.izzel.arclight.common.mod.util.ArclightBlockSnapshot) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftBlock(org.bukkit.craftbukkit.v.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v.CraftServer) Direction(net.minecraft.util.Direction) Hand(net.minecraft.util.Hand) BlockState(org.bukkit.block.BlockState) ItemStack(org.bukkit.inventory.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with CraftServer

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

the class ArclightHeadLoader method load.

@Override
public GameProfile load(String key) {
    GameProfile[] profiles = { null };
    ProfileLookupCallback gameProfileLookup = new ProfileLookupCallback() {

        @Override
        public void onProfileLookupSucceeded(GameProfile gp) {
            profiles[0] = gp;
        }

        @Override
        public void onProfileLookupFailed(GameProfile gp, Exception excptn) {
            profiles[0] = gp;
        }
    };
    ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository().findProfilesByNames(new String[] { key }, Agent.MINECRAFT, gameProfileLookup);
    GameProfile profile = profiles[0];
    if (profile == null) {
        UUID uuid = PlayerEntity.getUUID(new GameProfile(null, key));
        profile = new GameProfile(uuid, key);
        gameProfileLookup.onProfileLookupSucceeded(profile);
    } else {
        Property property = Iterables.getFirst((profile.getProperties()).get("textures"), null);
        if (property == null) {
            profile = SkullTileEntity.sessionService.fillProfileProperties(profile, true);
        }
    }
    return profile;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ProfileLookupCallback(com.mojang.authlib.ProfileLookupCallback) CraftServer(org.bukkit.craftbukkit.v.CraftServer) UUID(java.util.UUID) Property(com.mojang.authlib.properties.Property)

Example 3 with CraftServer

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

the class CraftServerMixin method syncCommands.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite(remap = false)
private void syncCommands() {
    Commands dispatcher = this.console.getCommandManager();
    for (Map.Entry<String, Command> entry : this.commandMap.getKnownCommands().entrySet()) {
        String label = entry.getKey();
        Command command = entry.getValue();
        new BukkitCommandWrapper((CraftServer) (Object) this, command).register(dispatcher.getDispatcher(), label);
    }
}
Also used : Command(org.bukkit.command.Command) BukkitCommandWrapper(org.bukkit.craftbukkit.v.command.BukkitCommandWrapper) Commands(net.minecraft.command.Commands) CraftServer(org.bukkit.craftbukkit.v.CraftServer) Map(java.util.Map) SimpleHelpMap(org.bukkit.craftbukkit.v.help.SimpleHelpMap) CraftCommandMap(org.bukkit.craftbukkit.v.command.CraftCommandMap) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with CraftServer

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

the class ServerLoginNetHandlerMixin method arclight$preLogin.

private void arclight$preLogin() throws Exception {
    String playerName = loginGameProfile.getName();
    InetAddress address = ((InetSocketAddress) networkManager.getRemoteAddress()).getAddress();
    UUID uniqueId = loginGameProfile.getId();
    CraftServer craftServer = (CraftServer) Bukkit.getServer();
    AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId);
    craftServer.getPluginManager().callEvent(asyncEvent);
    if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
        PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
        if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
            event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
        }
        class SyncPreLogin extends Waitable<PlayerPreLoginEvent.Result> {

            @Override
            protected PlayerPreLoginEvent.Result evaluate() {
                craftServer.getPluginManager().callEvent(event);
                return event.getResult();
            }
        }
        Waitable<PlayerPreLoginEvent.Result> waitable = new SyncPreLogin();
        ((MinecraftServerBridge) server).bridge$queuedProcess(waitable);
        if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
            disconnect(event.getKickMessage());
            return;
        }
    } else if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
        disconnect(asyncEvent.getKickMessage());
        return;
    }
    LOGGER.info("UUID of player {} is {}", loginGameProfile.getName(), loginGameProfile.getId());
    currentLoginState = ServerLoginNetHandler.State.NEGOTIATING;
}
Also used : Waitable(org.bukkit.craftbukkit.v.util.Waitable) InetSocketAddress(java.net.InetSocketAddress) AsyncPlayerPreLoginEvent(org.bukkit.event.player.AsyncPlayerPreLoginEvent) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v.CraftServer) AsyncPlayerPreLoginEvent(org.bukkit.event.player.AsyncPlayerPreLoginEvent) PlayerPreLoginEvent(org.bukkit.event.player.PlayerPreLoginEvent) InetAddress(java.net.InetAddress) MinecraftServerBridge(io.izzel.arclight.common.bridge.server.MinecraftServerBridge)

Example 5 with CraftServer

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

the class CommandBlockLogicMixin method arclight$serverCommand.

// @formatter:on
@Redirect(method = "trigger", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/Commands;handleCommand(Lnet/minecraft/command/CommandSource;Ljava/lang/String;)I"))
private int arclight$serverCommand(Commands commands, CommandSource sender, String command) {
    Joiner joiner = Joiner.on(" ");
    if (command.startsWith("/")) {
        command = command.substring(1);
    }
    ServerCommandEvent event = new ServerCommandEvent(((CommandSourceBridge) sender).bridge$getBukkitSender(), command);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return 0;
    }
    command = event.getCommand();
    String[] args = command.split(" ");
    String cmd = args[0];
    if (cmd.startsWith("minecraft:"))
        cmd = cmd.substring("minecraft:".length());
    if (cmd.startsWith("bukkit:"))
        cmd = cmd.substring("bukkit:".length());
    if (cmd.equalsIgnoreCase("stop") || cmd.equalsIgnoreCase("kick") || cmd.equalsIgnoreCase("op") || cmd.equalsIgnoreCase("deop") || cmd.equalsIgnoreCase("ban") || cmd.equalsIgnoreCase("ban-ip") || cmd.equalsIgnoreCase("pardon") || cmd.equalsIgnoreCase("pardon-ip") || cmd.equalsIgnoreCase("reload")) {
        return 0;
    }
    if (((CraftServer) Bukkit.getServer()).getCommandBlockOverride(args[0])) {
        args[0] = "minecraft:" + args[0];
    }
    return commands.handleCommand(sender, joiner.join(args));
}
Also used : Joiner(com.google.common.base.Joiner) ServerCommandEvent(org.bukkit.event.server.ServerCommandEvent) CraftServer(org.bukkit.craftbukkit.v.CraftServer) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

CraftServer (org.bukkit.craftbukkit.v.CraftServer)9 UUID (java.util.UUID)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 CraftBlock (org.bukkit.craftbukkit.v.block.CraftBlock)3 Player (org.bukkit.entity.Player)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 MinecraftServerBridge (io.izzel.arclight.common.bridge.server.MinecraftServerBridge)2 Entity (net.minecraft.entity.Entity)2 Direction (net.minecraft.util.Direction)2 Hand (net.minecraft.util.Hand)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 BlockPlaceEvent (org.bukkit.event.block.BlockPlaceEvent)2 ItemStack (org.bukkit.inventory.ItemStack)2 Joiner (com.google.common.base.Joiner)1 GameProfile (com.mojang.authlib.GameProfile)1 ProfileLookupCallback (com.mojang.authlib.ProfileLookupCallback)1 Property (com.mojang.authlib.properties.Property)1 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)1 ArclightBlockSnapshot (io.izzel.arclight.common.mod.util.ArclightBlockSnapshot)1 File (java.io.File)1