|
22 | 22 | import ch.vorburger.minecraft.storeys.events.Condition;
|
23 | 23 | import ch.vorburger.minecraft.storeys.events.ConditionService;
|
24 | 24 | import ch.vorburger.minecraft.storeys.events.LocatableInBoxCondition;
|
| 25 | +import ch.vorburger.minecraft.storeys.japi.PlayerInsideEvent; |
25 | 26 | import ch.vorburger.minecraft.storeys.japi.impl.Unregisterable;
|
26 | 27 | import ch.vorburger.minecraft.storeys.model.LocationToolAction;
|
27 | 28 | import ch.vorburger.minecraft.storeys.web.location.LocationHitBox;
|
|
51 | 52 | import org.spongepowered.api.event.EventManager;
|
52 | 53 | import org.spongepowered.api.event.Listener;
|
53 | 54 | import org.spongepowered.api.event.block.InteractBlockEvent;
|
| 55 | +import org.spongepowered.api.event.cause.Cause; |
| 56 | +import org.spongepowered.api.event.cause.EventContext; |
54 | 57 | import org.spongepowered.api.event.cause.EventContextKeys;
|
55 | 58 | import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
56 | 59 | import org.spongepowered.api.item.inventory.ItemStackSnapshot;
|
57 | 60 | import org.spongepowered.api.text.Text;
|
58 | 61 | import org.spongepowered.api.world.Location;
|
59 | 62 | import org.spongepowered.api.world.World;
|
60 | 63 |
|
61 |
| -@Singleton |
62 |
| -public class LocationToolListener { |
| 64 | +@Singleton public class LocationToolListener { |
63 | 65 | private static final Logger LOG = LoggerFactory.getLogger(LocationToolListener.class);
|
64 | 66 | private final Map<String, Pair<Location<World>, Location<World>>> playerBoxLocations = new ConcurrentHashMap<>();
|
65 | 67 | private final Map<String, Unregisterable> conditionRegistrations = new ConcurrentHashMap<>();
|
66 | 68 | private final ConditionService conditionService;
|
67 | 69 | private final ConfigurationLoader<CommentedConfigurationNode> configurationLoader;
|
68 | 70 |
|
| 71 | + private final EventContext eventContext; |
| 72 | + private EventManager eventManager; |
| 73 | + private final PluginInstance plugin; |
| 74 | + |
69 | 75 | @Inject public LocationToolListener(PluginInstance plugin, EventManager eventManager, ConditionService conditionService,
|
70 | 76 | ConfigurationLoader<CommentedConfigurationNode> loader) {
|
71 | 77 | TypeSerializerCollection.defaults().register(LocationPairSerializer.TYPE, new LocationPairSerializer());
|
72 | 78 | eventManager.registerListeners(plugin, this);
|
| 79 | + this.eventManager = eventManager; |
| 80 | + this.plugin = plugin; |
| 81 | + this.eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin.getPluginContainer()).build(); |
73 | 82 | this.conditionService = conditionService;
|
74 | 83 | configurationLoader = loader;
|
75 | 84 |
|
@@ -131,9 +140,9 @@ private void registerCondition(UUID player, String locationName, Pair<Location<W
|
131 | 140 | if (unregisterable != null) {
|
132 | 141 | unregisterable.unregister();
|
133 | 142 | }
|
134 |
| - ConditionService.ConditionServiceRegistration registration = conditionService.register(condition, |
135 |
| - // TODO properly implement full support for this old feature in the new api-jvm |
136 |
| - (Player p) -> LOG.warn("TODO inform the player that someone was inside the region {}", p)); |
| 143 | + ConditionService.ConditionServiceRegistration registration = conditionService.register(condition, (p) -> { |
| 144 | + eventManager.post(new PlayerInsideEvent(p, locationName, Cause.of(eventContext, plugin))); |
| 145 | + }); |
137 | 146 | conditionRegistrations.put(name, registration);
|
138 | 147 | }
|
139 | 148 |
|
|
0 commit comments