economy

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

README

Economy

The "pretty" straight forward api to create an economy for your server

To start of just use the New function

package main

import (
	"github.com/provsalt/economy"
	"github.com/provsalt/economy/provider"
)
func main() {
	e := economy.New(provider.NewSQLite("database/sqlite3.db"))
}

Balance

func main() {
    bal, ohno := e.Balance(player.UUID())
    if ohno != nil {
        panic(ohno) 
    }
    fmt.Println(bal)
}

Increase

ohno = e.Increase(player.UUID(), 500)
if ohno != nil {
	panic(ohno)
}

Decrease

ohno = e.Decrease(player.UUID(), 500)
if ohno != nil {
	panic(ohno)
}

Set

ohno = e.Set(player.UUID(), 500)
if ohno != nil {
	panic(ohno)
}

Close

ohno = e.Close()
if ohno != nil {
	panic(ohno)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEventCancelled = errors.New("event cancelled")

ErrEventCancelled is an error that is returned when the event is cancelled.

Functions

This section is empty.

Types

type Economy

type Economy struct {
	// contains filtered or unexported fields
}

Economy is a struct that contains the economy provider and the event handler.

func New

New creates a new economy instance with a provider.

func (*Economy) Balance added in v0.0.6

func (e *Economy) Balance(UUID uuid.UUID) (uint64, error)

Balance returns the balance of a player.

func (*Economy) Close added in v0.0.6

func (e *Economy) Close() error

Close closes the economy provider.

func (*Economy) Decrease added in v0.0.6

func (e *Economy) Decrease(UUID uuid.UUID, amount uint64) error

Decrease is a wrapper for Set that decreases the balance of a player.

func (*Economy) Handle added in v0.0.6

func (e *Economy) Handle(h handler.EconomyHandler)

Handle adds a new handler to handle economy changes.

func (*Economy) Increase added in v0.0.6

func (e *Economy) Increase(UUID uuid.UUID, amount uint64) error

Increase is a wrapper for Set that increases the balance of a player.

func (*Economy) Set added in v0.0.6

func (e *Economy) Set(UUID uuid.UUID, amount uint64) error

Set sets the balance of a player to a given value. You should be using this function to initialize a player's balance or Balance function will throw an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL