本文整理汇总了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);
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例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)
);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例10: getTarget
import nova.core.network.NetworkTarget.Side; //导入依赖的package包/类
@Override
public Side getTarget() {
return target;
}
示例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;
}
示例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;
}
示例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;
}