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());
}
}
}
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;
}
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);
}
}
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;
}
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));
}
Aggregations