Skip to content

Change up game rules to be more flexible and follow Sponge practices#1745

Closed
parlough wants to merge 1 commit intoSpongePowered:bleedingfrom
parlough:feature/game-rules
Closed

Change up game rules to be more flexible and follow Sponge practices#1745
parlough wants to merge 1 commit intoSpongePowered:bleedingfrom
parlough:feature/game-rules

Conversation

@parlough
Copy link
Contributor

Follows the style the rest of Sponge uses better while also providing a more flexible system.

Looking for some input on the set-up I have so far, then I will flesh out the rest of the API and write the implementation.

@Cybermaxke Any input here?

@parlough
Copy link
Contributor Author

Locally the file GameRule.java has the right name but Git seems to think the name is Gamerule.java :/

import java.util.Optional;

/**
* Someone who holds various {@link GameRule}s and the values they point to.
Copy link
Contributor

@ryantheleach ryantheleach Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone? Were you going to delegate per user gamerules to the world properties that currently controls them?

Copy link
Contributor Author

@parlough parlough Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant "Something", just in-case an implementation wants to allow gamerules to extend beyond just a WorldProperties.

@ryantheleach
Copy link
Contributor

ryantheleach commented Jan 23, 2018

If you are going to refactor GameRules I'm expecting that you are going to come up with some sort of sharing context?

e.g. nether and the_end and modded dimenson-worlds by default on sponge delegate to the overworld gamerules?

Where as Sponge worlds can share a 'multiverse'/world that contains the gamerules for a group of dimensions?

Note: My use of multiverse is just to convey concept, I am utterly aware how much of a Pain in the ass it would be to globally have support for true multiverses separating out inventory, stats, recipes. plugins etc on a Mojang based server.

I just can't help but think that the concept would be valuable, even if it only see's limited use on SpongeForge / SpongeVanilla. There isn't anything really forcing Lantern to having such limitations.

* @param <T> The value type of the game rule
*/
@CatalogedBy(GameRuleTypes.class)
public interface GameRuleType<T> extends CatalogType {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll introduce a builder for this to make it easier to create a new one.

* @param <T> The value type of the game rule
*/
@CatalogedBy(GameRules.class)
public interface GameRule<T> extends CatalogType {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create a builder for this as well.

*
* @return This type's deserializer
*/
Function<String, T> getDeserializer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not really a serializer, it’s more of a printer/parser combination, isn’t it?

@@ -334,28 +332,6 @@ default Difficulty getDifficulty() {
return getProperties().getDifficulty();
}

Copy link
Contributor

@Cybermaxke Cybermaxke Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the world also a GameRuleHolder? And then delegate all the methods to the properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will just specify in the Javadoc that most implementations delegate the methods to the properties.

* @param value The value to set the game rule to
* @param <T> The value type of the game rule
*/
<T> void setGameRule(GameRule<T> gameRule, T value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should also call the ChangeWorldGameRuleEvent, so return a boolean whether it was successful? That said, the ChangeWorldGameRuleEvent should also be refactored for the new API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I forgot to do this, thanks for reminding me. Will make these changes.

@dualspiral
Copy link
Contributor

dualspiral commented Jan 23, 2018

While I know we're breaking commands and text for API 8 without deprecations, here, I'd argue deprecations serve a purpose. Deprecations will emit a warning on compilers that use the code to point them in the right direction - while we'll really hammer the change in commands when API 8 is out, game rules and smaller, easier to deprecate systems might end up falling by the wayside. We should make sure we are in the mindset of deprecating when we can, not just using major API versions as a reason to break with no consequence.

That being said, looking at this, I suspect it's possible for both systems to coexist peacefully with no breaking changes. Do you think you could do that in time for 7.1? If so, maybe that's a route forward - a deprecation in 7.1 with the new methods, removal in 8.

@parlough
Copy link
Contributor Author

parlough commented Jan 23, 2018

@dualspiral I believe this is doable to an extent, the only problem would be for the events. I could introduce an event with a different name or package that supports the new changes while deprecating the old one.

How would you feel about that solution?

@gabizou gabizou added branch: bleeding api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) labels Aug 30, 2018
@gabizou
Copy link
Member

gabizou commented Aug 30, 2018

@dualspiral I disagree with trying to maintain deprecation policy for the bleeding branch. As we're already doing massive refactors left and right (Text has already changed, Value API is about to change, DataRegistration is partially changing due to values changing, Extent API is 100% rewritten at this point, Scheduling tasks will change as soon as we expose the client in the process, CauseStackManager is getting a rename, some major events are being redone, Inventory API changed, commands are going to be changing), I don't feel it necessary to keep something as simple as game rules deprecated for a version and then break it in a little way afterwards.

Not to mention that documentation alone for the migration from API 7 to API 8 will be somewhat extensive at that point given the PR's that were used to make all these changes, it'll be easy to show the migration via test plugin changes needed between the various pr's.

@dualspiral
Copy link
Contributor

dualspiral commented Aug 30, 2018

@gabizou With the extent of changes since, where before, it was impossible to know with clarity how much we would need to change, sure. Deprecations do serve a purpose and we should still pay mind to their use, but given how much we've changed since this was opened, I see the point.

Do bear in mind I made that comment 7 months ago, just after 7 was released. Things have changed!

@gabizou
Copy link
Member

gabizou commented Aug 30, 2018

Do bear in mind I made that comment 7 months ago, just after 7 was released. Things have changed!

Of course, just resuscitating PR's (having went through I think all the open PR's currently) and making sure their either alive, or relegated for future development/management.

@Cybermaxke
Copy link
Contributor

The game rule is already refactored in the api-8 branch, comment on the status PR #1995 if there's anything missing.

@Cybermaxke Cybermaxke closed this May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants