Coder Social home page Coder Social logo

embarker's People

Contributors

angushtlam avatar nenofite avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

embarker's Issues

Town center to replace commands

To set up Embarker on a new world, the op places a block when represents town center. That whole chunk becomes claimed under no one's name, so only ops can modify it. Perhaps level it off with cobblestone or some structure so it's nicely accessible.

Players can interact with the town center block to see their current number of staked chunks, the price of the next chunk, and to trade emeralds for a chunk token. While holding this token, the chunk borders are highlighted. When they use the token, they claim that chunk.

Due to differences per-player in chunk prices, chunk tokens are bound to a player. If the owning player drops it, the token gets destroyed and they get their emeralds back (or it turns into that many emeralds on the ground).

Clean up and standardize cache, DB, and models

Right now, the caching code is hard to follow and buggy. There's also some strange irregularities in the model classes (eg. what's the difference between creating a StakedChunk vs. finding one, setting the owner, then saving?) The encapsulation is such that the user of the model still needs to understand details of the model in DB, such as when to create a model, find then update a model, or delete a model--rather than only focusing on the state they are trying to persist.

I propose the following pattern, which will make working with models easier to reason about and hopefully we can eliminate some bugs/toil.

The model class has:

  • no public constructor (instead use get, detailed below)
  • save() which performs any updates to the model (such as setting the last updated timestamp) then calls the manager's save(model)
  • clear() which takes place of delete. To delete a model, clear then save it.
  • setters and getters for each non-key field

...and a nested Manager class (nested so it has access to the private constructor) which extends CachedModel, and has:

  • get(key...) which retrieves from cache, else from DB, else constructs a model with that key
  • private save(model) which is called by the model's save and includes the actual SQL to persist to cache and DB

Then in Globals we keep an instance of each model's manager class.

For example, the model class for StakedChunk would have:

public class StakedChunk {

    private StakedChunk(int coordX, int coordZ, String worldName, String ownerUniqueId, Timestamp firstStaked, Timestamp lastUpdated, Manager manager) { ... }
   
    public static class Manager extends CachedModel<StakedChunk> {

        public StakedChunk get(int coordX, int coordZ, String worldName) {...}

        private void save(StakedChunk stakedChunk) {...}
    }

    public void save() {...}

    public void clear() {...}

    // getters and setters for ownerUniqueId, firstStaked, lastUpdated
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.