Coder Social home page Coder Social logo

minecraft-wrapper's People

Contributors

wlwanpan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

minecraft-wrapper's Issues

Modify command implementation to use a Command interface

Currently, commands are being defined with functions that typically end up calling processCmdToEvent(Arr). As the functions are private methods, there are no options for commands to be defined for mods and datapacks in other packages while still using this package. A fork would be required.

Consider instead of defining a function for each command, define a struct fro each command that satisfies a Command interface which is passes to a Command function, which handles stringing the command to pass to the console, and reading/handling the events associated with that command. For example:

type Command interface {
	Command() string
	Events() []events.Event
}

type ExperienceAdd struct {
	Target string
	XP int32
	XPType ExperienceType
}

func (c ExperienceAdd) Command() string {
	return fmt.Sprintf(experience add %s &d %s, c.target, c.xp, c.xpType)
}

func (c ExperienceAdd) Events() []events.Event {
	return []events.Event{
		events.ExperienceAdd,
		events.NoPlayerFound.
	}
}

func (w *Wrapper) ExecuteCommand(c Command) error {
	ev, err := w.processCmdToEvent(c.Command(), time.Second, c.Events()...)
	if err != nil {
		return err
	}
	if ev.Is(events.NoPlayerFoundEvent) {
		return ErrPlayerNotFound
	}
	return nil
}

Please note this is not a real implementation, I just adapted the ExperienceAdd function to what it could look like in this Command interface format.

If this is an idea you are open to, I would be happy to work with you on a full implementation before switching from the current function approach.

Rework game events

Rn we need to look at the implementation logparser.go to figure out what Data each event holds. Might be worth having concrete event struct per events:

type PlayerJoinedEvent struct {
  Name string
  Time time.Time
  ...
}

type PlayerSayEvent struct {
  Name string
  Message string
  ...
}

then on the receiver side:

ev := <-wpr.GameEvents()
if ev.Type == events.PlayerSayEvent {
  playerSayEv := ev.(events.PlayerSayEvent)
}

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.