2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.minecraft.internal;
15 import java.util.ArrayList;
16 import java.util.HashSet;
17 import java.util.List;
20 import org.openhab.binding.minecraft.internal.handler.MinecraftPlayerHandler;
21 import org.openhab.binding.minecraft.internal.handler.MinecraftServerHandler;
22 import org.openhab.binding.minecraft.internal.handler.MinecraftSignHandler;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link MinecraftHandlerFactory} is responsible for creating things and thing
37 * @author Mattias Markehed - Initial contribution
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.minecraft")
40 public class MinecraftHandlerFactory extends BaseThingHandlerFactory {
42 private static final Logger LOGGER = LoggerFactory.getLogger(MinecraftHandlerFactory.class);
44 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>();
47 SUPPORTED_THING_TYPES_UIDS.add(MinecraftBindingConstants.THING_TYPE_SERVER);
48 SUPPORTED_THING_TYPES_UIDS.add(MinecraftBindingConstants.THING_TYPE_PLAYER);
49 SUPPORTED_THING_TYPES_UIDS.add(MinecraftBindingConstants.THING_TYPE_SIGN);
52 private static List<MinecraftServerHandler> minecraftServers = new ArrayList<>();
55 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
56 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
60 protected ThingHandler createHandler(Thing thing) {
61 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
63 if (thingTypeUID.equals(MinecraftBindingConstants.THING_TYPE_SERVER)) {
64 MinecraftServerHandler serverHandler = new MinecraftServerHandler((Bridge) thing);
65 minecraftServers.add(serverHandler);
67 } else if (thingTypeUID.equals(MinecraftBindingConstants.THING_TYPE_PLAYER)) {
68 return new MinecraftPlayerHandler(thing);
69 } else if (thingTypeUID.equals(MinecraftBindingConstants.THING_TYPE_SIGN)) {
70 return new MinecraftSignHandler(thing);
77 protected void removeHandler(ThingHandler thingHandler) {
78 minecraftServers.remove(thingHandler);
79 super.removeHandler(thingHandler);
83 * Get all Minecraft handlers created.
85 * @return the Minecraft handlers created,
87 public static List<MinecraftServerHandler> getMinecraftServers() {
88 LOGGER.debug("getMinecraftServers {}", minecraftServers.size());
89 return new ArrayList<>(minecraftServers);