當前位置: 首頁>>代碼示例>>Java>>正文


Java Side類代碼示例

本文整理匯總了Java中nova.core.network.NetworkTarget.Side的典型用法代碼示例。如果您正苦於以下問題:Java Side類的具體用法?Java Side怎麽用?Java Side使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Side類屬於nova.core.network.NetworkTarget包,在下文中一共展示了Side類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGui

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
public void testGui() {

		// Safe way of getting the fitting constraints for the layout, could also create the object yourself and spare another line.
		BorderLayout layout = new BorderLayout();
		BorderConstraints constraints = layout.constraints();
		Container container = new Container("test").setLayout(layout)
			.add(new Button("testButton1", "Test Button 1")
					.onEvent((e, button) -> {
						// TODO Still needs a cast unfortunately
						button.setActive(false);
					}, ActionEvent.class, Side.SERVER),
				constraints.of(e -> e.region = Anchor.WEST))
			.add(new Button("testButton2", "Test Button 2"), constraints.of(e -> e.region = Anchor.CENTER))
			.add(new Button("testButton3", "Test Button 3"), constraints.of(e -> e.region = Anchor.EAST));

		// Container 2 is the exact equivalent of container 1, without using any constraints. It's the more error prone way.
		Container container2 = new Container("test")
			.add(new Button("testButton1", "Test Button 1")
				.onEvent(this::onButton1Pressed, ActionEvent.class, Side.SERVER), Anchor.WEST)
			.add(new Button("testButton2", "Test Button 2"))
			.add(new Button("testButton3", "Test Button 3"), Anchor.EAST);
	}
 
開發者ID:NOVA-Team,項目名稱:NOVA-GUI,代碼行數:23,代碼來源:GuiTest.java

示例2: publish

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
@Override
public void publish(T event) {
	if (event instanceof SidedEventBus.SidedEvent) {
		SidedEventBus.SidedEvent sidedEvent = (SidedEventBus.SidedEvent) event;
		Side currentSide = Side.get();

		if (sidedEvent.getTarget().opposite().targets(currentSide)) {
			super.publish(event);
		}

		// Check if the event needs to be sent over the network.
		if (currentSide.targets(sidedEvent.getTarget())) {
			boolean send = !checkListenedBeforeSend;
			if (!send) {
				send = contains(event.getClass(), currentSide.opposite());
			}
			if (send) {
				eventProcessor.handleEvent(sidedEvent);
			}
		}
	} else {
		super.publish(event);
	}
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:25,代碼來源:SidedEventBus.java

示例3: closeGui

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
/**
 * Closes the currently open NOVA {@link Gui} on the client side, if
 * present, and returns to the in-game GUI. It will not affect any native
 * GUIs that might exist along with NOVA.
 * @throws IllegalSideException if called on the server side
 */
@Sided(Side.CLIENT)
public void closeGui() {
	Side.assertSide(Side.CLIENT);
	Optional<Gui> active = getActiveGui();
	if (active.isPresent()) {
		closeGui(active.get());
	}
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-GUI,代碼行數:15,代碼來源:GuiManager.java

示例4: getActiveGui

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
/**
 * Returns the active NOVA {@link Gui} of the supplied player on the client
 * side, if present.
 * @param player Player to check for
 * @return NOVA {@link Gui}
 */
public Optional<Gui> getActiveGui(Entity player) {
	if (Side.get().isClient()) {
		return getActiveGuiImpl();
	}
	return getActiveGuiImpl(player);
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-GUI,代碼行數:13,代碼來源:GuiManager.java

示例5: onEvent

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
public <EVENT extends ComponentEvent> O onEvent(ComponentEvent.ComponentEventListener<EVENT, O> listener, Class<EVENT> clazz, Side side) {
	if (side == Side.SERVER && !hasIdentifierRecursive()) {
		throw new GuiComponentException("Components without unique identifier can't recieve events on the server side!");
	}
	componentEventBus.add(listener, clazz, side);
	return (O) this;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-GUI,代碼行數:8,代碼來源:GuiComponent.java

示例6: initializeGUI

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
public static void initializeGUI() {
	guiFactory.register("testgui", () -> new Gui("testgui")
			.add(new Button("testbutton2", "I'm EAST")
				.setMaximumSize(Integer.MAX_VALUE, 120)

				.onEvent((event, component) -> {
					System.out.println("Test button pressed! " + Side.get());
				}, ActionEvent.class, Side.BOTH), Anchor.EAST)

			.add(new Button("testbutton3", "I'm CENTER"))
			.add(new Container("test").setLayout(new FlowLayout())
				.add(new Slot("main", 0))
				.add(new Slot("main", 0))
				.add(new Slot("main", 0))
				.add(new Slot("main", 0))
				, Anchor.SOUTH)

			.add(new Container("container").setLayout(new FlowLayout())
				.add(new Button("testbutton5", "I'm the FIRST Button and need lots of space"))
				.add(new Label("testlabel1", "I'm some label hanging around").setBackground(new Background(Color.white)))
				.add(new Button("testbutton7", "I'm THIRD"))
				.add(new Button("testbutton8", "I'm FOURTH"))
				, Anchor.NORTH)

			.onGuiEvent((event) -> {
				event.gui.addInventory("main", ((BlockSimpleTest) event.block.get()).inventory);
				System.out.println("Test GUI initialized! " + event.player.getDisplayName() + " " + event.position);
			}, BindEvent.class)

			.onGuiEvent((event) -> {
				System.out.println("Test GUI closed!");
			}, UnBindEvent.class)
	);
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Example,代碼行數:35,代碼來源:NovaGui.java

示例7: add

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
private void add(Class<?> clazz, Side side) {
	if (side == Side.NONE) {
		throw new IllegalArgumentException("Can't specify a sided event without a scope!");
	}
	Side side2 = listenedNetworkEvents.get(clazz);
	if (side2 != null) {
		if (side2 != Side.BOTH && side2 != side) {
			listenedNetworkEvents.put(clazz, Side.BOTH);
		}
	} else {
		listenedNetworkEvents.put(clazz, side);
	}
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:14,代碼來源:SidedEventBus.java

示例8: contains

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
private boolean contains(Class<?> clazz, Side side) {
	Class<?> clazz2 = clazz;
	while (true) {
		Side side2 = listenedNetworkEvents.get(clazz2);
		if (side2 == side || side2 == Side.BOTH) {
			listenedNetworkEvents.put(clazz, side2);
			return true;
		}
		if (clazz2 == Object.class) {
			break;
		}
		clazz2 = clazz2.getSuperclass();
	}
	return false;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:16,代碼來源:SidedEventBus.java

示例9: inject

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public synchronized T inject(ComponentProvider<? extends ComponentMap> provider, Class<?>[] typeArgs, Object[] args) {
	try {
		List<Component> components = provider.components().stream()
			.filter(component -> component.getClass().getAnnotationsByType(Passthrough.class).length > 0)
			.collect(Collectors.toList());

		if (components.size() > 0) {
			List<Class<? extends Component>> componentClazzes = components.stream().map(c -> c.getClass()).collect(Collectors.toList());
			Game.logger().info("{} {}", Side.get(), componentClazzes);
			if (cache.containsKey(componentClazzes))
			// Cached class
			{
				return inject(cache.get(componentClazzes).getConstructor(typeArgs).newInstance(args), provider);
			} else {
				Class<? extends T> clazz = construct(componentClazzes);
				cache.put(componentClazzes, clazz);
				return inject(clazz.getConstructor(typeArgs).newInstance(args), provider);
			}

		} else {
			// No components withPriority passthrough interfaces, we can use the
			// base class.
			return baseClazz.getConstructor(typeArgs).newInstance(args);
		}
	} catch (Exception e) {
		throw new ClassLoaderUtil.ClassLoaderException("Failed to construct wrapper class for " + baseClazz, e);
	}
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:30,代碼來源:ComponentInjector.java

示例10: getTarget

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
@Override
public Side getTarget() {
	return target;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-GUI,代碼行數:5,代碼來源:ComponentEvent.java

示例11: getTarget

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
default Side getTarget() {
	NetworkTarget target = getClass().getAnnotation(NetworkTarget.class);
	return target != null ? target.value() : Side.BOTH;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:5,代碼來源:SidedEventBus.java

示例12: SidedEventListener

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
public SidedEventListener(EventListener<E> wrappedListener, Class<E> eventClass, Side side) {
	super(wrappedListener, eventClass);
	this.side = side;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:5,代碼來源:SidedEventBus.java

示例13: getSide

import nova.core.network.NetworkTarget.Side; //導入依賴的package包/類
/**
 * Use {@link Side#get()} instead.
 *
 * @return active side
 */
public final Side getSide() {
	return isClient() ? Side.CLIENT : Side.SERVER;
}
 
開發者ID:NOVA-Team,項目名稱:NOVA-Core,代碼行數:9,代碼來源:NetworkManager.java


注:本文中的nova.core.network.NetworkTarget.Side類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。