Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package wrapper

// Reach objective: verify minecraft version (Bedrock vs. Java and 1.XX) to not build / prevent using certain commands

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

// Could be a great spot to use the github.com/densestvoid/postoffice package.
// It was designed to be able to send and receive on channels identified by interface addresses.
// Each event type could be registered as an address
// Event is for any console resposne, error is for command processing only
func (w *Wrapper) ExecuteCommand(cmd Command) (Event, error) {
// TODO: create/get channels for each event type on the wrapper

// TODO: write the command to the console

// TODO: wait to receive on one of the event channels, and return that event

return nil, nil
}

/*
attribute
advancement
ban x
ban-ip
banlist x
bossbar
clear
clone
data (get)
datapack
debug
defaultgamemode x
deop x
difficulty x
effect
enchant
execute
experience (add,query)
fill
forceload
function
gamemode
gamerule
give x
help
kick x
kill
list x
locate
locatebiome
loot
me
msg
op
pardon
particle
playsound
publish
recipe
reload
save-all x
save-off x
save-on x
say x
schedule
scoreboard
seed
setblock
setidletimeout
setworldspawn
spawnpoint
spectate
spreadplayers
stop x
stopsound
summon
tag
team
teammsg
teleport
tell x
tellraw
time
title
tp
trigger
w
weather
whitelist
worldborder
xp
*/
135 changes: 135 additions & 0 deletions commands/java/1.15.2/gamerule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package minecraft_1_15

import (
"fmt"

wrapper "github.com/wlwanpan/minecraft-wrapper"
)

type gameRuleBoolName string

func (gr gameRuleBoolName) gameRuleName() string {
return string(gr)
}

// GameRule Names that use booleans
const (
AnnounceAdvancements gameRuleBoolName = "announceAdvancements"
CommandBlockOutput gameRuleBoolName = "commandBlockOutput"
DisableElytraMovementCheck gameRuleBoolName = "disableElytraMovementCheck"
DisableRaids gameRuleBoolName = "disableRaids"
DoDaylightCycle gameRuleBoolName = "doDaylightCycle"
DoEntityDrops gameRuleBoolName = "doEntityDrops"
DoFireTick gameRuleBoolName = "doFireTick"
DoInsomnia gameRuleBoolName = "doInsomnia"
DoImmediateRespawn gameRuleBoolName = "doImmediateRespawn"
DoLimitedCrafting gameRuleBoolName = "doLimitedCrafting"
DoMobLoot gameRuleBoolName = "doMobLoot"
DoMobSpawning gameRuleBoolName = "doMobSpawning"
DoPatrolSpawning gameRuleBoolName = "doPatrolSpawning" // new
DoTileDrops gameRuleBoolName = "doTileDrops"
DoTraderSpawning gameRuleBoolName = "doTraderSpawning" // new
DoWeatherCycle gameRuleBoolName = "doWeatherCycle"
DrowningDamage gameRuleBoolName = "drowningDamage"
FallDamage gameRuleBoolName = "fallDamage"
FireDamage gameRuleBoolName = "fireDamage"
KeepInventory gameRuleBoolName = "keepInventory"
LogAdminCommands gameRuleBoolName = "logAdminCommands"
MobGriefing gameRuleBoolName = "mobGriefing"
NaturalRegeneration gameRuleBoolName = "naturalRegeneration"
ReducedDebugInfo gameRuleBoolName = "reducedDebugInfo"
SendCommandFeedback gameRuleBoolName = "sendCommandFeedback"
ShowDeathMessages gameRuleBoolName = "showDeathMessages"
SpectatorsGenerateChunks gameRuleBoolName = "spectatorsGenerateChunks"
)

type gameRuleIntName string

func (gr gameRuleIntName) gameRuleName() string {
return string(gr)
}

// GameRule Names that use integers
const (
MaxCommandChainLength gameRuleIntName = "maxCommandChainLength"
MaxEntityCramming gameRuleIntName = "maxEntityCramming"
RandomTickSpeed gameRuleIntName = "randomTickSpeed"
SpawnRadius gameRuleIntName = "spawnRadius"
)

// GameRuleName accepts either boolean or integer name types
type GameRuleName interface {
gameRuleName() string
}

// GameRule is a command used to set various rules in game
type GameRule struct {
name GameRuleName
bVal bool
iVal int
}

func NewGameRuleGet(name GameRuleName) GameRule {
return GameRule{name: name}
}

func NewGameRuleBoolean(name GameRuleName, b bool) GameRule {
return GameRule{name: name, bVal: b}
}

func NewGameRuleInt(name GameRuleName, i int) GameRule {
return GameRule{name: name, iVal: i}
}

// Command allows the GameRule struct to be executed as a command in game
func (c GameRule) Command() string {
switch c.name.(type) {
case gameRuleBoolName:
return fmt.Sprintf("gamerule %s %t", c.name.gameRuleName(), c.bVal)
case gameRuleIntName:
return fmt.Sprintf("gamerule %s %d", c.name.gameRuleName(), c.iVal)
default:
return fmt.Sprintf("gamerule %s", c.name.gameRuleName())
}
}

func (c GameRule) Events() []wrapper.Event {
return []wrapper.Event{
&GameRuleSet{},
&GameRuleGet{},
&wrapper.IncorrectCommandArgument{},
&wrapper.InvalidBoolean{},
&wrapper.InvalidInteger{},
&wrapper.UnknownOrIncompleteCommand{},
}
}

type GameRuleSet struct {
name GameRuleName
bVal *bool
iVal *int
}

func (event *GameRuleSet) Parse(s string) bool {
if _, err := fmt.Sscanf(s, "Gamerule %s is now set to: %T", event.bVal); err != nil {
if _, err := fmt.Sscanf(s, "Gamerule %s is now set to: %d", event.iVal); err != nil {
return false
}
}
return true
}

type GameRuleGet struct {
name GameRuleName
bVal *bool
iVal *int
}

func (event *GameRuleGet) Parse(s string) bool {
if _, err := fmt.Sscanf(s, "Gamerule %s is currently set to: %T", event.bVal); err != nil {
if _, err := fmt.Sscanf(s, "Gamerule %s is currently set to: %d", event.iVal); err != nil {
return false
}
}
return true
}
133 changes: 133 additions & 0 deletions commands/java/1.15/gamerule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package minecraft_1_15_2

import (
"fmt"

wrapper "github.com/wlwanpan/minecraft-wrapper"
)

type gameRuleBoolName string

func (gr gameRuleBoolName) gameRuleName() string {
return string(gr)
}

// GameRule Names that use booleans
const (
AnnounceAdvancements gameRuleBoolName = "announceAdvancements"
CommandBlockOutput gameRuleBoolName = "commandBlockOutput"
DisableElytraMovementCheck gameRuleBoolName = "disableElytraMovementCheck"
DisableRaids gameRuleBoolName = "disableRaids"
DoDaylightCycle gameRuleBoolName = "doDaylightCycle"
DoEntityDrops gameRuleBoolName = "doEntityDrops"
DoFireTick gameRuleBoolName = "doFireTick"
DoInsomnia gameRuleBoolName = "doInsomnia" // new
DoImmediateRespawn gameRuleBoolName = "doImmediateRespawn" // new
DoLimitedCrafting gameRuleBoolName = "doLimitedCrafting"
DoMobLoot gameRuleBoolName = "doMobLoot"
DoMobSpawning gameRuleBoolName = "doMobSpawning"
DoTileDrops gameRuleBoolName = "doTileDrops"
DoWeatherCycle gameRuleBoolName = "doWeatherCycle"
DrowningDamage gameRuleBoolName = "drowningDamage" // new
FallDamage gameRuleBoolName = "fallDamage" // new
FireDamage gameRuleBoolName = "fireDamage" // new
KeepInventory gameRuleBoolName = "keepInventory"
LogAdminCommands gameRuleBoolName = "logAdminCommands"
MobGriefing gameRuleBoolName = "mobGriefing"
NaturalRegeneration gameRuleBoolName = "naturalRegeneration"
ReducedDebugInfo gameRuleBoolName = "reducedDebugInfo"
SendCommandFeedback gameRuleBoolName = "sendCommandFeedback"
ShowDeathMessages gameRuleBoolName = "showDeathMessages"
SpectatorsGenerateChunks gameRuleBoolName = "spectatorsGenerateChunks"
)

type gameRuleIntName string

func (gr gameRuleIntName) gameRuleName() string {
return string(gr)
}

// GameRule Names that use integers
const (
MaxCommandChainLength gameRuleIntName = "maxCommandChainLength"
MaxEntityCramming gameRuleIntName = "maxEntityCramming"
RandomTickSpeed gameRuleIntName = "randomTickSpeed"
SpawnRadius gameRuleIntName = "spawnRadius"
)

// GameRuleName accepts either boolean or integer name types
type GameRuleName interface {
gameRuleName() string
}

// GameRule is a command used to set various rules in game
type GameRule struct {
name GameRuleName
bVal bool
iVal int
}

func NewGameRuleGet(name GameRuleName) GameRule {
return GameRule{name: name}
}

func NewGameRuleBoolean(name GameRuleName, b bool) GameRule {
return GameRule{name: name, bVal: b}
}

func NewGameRuleInt(name GameRuleName, i int) GameRule {
return GameRule{name: name, iVal: i}
}

// Command allows the GameRule struct to be executed as a command in game
func (c GameRule) Command() string {
switch c.name.(type) {
case gameRuleBoolName:
return fmt.Sprintf("gamerule %s %t", c.name.gameRuleName(), c.bVal)
case gameRuleIntName:
return fmt.Sprintf("gamerule %s %d", c.name.gameRuleName(), c.iVal)
default:
return fmt.Sprintf("gamerule %s", c.name.gameRuleName())
}
}

func (c GameRule) Events() []wrapper.Event {
return []wrapper.Event{
&GameRuleSet{},
&GameRuleGet{},
&wrapper.IncorrectCommandArgument{},
&wrapper.InvalidBoolean{},
&wrapper.InvalidInteger{},
&wrapper.UnknownOrIncompleteCommand{},
}
}

type GameRuleSet struct {
name GameRuleName
bVal *bool
iVal *int
}

func (event *GameRuleSet) Parse(s string) bool {
if _, err := fmt.Sscanf(s, "Gamerule %s is now set to: %T", event.bVal); err != nil {
if _, err := fmt.Sscanf(s, "Gamerule %s is now set to: %d", event.iVal); err != nil {
return false
}
}
return true
}

type GameRuleGet struct {
name GameRuleName
bVal *bool
iVal *int
}

func (event *GameRuleGet) Parse(s string) bool {
if _, err := fmt.Sscanf(s, "Gamerule %s is currently set to: %T", event.bVal); err != nil {
if _, err := fmt.Sscanf(s, "Gamerule %s is currently set to: %d", event.iVal); err != nil {
return false
}
}
return true
}
Loading