More advanced selection of position to put the Button
Thorinwasher opened this issue · 5 comments
Should have these priorities when selecting sign positions:
- Use the position of already existing button
- Use the position closest to head height (y=2) and closest in the z axis
I believe that this applies to control surfaces more broadly.
In the near future, addons are slated to add multiple users of control surfaces; the button is just one added natively.
For each control surface candidate as detailed in a .gate file, SG-core should assign it a desirability.
When a new portal is created, addons should request space from the control surfaces (and a priority for their request).
SG should then allocate space depending on the priority of the requests.
Off hand, this will probably be something like this (lower priorities are more important -- if there is a tie, pick one randomly)
SIGN=0
BUTTON=1
LEVER=3
REDSTONE_INPUT=3
LECTERN_INPUT=2
REDSTONE_LAMP_DISPLAY=4
This system might look like this:
void onPortalCreateEvent(StargateCreateEvent event){
int priority = 10;
Material preferredMaterial = Material.LECTERN;
event.claimControlSurface(priority, preferredMaterial, (BlockVector location) -> {
return new AddonGatePosition(location);
});
Bukkit.getServer().getScheduler().scheduleTask( () -> {
if(event.getLowestAcceptedPriority() > 10){
event.getPlayer().sendMessage("[Addon] Too few control surfaces to claim 'Å' flag");
event.getPortal().removeFlag(´Å´); // Should of course be AddonPortalFlag.SOMETHING
}
})
}
Where the method in the event will be with these input parameters
void claimControlSurface(int priority, Set<Material> preferredMaterials, Function<BlockVector,GatePosition> positionConstructor)
I don't know how to process gatepositions wanting to override vanilla positions. For example the V
gate should (if we want a popup sign) want to override the sign GatePosition. But what if another addon also want to override the default gateposition, there should be a way for the addons to know whether or not they were successfull.
I don't know how to process gatepositions wanting to override vanilla positions. For example the
V
gate should (if we want a popup sign) want to override the sign GatePosition. But what if another addon also want to override the default gateposition, there should be a way for the addons to know whether or not they were successfull.
An event could help with that. Basically, have add-ons specify an identifier in the method used to override positions. Then, we call the GatePositionOverrideEvent
(or whatever) in the method which actually deals with this stuff. An add-on could then listen to the GatePositionOverrideEvent
and see if the identifier is the same as it set. The event could contain a boolean result, and a descriptive message if it failed.
While just returning true/false could work as well, an event could return a lot more information which could be useful, like alternative locations that could be used to try again.