Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added core functions for steemplots addon #1

Merged
merged 32 commits into from May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0aa6076
Added custom json operations function
Abwasserrohr May 20, 2019
9b9436f
Changed a comment.
Abwasserrohr May 20, 2019
dfafdf1
Added getAccountHistory
Abwasserrohr May 20, 2019
83aa0fa
Added default tags for comments
Abwasserrohr May 20, 2019
c2d7ced
Added createComment function
Abwasserrohr May 20, 2019
d0c6532
Fixed a mistake
Abwasserrohr May 20, 2019
2e2d11b
objects can't be just null within the function definition in Skript
Abwasserrohr May 20, 2019
4b5e781
Added getSteemContent
Abwasserrohr May 20, 2019
8fb6cc6
Importing SteemJ is necessary...
Abwasserrohr May 20, 2019
b3a464e
Added getDummy function
Abwasserrohr May 20, 2019
8ac70b7
Removed not needed line
Abwasserrohr May 20, 2019
d7ff857
Added getRandomUUID function
Abwasserrohr May 20, 2019
e528198
Changed comment
Abwasserrohr May 20, 2019
91821bd
Added claimRewards function
Abwasserrohr May 20, 2019
d1624b8
Added getSteemResponse function
Abwasserrohr May 20, 2019
97ca618
Added getHeadBlockNumber function
Abwasserrohr May 21, 2019
bbc59b2
Added decompressBase64 function
Abwasserrohr May 21, 2019
a1c8390
Added compressBase64 function
Abwasserrohr May 21, 2019
5b635b9
Changed variable names
Abwasserrohr May 21, 2019
7435fd2
Added Base64ToBytes function
Abwasserrohr May 21, 2019
b6afd4b
Added BytesToBase64 function
Abwasserrohr May 21, 2019
dc3be49
Added yaml data storage functions
Abwasserrohr May 22, 2019
5ce300b
Added configurable storage format
Abwasserrohr May 22, 2019
f557780
Added functions for saving and getting data for users
Abwasserrohr May 22, 2019
883041e
Added getSyncedAccount function
Abwasserrohr May 22, 2019
e0c5198
Added setSyncedAccount function
Abwasserrohr May 22, 2019
82dad5e
Added getAccount function
Abwasserrohr May 22, 2019
ab68d84
getServerAccountName should return the server account
Abwasserrohr May 22, 2019
e41757a
Added validateSyncedSteemAccountUUID function
Abwasserrohr May 22, 2019
a883b08
Added validateSyncedSteemAccountAuths function
Abwasserrohr May 22, 2019
5962b89
Added chat prefix to configuration
Abwasserrohr May 22, 2019
ff44e4b
Added steemconnect addon
Abwasserrohr May 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions STEEM.CRAFT/_lib/getDummy.sk
@@ -0,0 +1,16 @@
#
# ==============
# getDummy.sk
# ==============
# getDummy.sk is part of the STEEM.CRAFT library.
# ==============

#
# > Function - getDummy
# > Actions:
# > Returns a block as a dummy for metadata storage.
function getDummy() :: block:
if {dummyblock} is not a block:
add all worlds to {_worlds::*}
set {dummyblock} to block at location at 0.0, 0.0, 0.0 in {_worlds::1}
return {dummyblock}
15 changes: 15 additions & 0 deletions STEEM.CRAFT/_lib/getRandomUUID.sk
@@ -0,0 +1,15 @@
#
# ==============
# getRandomUUID.sk
# ==============
# getRandomUUID.sk is part of the STEEM.CRAFT library.
# ==============

import:
java.util.UUID

#
# > Function - getRandomUUID:
# > Returns a random UUID as text.
function getRandomUUID() :: text:
return "%UUID.randomUUID()%"
100 changes: 100 additions & 0 deletions STEEM.CRAFT/addons/steemconnect.sk
@@ -0,0 +1,100 @@
#
# ==============
# steemconnect.sk
# ==============
# steemconnect.sk is part of the STEEM.CRAFT addons.
# ==============
# > This addon allows players to easily connect to the server
# > using SteemConnect links. SteemConnect is a trusted place
# > to sign transactions to the Steem Blockchain.
# ==============

import:
net.md_5.bungee.api.chat.TextComponent
net.md_5.bungee.api.chat.ComponentBuilder
net.md_5.bungee.api.chat.ClickEvent
net.md_5.bungee.api.chat.HoverEvent
net.md_5.bungee.api.chat.HoverEvent$Action as HoverEventAction
net.md_5.bungee.api.chat.ClickEvent$Action as ClickEventAction

#
# > Command - /steemconnect <steem account>
# > Gives the player links to connect the account to the server.
# > Also validates if the account is synced correctly and stores
# > the steem name once the verification is done.
command /steemconnect [<text>]:
trigger:
#
# > If the player is already synced with this account, there
# > is no need to repeat the process.
if getSyncedAccount(player) is arg-1:
message "%getChatPrefix()% You're already connected to this account."
stop

#
# > If the player has not set any argument, send the usage.
if arg-1 is not set:
message "%getChatPrefix()% Usage: /steemconnect <steem account>"
stop

#
# > If the account name doesn't exist, tell the player
# > about this and add a usage for support.
else if getAccount(arg-1) is not set:
message "%getChatPrefix()% Steem account %arg-1% not found."
message "%getChatPrefix()% Usage: /steemconnect <steem account>"
stop

#
# > If the account doesn't have the uuid saved in the profile, send a link
# > which sets the player's uuid to the profile of the steem account.
if validateSyncedSteemAccountUUID(player,arg-1) is false:

#
# > Create a new ComponentBuilder to make clickable and hoverable text.
set {_builder} to new ComponentBuilder(new TextComponent(getChatPrefix()))
set {_uuid} to uuid of player
set {_updateprofileurl} to "https://app.steemconnect.com/sign/profile-update?minecraftuuid=%{_uuid}%"
set {_msg} to new TextComponent("Click here to sync your Steem account.")
{_msg}.setClickEvent(new ClickEvent(ClickEventAction.OPEN_URL!,{_updateprofileurl}))
{_msg}.setHoverEvent(new HoverEvent(HoverEventAction.SHOW_TEXT!,new ComponentBuilder("Click here to open.").create()))
{_builder}.append({_msg})

#
# > This is a temporary fix until ComponentBuilder works again.
execute console command "/tellraw %player% ["""",{""text"":""%getChatPrefix()% ""},{""text"":""Click here to sync your Steem account."",""clickEvent"":{""action"":""open_url"",""value"":""%{_updateprofileurl}%""}}]"

#
# > The function currently doesn't work correctly, use backup command above.
# > player.sendMessage({_builder}.create())
message "%getChatPrefix()% Once you're done: /steemconnect %arg-1%"
stop

#
# > If the account doesn't have the server account authorized, send a link
# > which authorizes the server account.
if validateSyncedSteemAccountAuths(player,arg-1) is false:

#
# > Create a new ComponentBuilder to make clickable and hoverable text.
set {_builder} to new ComponentBuilder(new TextComponent(getChatPrefix()))
set {_updateprofileurl} to "https://app.steemconnect.com/authorize/@%getServerAccountName()%"
set {_msg} to new TextComponent("Click here to authorize the server.")
{_msg}.setClickEvent(new ClickEvent(ClickEventAction.OPEN_URL!,{_updateprofileurl}))
{_msg}.setHoverEvent(new HoverEvent(HoverEventAction.SHOW_TEXT!,new ComponentBuilder("Click here to open.").create()))
{_builder}.append({_msg})

#
# > This is a temporary fix until ComponentBuilder works again.
execute console command "/tellraw %player% ["""",{""text"":""%getChatPrefix()% ""},{""text"":""Click here to authorize the server."",""clickEvent"":{""action"":""open_url"",""value"":""%{_updateprofileurl}%""}}]"

#
# > The function currently doesn't work correctly, use backup command above.
# > player.sendMessage({_builder}.create())
message "%getChatPrefix()% Once you're done: /steemconnect %arg-1%"
stop

#
# > If the event has not been stopped yet, the account is synced.
setSyncedAccount(player,arg-1)
message "%getChatPrefix()% Your account has been successfully connected."
33 changes: 31 additions & 2 deletions STEEM.CRAFT/config.sk
Expand Up @@ -14,9 +14,16 @@ options:
privatepostingkey: "<place your private posting key here>"
serveraccountname: "<place your steem account name here>"
appname: "STEEM.CRAFT/0.1"
defaultAppTags: ["steemcraft"]
DefaultBeneficiaryAccount: "skyroad"
DefaultBeneficiaryWeight: 250

#
# > Currently supported formats: yaml.
storagetype: "yaml"
#
# > Chat prefix that is shown in STEEM.CRAFT addons.
chatprefix: "&7[&6&lSTEEM.CRAFT&7] &8&l>>&7"

#
# > Please do not change these functions, since they are used to share the data between
# > other Skript files on the server. Be sure to never leak your private posting key!
Expand All @@ -33,7 +40,7 @@ function getPrivatePostingKey() :: text:
# > Actions:
# > Returns the server account name.
function getServerAccountName() :: text:
return {@privatepostingkey}
return {@serveraccountname}

#
# > Function - getAppName
Expand All @@ -42,6 +49,14 @@ function getServerAccountName() :: text:
function getAppName() :: text:
return {@appname}

#
# > Function - getDefaultAppTags
# > Actions:
# > Returns the default app tags which should be used if
# > no other app tag is defined.
function getDefaultAppTags() :: object:
return {@defaultAppTags}

#
# > Function - getDefaultBeneficiaryAccount
# > Actions:
Expand All @@ -55,3 +70,17 @@ function getDefaultBeneficiaryAccount() :: text:
# > Returns the default beneficary weight.
function getDefaultBeneficiaryWeight() :: number:
return {@DefaultBeneficiaryWeight}

#
# > Function - getStorageType
# > Actions:
# > Returns the current storage type.
function getStorageType() :: text:
return {@storagetype}

#
# > Function - getChatPrefix
# > Actions:
# > Returns the chat prefix.
function getChatPrefix() :: text:
return {@chatprefix}
99 changes: 99 additions & 0 deletions STEEM.CRAFT/core/functions/claimRewards.sk
@@ -0,0 +1,99 @@
#
# ==============
# claimRewards.sk
# ==============
# claimRewards.sk is part of the STEEM.CRAFT core functions.
# ==============

import:
java.util.ArrayList
java.util.HashMap
org.apache.commons.lang3.tuple.ImmutablePair
eu.bittrade.libs.steemj.SteemJ
eu.bittrade.libs.steemj.base.models.AccountName
eu.bittrade.libs.steemj.configuration.SteemJConfig
eu.bittrade.libs.steemj.enums.PrivateKeyType

#
# > Function - claimRewards:
# > Claims the rewards for the specified Steem wallet.
# > Parameters:
# > <text>Steem wallet name
# > <text>random tx uuid (only used for local feedback)
function claimRewards(account:text,txuuid:text):
#
# > Addons can wait for the process until done. Set the response to "wait",
# > they should then wait until it is done.
set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "wait"
#
# > Only prepare one claim transaction at once.
while {steemsk::txclaim} is set:
wait 1 tick
#
# > Use a HashMap to call the threaded asyncClaimRewards function.
set {_tx} to new HashMap()
{_tx}.put("account",{_account})
{_tx}.put("txuuid","%{_txuuid}%")
set {steemsk::txclaim} to {_tx}
#
# > The response by the Steem node is not instantly, this would halt
# > the main game, and needs to be in a thread.
$ thread
#
# > Since this is a thread, only global variables will work here.
# > This is why not the local variable above has been used here.
asyncClaimRewards({steemsk::txclaim})

#
# > Function - asyncClaimRewards:
# > Claims the rewards for the specified Steem wallet.
# > Meant to only be used by the claimRewards function.
# > Parameters:
# > <HashMap>(text)account,(text)txuuid (only used for local feedback)
function asyncClaimRewards(tx:object):
#
# > Once this function has been called, remove the global variable
# > which has been used to call this function to allow more being
# > processed.
delete {steemsk::txclaim}

#
# > Get the txuuid and acccount (as string) out of the HashMap.
set {_txuuid} to {_tx}.get("txuuid")
set {_account} to {_tx}.get("account")

#
# > To claim the rewards, SteemJ is needed.
set {_steemj} to new SteemJ()
set {_config} to SteemJConfig.getInstance()

#
# > Convert the string to a usable AccountName.
set {_account} to new AccountName({_account})

#
# > SteemJ.claimRewards() uses the default account. Set it here.
{_config}.setDefaultAccount({_account})

#
# > Add the private posting keys of the user to the PrivateKeyStorage to allow
# > broadcasting the claimRewards transaction.
set {_privatekeys} to new ArrayList()
{_privatekeys}.add(new ImmutablePair(PrivateKeyType.POSTING!, getPrivatePostingKey()))
{_config}.getPrivateKeyStorage().addAccount({_account},{_privatekeys})
delete {_privatekeys}

#
# > To work, the maximum expiration date offset has to decreased from default.
{_config}.setMaximumExpirationDateOffset(400000)

#
# > claimRewards have a "try" prefix to prevent errors being logged to console.
try {_steemj}.claimRewards()

#
# > If a error has been produced by the claimRewards, it can be handeled by addons.
if last java error is set:
set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java error
else:
set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "done"
19 changes: 19 additions & 0 deletions STEEM.CRAFT/core/functions/compression/Base64ToBytes.sk
@@ -0,0 +1,19 @@
#
# ==============
# Base64ToBytes.sk
# ==============
# Base64ToBytes.sk is part of the STEEM.CRAFT core functions.
# ==============

import:
org.apache.commons.codec.binary.Base64

#
# > Function - Base64ToBytes:
# > Decodes base64 into bytes
# > Parameters:
# > <text>byte64 string
# > Returns:
# > <text>bytes
function Base64ToBytes(base64:text) :: object:
return Base64.decodeBase64({_base64})
19 changes: 19 additions & 0 deletions STEEM.CRAFT/core/functions/compression/BytesToBase64.sk
@@ -0,0 +1,19 @@
#
# ==============
# BytesToBase64.sk
# ==============
# BytesToBase64.sk is part of the STEEM.CRAFT core functions.
# ==============

import:
org.apache.commons.codec.binary.Base64

#
# > Function - BytesToBase64:
# > Encodes bytes into a base64 string.
# > Parameters:
# > <text>bytes
# > Returns:
# > <text>byte64 string
function BytesToBase64(bytes:object) :: text:
return Base64.encodeBase64String({_bytes})
27 changes: 27 additions & 0 deletions STEEM.CRAFT/core/functions/compression/compressBase64.sk
@@ -0,0 +1,27 @@
#
# ==============
# compressBase64.sk
# ==============
# compressBase64.sk is part of the STEEM.CRAFT core functions.
# ==============

import:
org.apache.commons.codec.binary.Base64
org.apache.commons.io.IOUtils
java.io.ByteArrayOutputStream
java.util.zip.GZIPOutputStream

#
# > Function - compressBase64:
# > Compresses a string into a compressed base64 string.
# > Parameters:
# > <text>regular text
# > Returns:
# > <text>compressed base64 string
function compressBase64(text:text) :: text:
set {_baos} to new ByteArrayOutputStream()
set {_gzos} to new GZIPOutputStream({_baos})
{_gzos}.write({_text}.getBytes("Cp1047"))
IOUtils.closeQuietly({_gzos})
set {_bytes} to {_baos}.toByteArray()
return Base64.encodeBase64String({_bytes})
26 changes: 26 additions & 0 deletions STEEM.CRAFT/core/functions/compression/decompressBase64.sk
@@ -0,0 +1,26 @@
#
# ==============
# decompressBase64.sk
# ==============
# decompressBase64.sk is part of the STEEM.CRAFT core functions.
# ==============

import:
org.apache.commons.codec.binary.Base64
org.apache.commons.io.IOUtils
java.io.ByteArrayInputStream
java.util.zip.GZIPInputStream

#
# > Function - decompressBase64:
# > Decompresses a compressed base64 string back into a normal string.
# > Parameters:
# > <text>compressed text
# > Returns:
# > <text>decompressed text
function decompressBase64(text:text) :: text:
set {_bytes} to Base64.decodeBase64({_text})
set {_gzis} to new GZIPInputStream(new ByteArrayInputStream({_bytes}))
set {_result} to IOUtils.toString({_gzis},"Cp1047")
IOUtils.closeQuietly({_gzis})
return {_result}