Skip to main content
ALPHA    This is new software undergoing tests! Thank you for your patience.

Candidate: James janes Presented by: Conrad Ho conrad Assessed by: Tim Golden tjguk

Python (2023) ~ Grade 4 (Intermediate)

mineral statistic and trade system in minecraft

this is a project allow you to statistic how many mineral (e.g. iron, diamond, gold, coal) have been collected on website, and players can also buy or trade them on website by their money in minecraft, so it is also a market system.

Attached files
Filename (click to download) Size Uploaded by
1.png 316.8 KB janes
Markdown code
![1.png](/media/assessment/f0674379/2023-03-22/07-43-50/1.png "1.png")
2.png 311.0 KB janes
Markdown code
![2.png](/media/assessment/f0674379/2023-03-22/07-43-56/2.png "2.png")

Status: Submitted for assessment.


janes James ~ 22 Mar 2023 7:44 a.m.

project :an mineral economy system This is a project with mineral in mineraft, it can balance the price of different sort of mineral. while you are mining, you may need to focus on your inventory whether it is full.This system can stored your mineral into database not inventory, so you will no longer need to worry about your inventory capacity.However, you cannot mining before you sign up a bank account.More important, this is not only a storage system,it is an economy system, you can login to the website. Then you can sell your mineral to get money or take them into your inventory with a token code generated

How I imagine people would use my project? Since mining is one of the most indispensable thing for players in minecraft, they need to check their inventory capacity anytime. "how about replace the limited inventory with a bank account?","how about to make these mineral exchangeable?"but if we just exchange different mineral directly. Since some mineral is relatively rare(like exchange iron with diamond),it may unfair, In order to adjust their value, we need money.for instance, the iron cost$50 and the diamond cost$500 at the beginning.Some people may think that they are fortune so they can get more diamond. By contrast, some people may thinks that they are misfortune so they have no enthusiasm to find diamond, but they can buy diamond with their money.This project can make the mineral own its commercial value and the market supply.

the video of my project(google drive) https://drive.google.com/file/d/1FGQVogbM8C1psdL_JpVEtMhsYFIGzdo-/view?usp=share_link

1.png is my website with flask(python and html) 2.png is my plugin project (java) 1.png

2.png


janes James ~ 28 Apr 2023 2:28 p.m. (updated: 28 Apr 2023 2:29 p.m.)

sorry for late posting the code, here's all the packages/libraries I use to my project

import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
import os.path
import random
import re
import sys
from importlib import import_module
from bs4 import BeautifulSoup
import jinja2
import psutil
import time

janes James ~ 28 Apr 2023 2:33 p.m.

this is my main page's work,(I omit the database link due to the privacy)

@app.route('/')
def index():
    i = 0
    total = 0
    cpu = psutil.cpu_percent()
    mydb = mysql.connector.connect(....)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]   
    mycursor = mydb.cursor()
    for x in minerallist:
      mycursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
      minerallist[i] = mycursor.fetchall()
      minerallist[i] = str(minerallist[i])    
      minerallist[i] = minerallist[i].replace('[(', '')
      minerallist[i] = minerallist[i].replace(',)]', '')
      minerallist[i] = int(minerallist[i])    
      total = total + minerallist[i]
      i = i + 1  
    if minerallist[0] == 0:
      current1 = 50 
    else:
      current1=round(50*(1-(minerallist[0]/total)),2)
    if minerallist[1] == 0:
      current2 = 10 
    else:
      current2=round(10*(1-(minerallist[1]/total)),2)
    if minerallist[2] == 0:
      current3 = 500 
    else:      
      current3=round(500*(1-(minerallist[2]/total)),2)
    if minerallist[3] == 0:
      current4 = 40 
    else:      
      current4=round(40*(1-(minerallist[3]/total)),2)
    if minerallist[4] == 0:
      current5 = 60 
    else:      
      current5=round(60*(1-(minerallist[4]/total)),2)
    if minerallist[5] == 0:
      current6 = 200 
    else:      
      current6=round(200*(1-(minerallist[5]/total)),2)
    if minerallist[6] == 0:
      current7 = 600 
    else:         
      current7=round(600*(1-(minerallist[6]/total)),2)
    return render_template("index.html",variable=minerallist[0],variable2=minerallist[1],variable3=minerallist[2],variable4=minerallist[3],
    variable5=minerallist[4],variable6=minerallist[5],variable7=minerallist[6],current1=current1,current2=current2,current3=current3
    ,current4=current4,current5=current5,current6=current6,current7=current7,cpu=cpu)

janes James ~ 28 Apr 2023 2:37 p.m. (updated: 28 Apr 2023 2:37 p.m.)

my current work is to use javascript to reload one data(cpu usage) without refreshed the entire pages. I stuck in this step....

javascript code

 <script>
setInterval(function() {
   $("#cpu").load(self);
}, 2000);
</script>

python code

cpu = psutil.cpu_percent()
return render_template("index.html",cpu=cpu)

html code

<div id='cpu'><h4 style="color:white;font-size:200%;">{{ cpu }}</h4></div>

janes James ~ 30 Jun 2023 2:45 p.m. (updated: 30 Jun 2023 2:56 p.m.)

buy_item.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
from bs4 import BeautifulSoup
from flask import Markup
import jinja2
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']  
def buy_item():    
    i = 0 
    e = 0
    p = 0
    g = 0
    total = 0
    mtotal = 0
    soldtotal=0
    index=0
    fndex=0
    connection = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    moneymydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    usermydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    serverdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    fdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    moneymycursor = moneymydb.cursor()
    mycursor = connection.cursor()
    usermycursor = usermydb.cursor()
    servercursor = serverdb.cursor()
    fcursor = fdb.cursor()
    username = str(request.form['user'])
    password = str(request.form['pass'])
    print(username)
    print(password)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]
    amountlist = ["amount0","amount1", "amount2", "amount3", "amount4", "amount5", "amount6"]
    userminerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    current = [0] * 7      
    while index < 7: 
        try:
            sql= f"UPDATE usermineral SET {minerallist[index]} = {minerallist[index]} + {request.form[amountlist[index]]} WHERE username = '{username}'"
            sql2= f"UPDATE mineral SET {minerallist[index]} = {minerallist[index]} + {request.form[amountlist[index]]} WHERE id = '0'"
            index = index + 1  
            mycursor.execute(sql)  
            fcursor.execute(sql2)  
            connection.commit()
            fdb.commit()
        except mysql.connector.Error as g:
            print('Error')       
    for x in userminerallist:
        usermycursor.execute(f"SELECT {x} FROM usermineral WHERE username = '{username}'")
        userminerallist[e] = usermycursor.fetchall()
        userminerallist[e] = str(userminerallist[e])    
        userminerallist[e] = userminerallist[e].replace('[(', '')
        userminerallist[e] = userminerallist[e].replace(',)]', '')
        userminerallist[e] = int(userminerallist[e])    
        print(userminerallist[e]) 
        mtotal = mtotal + userminerallist[e]
        e = e + 1  
    for x in minerallist:
        servercursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
        minerallist[i] = servercursor.fetchall()
        minerallist[i] = str(minerallist[i])    
        minerallist[i] = minerallist[i].replace('[(', '')
        minerallist[i] = minerallist[i].replace(',)]', '')
        minerallist[i] = int(minerallist[i])    
        total = total + minerallist[i]
        i = i + 1        
    if userminerallist[0] == 0:
        current[0] = 50 
    else:
        current[0]=round(50*(1-(userminerallist[0]/total)),2)
    if userminerallist[1] == 0:
        current[1] = 10 
    else:
        current[1]=round(10*(1-(userminerallist[1]/total)),2)
    if userminerallist[2] == 0:
        current[2] = 500 
    else:      
        current[2]=round(500*(1-(userminerallist[2]/total)),2)
    if userminerallist[3] == 0:
        current[3] = 40 
    else:      
        current[3]=round(40*(1-(userminerallist[3]/total)),2)
    if userminerallist[4] == 0:
        current[4] = 60 
    else:      
        current[4]=round(60*(1-(userminerallist[4]/total)),2)
    if userminerallist[5] == 0:
        current[5] = 200 
    else:      
        current[5]=round(200*(1-(userminerallist[5]/total)),2)
    if userminerallist[6] == 0:
        current[6] = 600 
    else:      
        current[6]=round(600*(1-(userminerallist[6]/total)),2)  
    while g < 7:
        nef = request.form[amountlist[g]]
        nef = nef.replace('[(', '')
        nef = nef.replace(',)]', '')
        nef = int(nef)    
        soldtotal = soldtotal + nef*current[g]
        print("sd")
        print(soldtotal)
        g=g+1
    sql2= f"UPDATE usermineral SET money = money - {soldtotal} WHERE username = '{username}'"
    mycursor.execute(sql2)  
    connection.commit()        
    moneymycursor.execute(f"SELECT money FROM usermineral WHERE username ='{username}'")  
    money = moneymycursor.fetchall()
    money = str(money)    
    money = money.replace("[('", '')
    money = money.replace("',)]", '')  
    money = round(float(money),2)
    moneymycursor.close()
    mycursor.close()
    usermycursor.close()
    servercursor.close()
    fcursor.close()
    connection.close()
    moneymydb.close()
    usermydb.close()
    serverdb.close()
    fdb.close()
    mineraltotal = round(current[0]*userminerallist[0]+current[1]*userminerallist[1]+current[2]*userminerallist[2]+current[3]*userminerallist[3]+current[4]*userminerallist[4]+current[5]*userminerallist[5]+current[6]*userminerallist[6],2)        
    return username,password,userminerallist[0],userminerallist[1],userminerallist[2],userminerallist[3],userminerallist[4],userminerallist[5],userminerallist[6],mineraltotal,money

janes James ~ 30 Jun 2023 2:58 p.m. (updated: 30 Jun 2023 2:58 p.m.)

web.py (the main page)

from flask import Flask, render_template, redirect, url_for, request
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
import os.path
from importlib import import_module
from bs4 import BeautifulSoup
import psutil
import time
import pynvml
from s_tui.sources.rapl_power_source import RaplPowerSource
import yaml

app = Flask(__name__)

STATIC_DIR = os.path.abspath('static\css\style.css')
STATIC_DIR = os.path.abspath('static\ironignot.png')


with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    host = cfg['hostip']
    hostport = cfg['hostport']
    database= cfg['database']

a = 0
k = 0
cpu = 0
usernamevalue = {}
passwordvalue = {}
poverty1value = {}
poverty2value = {}
poverty3value = {}
poverty4value = {}
poverty5value = {}
poverty6value = {}
poverty7value = {}
totalvaluevalue = {}
moneyvalue = {}
c1value = {}
c2value = {}
c3value = {}
c4value = {}
c5value = {}
c6value = {}
c7value = {}

@app.route('/')
def index():
    i = 0
    total = 0
    tx = ", min=0.0"
    my_str = str(psutil.cpu_freq())
    my_str = my_str.split(tx,2)[0]
    intfeq = str(my_str.replace('scpufreq(current=',''))
    strfeq = str(intfeq)+"Mhz"
    cpu = str(psutil.cpu_percent())
    ramper = psutil.virtual_memory()[2]
    ram = str(round(psutil.virtual_memory()[3]/1000000000,2))+' GB'
    pynvml.nvmlInit()
    handle = pynvml.nvmlDeviceGetHandleByIndex(0)
    powerusage = str(round(int(pynvml.nvmlDeviceGetPowerUsage(handle) / 1000),2))
    source = RaplPowerSource()
    source.update()
    summary = dict(source.get_sensors_summary())
    cpu_power_total = str(sum(list(map(float, [summary[key] for key in summary.keys() if key.startswith('package')]))))
    print(cpu_power_total)
    power = f'{powerusage}W'
    mydb = mysql.connector.connect(host=ip, port=port, user="root2", password="20050118",database=database)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]   
    mycursor = mydb.cursor()
    for x in minerallist:
      mycursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
      minerallist[i] = mycursor.fetchall()
      minerallist[i] = str(minerallist[i])    
      minerallist[i] = minerallist[i].replace('[(', '')
      minerallist[i] = minerallist[i].replace(',)]', '')
      minerallist[i] = int(minerallist[i])    
      total = total + minerallist[i]
      i = i + 1  
    if minerallist[0] == 0:
      current1 = 50 
    else:
      current1=round(50*(1-(minerallist[0]/total)),2)
    if minerallist[1] == 0:
      current2 = 10 
    else:
      current2=round(10*(1-(minerallist[1]/total)),2)
    if minerallist[2] == 0:
      current3 = 500 
    else:      
      current3=round(500*(1-(minerallist[2]/total)),2)
    if minerallist[3] == 0:
      current4 = 40 
    else:      
      current4=round(40*(1-(minerallist[3]/total)),2)
    if minerallist[4] == 0:
      current5 = 60 
    else:      
      current5=round(60*(1-(minerallist[4]/total)),2)
    if minerallist[5] == 0:
      current6 = 200 
    else:      
      current6=round(200*(1-(minerallist[5]/total)),2)
    if minerallist[6] == 0:
      current7 = 600 
    else:         
      current7=round(600*(1-(minerallist[6]/total)),2)
    mydb.close
    mycursor.close
    return render_template("index.html",variable=minerallist[0],variable2=minerallist[1],variable3=minerallist[2],variable4=minerallist[3],
    variable5=minerallist[4],variable6=minerallist[5],variable7=minerallist[6],current1=current1,current2=current2,current3=current3
    ,current4=current4,current5=current5,current6=current6,current7=current7,cpu=cpu,ram=ram,ramper=ramper,feq=strfeq,intfeq=intfeq,powerusage=power
    ,power=powerusage)



@app.route('/loginpage', methods=['GET', 'POST'])
def loginpage():
    return render_template("loginpage.html",) 

@app.route('/poverty', methods=['GET', 'POST'])
def povety():
    from function.mineral_list import mineral_for_server
    from function.check_login import check_login
    from function.login_sucessful import login_sucessful
    username,password,poverty1,poverty2,poverty3,poverty4,poverty5,poverty6,poverty7,totalvalue,money = login_sucessful()
    va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
    return render_template("playerpovety.html", poverty1=poverty1,poverty2=poverty2,poverty3=poverty3,poverty4=poverty4,
    poverty5=poverty5,poverty6=poverty6,poverty7=poverty7,totalvalue=totalvalue,money=money,username=usernamevalue['username'],password=passwordvalue['username'],
    current1=c1,current2=c2,current3=c3
    ,current4=c4,current5=c5,current6=c6,current7=c7) 

@app.route('/currenthardware', methods=['GET', 'POST'])
def currenthardware():
    tx = ", min=0.0"
    my_str = str(psutil.cpu_freq())
    my_str = my_str.split(tx,2)[0]
    intfeq = str(my_str.replace('scpufreq(current=',''))
    strfeq = str(intfeq)+"Mhz"
    cpu = str(psutil.cpu_percent())
    ramper = psutil.virtual_memory()[2]
    ram = str(round(psutil.virtual_memory()[3]/1000000000,2))+' GB'
    pynvml.nvmlInit()
    handle = pynvml.nvmlDeviceGetHandleByIndex(0)
    powerusage = str(round(int(pynvml.nvmlDeviceGetPowerUsage(handle) / 1000),2))
    source = RaplPowerSource()
    source.update()
    summary = dict(source.get_sensors_summary())
    cpu_power_total = str(sum(list(map(float, [summary[key] for key in summary.keys() if key.startswith('package')]))))
    print(cpu_power_total)
    power = f'{powerusage}W'
    return render_template("hardwaremonitor.html", money=money,username=usernamevalue['username'],password =passwordvalue['username']
   ,cpu=cpu,ram=ram,ramper=ramper,feq=strfeq,intfeq=intfeq,powerusage=power
  ,power=powerusage)

@app.route('/playerpovety', methods=['GET', 'POST'])
def playerpovety():
    from function.mineral_list import mineral_for_server
    from function.check_login import check_login
    from function.login_sucessful import login_sucessful
    status = check_login()
    if status == 1:
      username,password,poverty1,poverty2,poverty3,poverty4,poverty5,poverty6,poverty7,totalvalue,money = login_sucessful()
      va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
      usernamevalue['username'] = username
      passwordvalue['username'] = password
      poverty1value['username'] = poverty1
      poverty2value['username'] = poverty2
      poverty3value['username'] = poverty3
      poverty4value['username'] = poverty4
      poverty5value['username'] = poverty5
      poverty6value['username'] = poverty6
      poverty7value['username'] = poverty7
      totalvaluevalue['username'] = totalvalue
      moneyvalue['username'] = money
      c1value['username'] = c1
      c2value['username'] = c2
      c3value['username'] = c3
      c4value['username'] = c4
      c5value['username'] = c5
      c6value['username'] = c6
      c7value['username'] = c7
      return render_template("playerpovety.html", poverty1=poverty1,poverty2=poverty2,poverty3=poverty3,poverty4=poverty4,
      poverty5=poverty5,poverty6=poverty6,poverty7=poverty7,totalvalue=totalvalue,money=money,username=usernamevalue['username'],password=passwordvalue['username'],
      current1=c1,current2=c2,current3=c3
      ,current4=c4,current5=c5,current6=c6,current7=c7) 
    else: 
      va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
      return render_template("index.html",variable=va1,variable2=va2,variable3=va3,variable4=va4,
            variable5=va5,variable6=va6,variable7=va7,errormsg="invaid",
            current1=c1,current2=c2,current3=c3
                  ,current4=c4,current5=c5,current6=c6,current7=c7) 

@app.route('/logined_playerpovety', methods=['GET', 'POST'])
def logined_playerpovety():
    return render_template("playerpovety.html", poverty1=poverty1value['username'],poverty2=poverty2value['username'],poverty3=poverty3value['username'],poverty4=poverty4value['username'],
    poverty5=poverty5value['username'],poverty6=poverty6value['username'],poverty7=poverty7value['username'],totalvalue=totalvaluevalue['username'],money=moneyvalue['username'],username=usernamevalue['username'],password=passwordvalue['username'],
    current1=c1value['username'],current2=c2value['username'],current3=c3value['username']
    ,current4=c4value['username'],current5=c5value['username'],current6=c6value['username'],current7=c7value['username'])   

@app.route('/shop', methods=['GET', 'POST'])
def shop():
    return render_template("shop.html")    

@app.route('/playerpovetypage', methods=['GET', 'POST'])
def playerpovetypage():
    from function.mineral_list import mineral_for_server
    from function.buy_item import buy_item   
    username,password,poverty, poverty2, poverty3,poverty4,poverty5,poverty6,poverty7,totalvalue,money = buy_item()
    va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
    return render_template("playerpovety.html", username=username,password=password,poverty1=poverty,poverty2=poverty2,poverty3=poverty3,poverty4=poverty4,
    poverty5=poverty5,poverty6=poverty6,poverty7=poverty7,totalvalue=totalvalue,money=money,current1=c1,current2=c2,current3=c3
    ,current4=c4,current5=c5,current6=c6,current7=c7)  


@app.route("/money", methods=['GET', 'POST'])
def money():
    from function.mineral_list import mineral_for_server
    if 'sell' in request.form:
      from function.sell_item import sell_item   
      username,password,poverty, poverty2, poverty3,poverty4,poverty5,poverty6,poverty7,totalvalue,money = sell_item()
      va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
      return render_template("playerpovety.html", password=password,poverty1=poverty,poverty2=poverty2,poverty3=poverty3,poverty4=poverty4,
      poverty5=poverty5,poverty6=poverty6,poverty7=poverty7,totalvalue=totalvalue,money=money,username=username,current1=c1,current2=c2,current3=c3
      ,current4=c4,current5=c5,current6=c6,current7=c7)   
    if 'take' in request.form:
      from function.take_item import take_item   
      token = take_item()
      return render_template("tokenpage.html", token=token)     
    if 'buy' in request.form:
      from function.buy_item import buy_item   
      username,password,poverty, poverty2, poverty3,poverty4,poverty5,poverty6,poverty7,totalvalue,money = buy_item()
      va1, va2, va3, va4, va5, va6, va7, c1, c2, c3, c4, c5, c6,c7 = mineral_for_server()
      return render_template("playerpovety.html", username=username,password=password,poverty1=poverty,poverty2=poverty2,poverty3=poverty3,poverty4=poverty4,
      poverty5=poverty5,poverty6=poverty6,poverty7=poverty7,totalvalue=totalvalue,money=money,current1=c1,current2=c2,current3=c3
      ,current4=c4,current5=c5,current6=c6,current7=c7)



if __name__=='__main__':
 app.run(debug=True,host=host,port=hostport)

janes James ~ 30 Jun 2023 2:59 p.m.

check_login.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def check_login():
    status = 0
    mydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    username = str(request.form['username'])
    password = str(request.form['password'])
    mycursor = mydb.cursor()
    mycursor.execute(f"SELECT iron FROM usermineral WHERE username ='{username}' and password='{password}'")
    value = mycursor.fetchall()
    strvalue = str(value)
    print(value)
    mydb.close
    mycursor.close
    if strvalue == "[]":
      return status
    else:  
      status = 1
      return status

janes James ~ 30 Jun 2023 3 p.m.

login_sucessful.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
import jinja2
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def login_sucessful():
    i = 0
    e = 0
    total = 0
    mtotal = 0
    status = 0
    mydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    moneymydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    username = str(request.form['username'])
    password = str(request.form['password'])
    print(username,password)
    limitusername = username
    mycursor = mydb.cursor()
    moneymycursor = moneymydb.cursor()
    for x in minerallist:
      mycursor.execute(f"SELECT {x} FROM usermineral WHERE username ='{username}' and password='{password}'")
      minerallist[i] = mycursor.fetchall()
      minerallist[i] = str(minerallist[i])    
      minerallist[i] = minerallist[i].replace('[(', '')
      minerallist[i] = minerallist[i].replace(',)]', '')
      minerallist[i] = int(minerallist[i])    
      total = total + minerallist[i]
      i = i + 1        
    moneymycursor.execute(f"SELECT money FROM usermineral WHERE username ='{username}'")  
    money = moneymycursor.fetchall()
    money = str(money)    
    print(money)
    money = money.replace("[('", '')
    money = money.replace("',)]", '')  
    money = round(float(money),2)
    money = str(money) 
    if minerallist[0] == 0:
      current1 = 50 
    else:
      current1=round(50*(1-(minerallist[0]/total)),2)
    if minerallist[1] == 0:
      current2 = 10 
    else:
      current2=round(10*(1-(minerallist[1]/total)),2)
    if minerallist[2] == 0:
      current3 = 500 
    else:      
      current3=round(500*(1-(minerallist[2]/total)),2)
    if minerallist[3] == 0:
      current4 = 40 
    else:      
      current4=round(40*(1-(minerallist[3]/total)),2)
    if minerallist[4] == 0:
      current5 = 60   
    else:      
      current5=round(60*(1-(minerallist[4]/total)),2)
    if minerallist[5] == 0:
      current6 = 200 
    else:      
      current6=round(200*(1-(minerallist[5]/total)),2)
    if minerallist[6] == 0:
      current7 = 600 
    else:      
      current7=round(600*(1-(minerallist[6]/total)),2)  
    mydb.close
    moneymydb.close
    mycursor.close
    moneymycursor.close
    mineraltotal = round(current1*minerallist[0]+current2*minerallist[1]+current3*minerallist[2]+current4*minerallist[3]+current5*minerallist[4]+current6*minerallist[5]+current7*minerallist[6],2)  
    return limitusername,password,minerallist[0],minerallist[1],minerallist[2],minerallist[3],minerallist[4],minerallist[5],minerallist[6],mineraltotal,money

janes James ~ 30 Jun 2023 3:01 p.m.

mineral_list.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def mineral_for_server():
    f = 0
    total = 0
    mydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)  
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    mycursor = mydb.cursor()
    for x in minerallist:
        mycursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
        minerallist[f] = mycursor.fetchall()
        minerallist[f] = str(minerallist[f])    
        minerallist[f] = minerallist[f].replace('[(', '')
        minerallist[f] = minerallist[f].replace(',)]', '')
        minerallist[f] = int(minerallist[f])    
        total = total + minerallist[f]
        f = f + 1  
    if minerallist[0] == 0:
        current1 = 50 
    else:
        current1=round(50*(1-(minerallist[0]/total)),2)
    if minerallist[1] == 0:
        current2 = 10 
    else:
        current2=round(10*(1-(minerallist[1])/total),2)
    if minerallist[2] == 0:
        current3 = 500 
    else:      
        current3=round(500*(1-(minerallist[2]/total)),2)
    if minerallist[3] == 0:
        current4 = 40 
    else:      
        current4=round(40*(1-(minerallist[3]/total)),2)
    if minerallist[4] == 0:
        current5 = 60   
    else:      
        current5=round(60*(1-(minerallist[4]/total)),2)
    if minerallist[5] == 0:
        current6 = 200 
    else:      
        current6=round(200*(1-(minerallist[5]/total)),2)
    if minerallist[6] == 0:
        current7 = 600 
    else:      
        current7=round(600*(1-(minerallist[6]/total)),2) 
    mydb.close
    mycursor.close
    return minerallist[0], minerallist[1] ,minerallist[2] ,minerallist[3] ,minerallist[4] ,minerallist[5], minerallist[6],current1,current2,current3,current4,current5,current6,current7
    #return render_template("index.html",variable=minerallist[0],variable2=minerallist[1],variable3=minerallist[2],variable4=minerallist[3],
    #variable5=minerallist[4],variable6=minerallist[5],variable7=minerallist[6],current1=current1,current2=current2,current3=current3
    #,current4=current4,current5=current5,current6=current6,current7=current7,errormsg="invaid")   

janes James ~ 30 Jun 2023 3:01 p.m.

sell_item.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
from bs4 import BeautifulSoup
from flask import Markup
import jinja2
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def sell_item():    
    i = 0 
    e = 0
    p = 0
    g = 0
    total = 0
    mtotal = 0
    soldtotal=0
    index=0
    fndex =0
    connection = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    moneymydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    usermydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    serverdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    fdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    cdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    fcursor = fdb.cursor()
    moneymycursor = moneymydb.cursor()
    mycursor = connection.cursor()
    usermycursor = usermydb.cursor()
    servercursor = serverdb.cursor()
    ccursor = cdb.cursor()
    username = str(request.form['user'])
    password = str(request.form['pass'])
    print(username)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]
    amountlist = ["amount0","amount1", "amount2", "amount3", "amount4", "amount5", "amount6"]
    userminerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    current = [0] * 7
    while index < 7: 
        try:
            sql= f"UPDATE usermineral SET {minerallist[index]} = {minerallist[index]} - {request.form[amountlist[index]]} WHERE username = '{username}'"
            sql2= f"UPDATE mineral SET {minerallist[index]} = {minerallist[index]} - {request.form[amountlist[index]]} WHERE id = '0'"
            index = index + 1  
            mycursor.execute(sql)  
            fcursor.execute(sql2)  
            connection.commit()
            fdb.commit()
        except mysql.connector.Error as g:
            print('Error')         
    for x in userminerallist:
        usermycursor.execute(f"SELECT {x} FROM usermineral WHERE username = '{username}'")
        userminerallist[e] = usermycursor.fetchall()
        userminerallist[e] = str(userminerallist[e])    
        userminerallist[e] = userminerallist[e].replace('[(', '')
        userminerallist[e] = userminerallist[e].replace(',)]', '')
        userminerallist[e] = int(userminerallist[e])    
        mtotal = mtotal + userminerallist[e]
        e = e + 1  
    for x in minerallist:
        servercursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
        minerallist[i] = servercursor.fetchall()
        minerallist[i] = str(minerallist[i])    
        minerallist[i] = minerallist[i].replace('[(', '')
        minerallist[i] = minerallist[i].replace(',)]', '')
        minerallist[i] = int(minerallist[i])    
        total = total + minerallist[i]
        i = i + 1        
    if userminerallist[0] == 0:
        current[0] = 50 
    else:
        current[0]=round(50*(1-(userminerallist[0]/total)),2)
    if userminerallist[1] == 0:
        current[1] = 10 
    else:
        current[1]=round(10*(1-(userminerallist[1]/total)),2)
    if userminerallist[2] == 0:
        current[2] = 500 
    else:      
        current[2]=round(500*(1-(userminerallist[2]/total)),2)
    if userminerallist[3] == 0:
        current[3] = 40 
    else:      
        current[3]=round(40*(1-(userminerallist[3]/total)),2)
    if userminerallist[4] == 0:
        current[4] = 60 
    else:      
        current[4]=round(60*(1-(userminerallist[4]/total)),2)
    if userminerallist[5] == 0:
        current[5] = 200 
    else:      
        current[5]=round(200*(1-(userminerallist[5]/total)),2)
    if userminerallist[6] == 0:
        current[6] = 600 
    else:      
        current[6]=round(600*(1-(userminerallist[6]/total)),2)  
    while g < 7:
        nef = request.form[amountlist[g]]
        nef = nef.replace('[(', '')
        nef = nef.replace(',)]', '')
        nef = int(nef)    
        soldtotal = soldtotal+ nef*current[g]
        print(soldtotal)
        g=g+1
    mineraltotal = round(current[0]*userminerallist[0]+current[1]*userminerallist[1]+current[2]*userminerallist[2]+current[3]*userminerallist[3]+current[4]*userminerallist[4]+current[5]*userminerallist[5]+current[6]*userminerallist[6],2)
    sql2= f"UPDATE usermineral SET money = money + {soldtotal} WHERE username = '{username}'"
    mycursor.execute(sql2)  
    connection.commit()
    moneymycursor.execute(f"SELECT money FROM usermineral WHERE username ='{username}'")  
    money = moneymycursor.fetchall()
    money = str(money)    
    money = money.replace("[('", '')
    money = money.replace("',)]", '') 
    money = round(float(money))
    return username,password,userminerallist[0],userminerallist[1],userminerallist[2],userminerallist[3],userminerallist[4],userminerallist[5],userminerallist[6],mineraltotal,money

janes James ~ 30 Jun 2023 3:01 p.m.

take_item.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
from bs4 import BeautifulSoup
from flask import Markup
import jinja2
import random
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def take_item():
    e = 0
    q = 0
    index=0
    token = random.randint(122233,875565)
    connection = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    usermydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    serverdb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    serverdb2 = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    mycursor = connection.cursor()
    mycursor2 = usermydb.cursor()
    mycursor3 = serverdb.cursor()
    mycursor4 = serverdb2.cursor()
    username = str(request.form['user'])
    password = str(request.form['pass'])
    print(username)
    print(password)
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]
    amountlist = ["amount0","amount1", "amount2", "amount3", "amount4", "amount5", "amount6"]
    userminerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    current = [0] * 7     
    for x in userminerallist:
        mycursor.execute(f"SELECT {x} FROM usermineral WHERE username = '{username}'")
        userminerallist[e] = mycursor.fetchall()
        userminerallist[e] = str(userminerallist[e])    
        userminerallist[e] = userminerallist[e].replace('[(', '')
        userminerallist[e] = userminerallist[e].replace(',)]', '')
        userminerallist[e] = int(userminerallist[e])    
        e = e+1
    mycursor3.execute(f"SELECT UUID FROM usermineral WHERE username = '{username}'")  
    ID = mycursor3.fetchall()
    uID = str(ID)
    print(uID)
    uID = uID.replace("[('", "")
    uID = uID.replace("',)]", "")
    for x in minerallist:
        sql2= f"UPDATE usermineral SET {x} = {x} - {request.form[amountlist[q]]} WHERE username = '{username}'"
        mycursor2.execute(sql2)  
        usermydb.commit()
        q = q+1
    sql1= "INSERT INTO takemineral (id, UUID, token, iron, coal, diamond, copper, redstone, gold, emerald) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
    params = [username,uID,token,request.form[amountlist[0]],request.form[amountlist[1]],request.form[amountlist[2]],request.form[amountlist[3]], request.form[amountlist[4]],request.form[amountlist[5]],request.form[amountlist[6]]]
    mycursor4.executemany(sql1,[params])  
    serverdb2.commit()
    mycursor.close
    mycursor2.close
    mycursor3.close
    mycursor4.close
    connection.close
    usermydb.close
    serverdb.close
    serverdb2.close

    return token

janes James ~ 30 Jun 2023 3:02 p.m.

user_mineral_list.py

from flask import Flask, render_template, redirect, url_for, request
from flask_socketio import SocketIO
import mysql.connector
from win32gui import GetWindowText, GetForegroundWindow
from threading import Lock
import os.path
import random
import re
import sys
from flask_socketio import emit
from importlib import import_module
import yaml
with open("config.yaml") as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)
    ip = cfg['SQLip']
    port = cfg['SQLport']
    database= cfg['database']
def mineral_for_user():
    i = 0
    e = 0
    total = 0
    mtotal = 0
    mydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    moneymydb = mysql.connector.connect(host=ip, port = port, user="root2", password="20050118",database=database)
    information = ["username", "password"]   
    userminerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]    
    minerallist = ["iron", "coal", "diamond", "copper", "redstone", "gold", "emerald"]  
    username = str(request.form['username'])
    password = str(request.form['password'])
    mycursor = mydb.cursor()
    moneymycursor = moneymydb.cursor()
    for x in userminerallist:
        mycursor.execute(f"SELECT {x} FROM usermineral WHERE username ='{username}' and password='{password}'")
        userminerallist[e] = mycursor.fetchall()
        userminerallist[e] = str(userminerallist[e])    
        userminerallist[e] = userminerallist[e].replace('[(', '')
        userminerallist[e] = userminerallist[e].replace(',)]', '')
        userminerallist[e] = int(userminerallist[e])    
        mtotal = mtotal + userminerallist[e]
        e = e + 1  
    for x in minerallist:
        mycursor.execute(f"SELECT {x} FROM mineral WHERE id ='0'")
        minerallist[i] = mycursor.fetchall()
        minerallist[i] = str(minerallist[i])    
        minerallist[i] = minerallist[i].replace('[(', '')
        minerallist[i] = minerallist[i].replace(',)]', '')
        minerallist[i] = int(minerallist[i])    
        total = total + minerallist[i]
        i = i + 1        
    moneymycursor.execute(f"SELECT money FROM usermineral WHERE username ='{username}'")  
    money = moneymycursor.fetchall()
    money = str(money)    
    money = money.replace("[('", '')
    money = money.replace("',)]", '')  
    if minerallist[0] == 0:
        current1 = 50 
    else:
        current1=round(50*(1-(minerallist[0]/total)),2)
    if minerallist[1] == 0:
        current2 = 10 
    else:
        current2=round(10*(1-(minerallist[1]/total)),2)
    if minerallist[2] == 0:
        current3 = 500 
    else:      
        current3=round(500*(1-(minerallist[2]/total)),2)
    if minerallist[3] == 0:
        current4 = 40 
    else:      
        current4=round(40*(1-(minerallist[3]/total)),2)
    if minerallist[4] == 0:
        current5 = 60   
    else:      
        current5=round(60*(1-(minerallist[4]/total)),2)
    if minerallist[5] == 0:
        current6 = 200 
    else:      
        current6=round(200*(1-(minerallist[5]/total)),2)
    if minerallist[6] == 0:
        current7 = 600 
    else:      
        current7=round(600*(1-(minerallist[6]/total)),2)  
    mycursor.close
    moneymycursor.close
    mydb.close
    moneymydb.close    
    mineraltotal = round(current1*userminerallist[0]+current2*userminerallist[1]+current3*userminerallist[2]+current4*userminerallist[3]+current5*userminerallist[4]+current6*userminerallist[5]+current7*userminerallist[6],2)  

janes James ~ 30 Jun 2023 3:02 p.m.

atable.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
<table class="center">
    <tr>
      <th><h4 style="color:black;font-size:200%;">礦物類型</h4></th>
      <th><img src="static\ironignot.png" style="width:160px;height:120px;"></th>
      <th><img src="static\coal.png" style="width:160px;height:120px;"></th>
      <th><img src="static\diamond.png" style="width:160px;height:120px;"></th>
      <th><img src="static\copper.png" style="width:160px;height:120px;"></th>
      <th><img src="static\redstone.png" style="width:160px;height:120px;"></th>
      <th><img src="static\gold.png" style="width:160px;height:120px;"></th>
      <th><img src="static\emerald.png" style="width:160px;height:120px;"></th>
    </tr>
    <tr>
      <td><h4 style="color:black;font-size:200%;">開采數量</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable2 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable3 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable4 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable5 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable6 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable7 }}</h4><center></td>
      </tr>    
    <tr>
      <td><center><h4 style="color:black;font-size:200%;">目前物價</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current1}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current2}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current3}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current4}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current5}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current6}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current7}}</h4></td>
    </tr>
  </table>
</body>
</html>

janes James ~ 30 Jun 2023 3:02 p.m.

background.html

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-image: url('backgrond.png');
  background-repeat: no-repeat;
  background-attachment: fixed; 
  background-size: 100% 100%;
}
</style>
</head>
</html>

janes James ~ 30 Jun 2023 3:03 p.m.

frameset.html

<!DOCTYPE html>


<html>
    <body>
    <h3 style="font-size:50%"><center>{{names}}</h3>  
    <iframe style="position:absolute;left:0%;top:0%"height="35%" width="100%" src="{{imgframe}}"></iframe>   
    <iframe style="position:absolute;left:0%;top:35%" height="70%" width="20%" src="{{frame2}}"></iframe>
    <iframe style="position:absolute;left:20%;top:35%"height="70%" width="80%"  name="index2_frame" src="{{index2_frame}}"></iframe>
</body>
</html>

janes James ~ 30 Jun 2023 3:03 p.m.

hardwaremonitor.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
<script>
setInterval(function() {
$('#cpu').load(' #cpu')},2000)
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='buy_sell_take_button.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='horizontalbar.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
<ul>
  <form method="POST" action="/logined_playerpovety">  
  <li><a href="{{ url_for('logined_playerpovety') }}" >MY POVERTY</a></li>
  </form>
  <form method="POST" action="/currenthardware">
  <li><a href="{{ url_for('currenthardware') }}" >CURRENT SERVER HARDWARE</a></li>
  </form>
  </ul>
<div id='cpu'>  
<form method="POST" action="/currenthardware">  
<center><h6 style="color:white;width:1560px;height:60px;font-size:500%;">CURRENT SERVER HARDWARE CONSUMPTION</h6>  
<table class="center" style="width:1200px">
    <tr>
      <table style="background-color:white;height:100px;width:15%;position:absolute;left:10%">
      <tr>
        <th><h4 style="color:black;font-size:180%;height:15%">CPU usage</h4></th>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:200%;">{{ cpu }}%</h4></th>
      </tr>
      <tr>
        <th><progress style="accent-color:yellow;height:15px;width:60px" value="{{ cpu }}" max="100"> {{ cpu }}% </progress></th>
      </tr>
    </table>
    <table style="background-color:white;width:15%;position:absolute;left:32%">
      <tr>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:180%;height:15%">RAM usage</h4></th>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:200%;">{{ ram }}</h4></th>
      </tr>
      <tr>
        <th><progress style="accent-color:greenyellow;height:15px;width:60px" value="{{ ramper }}" max="100"> {{ cpu }}% </progress></th>
      </tr>
    </table>
    <table style="background-color:white;width:15%;position:absolute;right:32%">
      <tr>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:180%;height:15%">CPU feq</h4></th>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:200%;">{{ feq }}</h4></th>
      </tr>
      <tr>
        <th><progress style="accent-color:black;height:15px;width:60px" value="{{ intfeq }}" max="5000"> {{ feq }}% </progress></th>
      </tr>
    </table>
    <table style="background-color:white;width:15%;position:absolute;right:10%">
      <tr>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:180%;height:15%">powerusage</h4></th>
      </tr>
      <tr>
        <th><h4 style="color:black;font-size:200%;">{{ powerusage }}</h4></th>
      </tr>
      <tr>
        <th><progress style="accent-color:black;height:15px;width:60px" value="{{ power }}" max="1000"> {{ powerusage }} </progress></th>
      </tr>
    <textarea id="w3review" name="user" rows="4" cols="50" hidden>{{username}}</textarea>
    <textarea id="w3review" name="pass" rows="4" cols="50" hidden>{{password}}</textarea>  
  </form>  
</div>  
  </table>
</body>
</html>

janes James ~ 30 Jun 2023 3:03 p.m.

index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='buy_sell_take_button.css') }}"> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
setInterval(function() {
  $('#cpu').load(' #cpu')},2000)
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<div id='cpu'>
<body>
  <form action="/loginpage" method="post">
  <a href="{{ url_for('loginpage') }}" class="button button3 " style="color:white;width:300px;height:50px;font-size:200%;">LOGIN_PAGE</a>
  </form>
  <center><h6 style="color:white;width:660px;height:60px;font-size:500%;">MINED AMOUNT & PRICES</h6>
  <div id='refresh-section'>  
  <table class="center" style="width:1200px">
    <tr>
      <th><center><h4 style="color:black;font-size:100%;">OLE TYPE</h4></th>
      <th><img src="static\ironignot.png" style="width:110px;height:90px;"></th>
      <th><img src="static\coal.png" style="width:110px;height:90px;"></th>
      <th><img src="static\diamond.png" style="width:110px;height:90px;"></th>
      <th><img src="static\copper.png" style="width:110px;height:90px;"></th>
      <th><img src="static\redstone.png" style="width:110px;height:90px;"></th>
      <th><img src="static\gold.png" style="width:110px;height:90px;"></th>
      <th><img src="static\emerald.png" style="width:110px;height:90px;"></th>
    </tr>
    <tr>
      <td><center><h4 style="color:black;font-size:100%;">MINED AMOUNT</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable2 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable3 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable4 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable5 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable6 }}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{ variable7 }}</h4><center></td>
      </tr>    
    <tr>
      <td><center><h4 style="color:black;font-size:100%;">THE OLE PRICE</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current1}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current2}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current3}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current4}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current5}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current6}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current7}}</h4></td>
    </tr>
  </table>
</div>
<div id="cpu">
  <center><table>
  </table>
  </tr>
</table>
  </div>
<br>




<h4 style="color:red;font-size:200%;">{{errormsg}}</h4>
{% if error %}
  <p class="error"><strong>Error:</strong> {{ error }}
{% endif %}
</body>
</html>

janes James ~ 30 Jun 2023 3:04 p.m.

loginpage.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<script>
  //window.setTimeout( function() {
   // window.location.reload();
 // }, 3000);
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='buy_sell_take_button.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
<center><form action="/playerpovety" method="post">
  <br><br><br><br><br><br><br><br>   
<label style="color:white;width:260px;height:60px;font-size:300%;">username:</label>  
<input type="text" style="color:black;width:660px;height:60px;font-size:500%;" name="username" value=""><br><br>
<label style="color:white;width:260px;height:60px;font-size:300%;">password:</label>  
<input type="password" style="color:black;width:660px;height:60px;font-size:500%;" name="password" value=""><br><br>
<input class="button button3 " type="submit" value="Login">
</form>
</body>
</html>

janes James ~ 30 Jun 2023 3:04 p.m.

playerpovety.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
setInterval(function() {
  $('#cpu2').load(' #cpu2')},2000)
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='buy_sell_take_button.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='horizontalbar.css') }}">

<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
  <ul>
    <form method="POST" action="/logined_playerpovety">  
    <li><a href="{{ url_for('logined_playerpovety') }}" >MY POVERTY</a></li>
    </form>
    <form method="POST" action="/currenthardware">
    <li><a href="{{ url_for('currenthardware') }}" >CURRENT SERVER HARDWARE</a></li>
    </form>
    </ul>

<form action="/money" method="POST">
<center><h6 style="color:white;width:960px;height:60px;font-size:500%;">{{username}}'S POVERTY</h6>  
<center><h6 style="color:white;width:1660px;height:60px;font-size:500%;">POVERTY'S TOTAL AMOUNT: {{totalvalue}} MONEY: {{money}}</h6>  


<table class="center" style="width:1200px">
    <tr>
      <th><center><h4 style="color:black;font-size:100%;">OLE TYPE</h4></th>
      <th><img src="static\ironignot.png" style="width:120px;height:100px;"></th>
      <th><img src="static\coal.png" style="width:120px;height:100px;"></th>
      <th><img src="static\diamond.png" style="width:120px;height:100px;"></th>
      <th><img src="static\copper.png" style="width:120px;height:100px;"></th>
      <th><img src="static\redstone.png" style="width:120px;height:100px;"></th>
      <th><img src="static\gold.png" style="width:120px;height:100px;"></th>
      <th><img src="static\emerald.png" style="width:120px;height:100px;"></th>
    </tr>
    <tr>
    <div id="cpu2">
    <td><center><h4 style="color:black;font-size:100%;">MINED AMOUNT</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty1 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty2 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty3 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty4 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty5 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty6 }}</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty7 }}</h4></td>
    </div>
    </tr>
    <textarea name="username" id="username" rows="4" cols="50" hidden>{{username}}</textarea>
    <textarea name="password" id="password" rows="4" cols="50" hidden>{{password}}</textarea> 
    <tr>
      <td><center><h4 style="color:black;font-size:100%;">THE OLE PRICE</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current1}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current2}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current3}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current4}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current5}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current6}}</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current7}}</h4></td>

      </tr>
    </form>    

  <tr>
    <td><center><h4 style="color:black;font-size:100%;">SELL AMOUNT</h4></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount0" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount1" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount2" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount3" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount4" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount5" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount6" value="0"><center></td> 
    </tr>
    <tr>
      <td colspan="8"><center><input type="submit" class="button button1" value="sell" name="sell"><input type="submit" class="button button2"value="take" name="take"><input type="submit" class="button button3" value="buy" name="buy"></td>
      </tr>


  </table>
    </tr>
    <textarea id="w3review" name="user" rows="4" cols="50" hidden>{{username}}</textarea>
    <textarea id="w3review" name="pass" rows="4" cols="50" hidden>{{password}}</textarea>  
  </table>
</form>  

</body>
</html>

janes James ~ 30 Jun 2023 3:04 p.m.

shop.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<script>
  //window.setTimeout( function() {
   // window.location.reload();
 // }, 3000);
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='buy_sell_take_button.css') }}">
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='horizontalbar.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
<ul>
<form method="POST" action="/playerpovetypage">  
<li><a href="{{ url_for('playerpovetypage') }}" >銀行戶口狀況</a></li>
</form>
<form method="POST" action="/shop">
<li><a href="{{ url_for('shop') }}" >商店</a></li>
</form>
</ul>
<form method="POST" action="/money">
<center><h6 style="color:white;width:960px;height:60px;font-size:500%;">閣下{{username}}的總資產</h6>  
<center><h6 style="color:white;width:1660px;height:60px;font-size:500%;">資產總值: {{totalvalue}} 錢: {{money}}</h6>  
<table class="center" style="width:1200px">
    <tr>
      <th><center><h4 style="color:black;font-size:100%;">礦物類型</h4></th>
      <th><img src="static\ironignot.png" style="width:120px;height:100px;"></th>
      <th><img src="static\coal.png" style="width:120px;height:100px;"></th>
      <th><img src="static\diamond.png" style="width:120px;height:100px;"></th>
      <th><img src="static\copper.png" style="width:120px;height:100px;"></th>
      <th><img src="static\redstone.png" style="width:120px;height:100px;"></th>
      <th><img src="static\gold.png" style="width:120px;height:100px;"></th>
      <th><img src="static\emerald.png" style="width:120px;height:100px;"></th>
    </tr>
    <tr>
    <td><center><h4 style="color:black;font-size:100%;">開采數量</h4></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty1 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty2 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty3 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty4 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty5 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty6 }}</h4><center></td>
    <td><center><h4 style="color:black;font-size:200%;">{{ poverty7 }}</h4><center></td>
    </tr>
    <tr>
      <td><center><h4 style="color:black;font-size:100%;">當前物價</h4></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current1}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current2}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current3}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current4}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current5}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current6}}</h4><center></td>
      <td><center><h4 style="color:black;font-size:200%;">{{current7}}</h4><center></td>
      </tr>
  <tr>
    <td><center><h4 style="color:black;font-size:100%;">出售數量</h4></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount0" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount1" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount2" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount3" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount4" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount5" value="0"><center></td>
    <td><center><input type="text" style="color:black;width:100px;height:50px;font-size:100%;" placeholder="Username" name="amount6" value="0"><center></td> 
    </tr>
    <tr>
      <td colspan="8"><center><input type="submit" class="button button1" value="sell" name="sell"><input type="submit" class="button button2"value="take" name="take"><input type="submit" class="button button3" value="buy" name="buy"></td>
      </tr>
    <textarea id="w3review" name="user" rows="4" cols="50" hidden>{{username}}</textarea>
    <textarea id="w3review" name="pass" rows="4" cols="50" hidden>{{password}}</textarea>  
  </form>  
  </table>
</body>
</html>

janes James ~ 30 Jun 2023 3:05 p.m.

tokenpage.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<head>
<script>
  //window.setTimeout( function() {
   // window.location.reload();
 // }, 3000);
</script>
<title>Flask模板</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}

table.center {
  margin-left: auto; 
  margin-right: auto;
  background-color: white;
}
</style>
</head>
<body>
<center><h6 style="color:white;width:660px;height:60px;font-size:500%;">YOUR TOKEN IS {{token}}</h6>  
  <textarea id="w3review" name="user" rows="4" cols="50" hidden>{{already}}</textarea>
</body>
</html>

janes James ~ 30 Jun 2023 3:05 p.m. (updated: 30 Jun 2023 3:06 p.m.)

project structure


janes James ~ 30 Jun 2023 3:14 p.m.

mineral plugin

Mineralindication:

package mineralindication.mineralindication;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;

public final class Mineralindication extends JavaPlugin {

    private static Mineralindication main;
    public static Mineralindication getPlugin() {
        return new Mineralindication();
    }
    public static Mineralindication getMain(){
        return main;
    }

    public boolean contains(String cyber) {
        return false;
    }

    @Override
    public void onEnable() {
        main = this;
        Random random = new Random();
        main.saveDefaultConfig();
        System.out.println("started");
        String ip = main.getConfig().getString("SQL.ip");
        String table = main.getConfig().getString("SQL.table");
        String individual = main.getConfig().getString("SQL.individual SQL base");
        String user = main.getConfig().getString("SQL.user");
        String password = main.getConfig().getString("SQL.password");
        String DB_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://"+ ip + "/" +table;
        String DB_IND = "jdbc:mysql://"+ ip + "/" +individual;
        String DB_USERNAME = user;
        String DB_PASSWORD = password;
        Connection conn = null;
        try{
            //Register the JDBC driver
            Class.forName(DB_DRIVER);
            //Open the connection
            conn = DriverManager.
                    getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
            if(conn != null){
                System.out.println("Successfully connected.");
            }else{
                System.out.println("Failed to connect.");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        getCommand("register").setExecutor(new register());
        getCommand("token").setExecutor(new takemineral());
        Bukkit.getServer().getPluginManager().registerEvents(new mineralshow(), this);
        try(Connection connn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
            Statement stmt = connn.createStatement();
            Statement stmt2 = connn.createStatement();
            Statement stmt3 = connn.createStatement();
            Statement stmt4 = connn.createStatement();
            Statement stmt5 = connn.createStatement();
            Statement stmt6 = connn.createStatement();
        ) {
            String mineral = "CREATE TABLE mineral " +
                    "(id INTEGER not NULL, " +
                    " iron INTEGER, " +
                    " coal INTEGER, " +
                    " diamond INTEGER, " +
                    " copper INTEGER, " +
                    " redstone INTEGER, " +
                    " gold INTEGER, " +
                    " emerald INTEGER, " +
                    " PRIMARY KEY ( id ), "+
                    " CHECK(copper >= 0), " +
                    " CHECK(iron >= 0), " +
                    " CHECK(redstone >= 0), " +
                    " CHECK(coal >= 0), " +
                    " CHECK(gold >= 0), " +
                    " CHECK(diamond >= 0), " +
                    " CHECK(emerald >= 0)) ";
            String usermineral = "CREATE TABLE usermineral " +
                    "(id INTEGER not NULL, " +
                    " UUID VARCHAR(255), " +
                    " username VARCHAR(255), " +
                    " password VARCHAR(255), " +
                    " money VARCHAR(255), " +
                    " iron INTEGER, " +
                    " coal INTEGER, " +
                    " diamond INTEGER, " +
                    " copper INTEGER, " +
                    " redstone INTEGER, " +
                    " gold INTEGER, " +
                    " emerald INTEGER, " +
                    " PRIMARY KEY ( id )," +
                    " CHECK(money >= 0), " +
                    " CHECK(copper >= 0), " +
                    " CHECK(iron >= 0), " +
                    " CHECK(redstone >= 0), " +
                    " CHECK(coal >= 0), " +
                    " CHECK(gold >= 0), " +
                    " CHECK(diamond >= 0), " +
                    " CHECK(emerald >= 0), " +
                    " CHECK(money >= 0)) ";
            String takemineral = "CREATE TABLE takemineral " +
                    "(id VARCHAR(255) not NULL, " +
                    " UUID VARCHAR(255), " +
                    " token VARCHAR(255), " +
                    " iron INTEGER, " +
                    " coal INTEGER, " +
                    " diamond INTEGER, " +
                    " copper INTEGER, " +
                    " redstone INTEGER, " +
                    " gold INTEGER, " +
                    " emerald INTEGER, " +
                    " PRIMARY KEY ( id ), "+
                    " CHECK(copper >= 0), " +
                    " CHECK(iron >= 0), " +
                    " CHECK(redstone >= 0), " +
                    " CHECK(coal >= 0), " +
                    " CHECK(gold >= 0), " +
                    " CHECK(diamond >= 0), " +
                    " CHECK(emerald >= 0)) ";
            stmt.executeUpdate(mineral);
            stmt2.executeUpdate(usermineral);
            stmt3.executeUpdate(takemineral);
            System.out.println("Created table in given database...");
            String mineralrow = "INSERT INTO mineral VALUES (0, 1, 1, 1, 1, 1, 1, 1)";
            stmt4.executeUpdate(mineralrow);
            String usermineralrow = "INSERT INTO usermineral VALUES (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
            stmt5.executeUpdate(usermineralrow);
            String takerow = "INSERT INTO takemineral VALUES (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
            stmt6.executeUpdate(takerow);
        } catch (SQLException e) {
            e.printStackTrace();
        } }

    @Override
    public void onDisable() {
        // Plugin shutdown logic
    }
}

mineralshow:

package mineralindication.mineralindication;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerMoveEvent;

import java.sql.*;
import java.util.Random;
import java.util.UUID;

public class mineralshow implements Listener {
    int x= 0;
    static final String mineral = "SELECT id, iron, coal, diamond FROM mineral";


    Random random = new Random();
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Player p = event.getPlayer();
        UUID UUid = p.getUniqueId();
        String uid = String.valueOf(UUid);
        Random random = new Random();
        String ID = String.valueOf(p);
        String q1 = "CraftPlayer{name=";
        String q2 = "}";
        Block block = event.getBlock();
        String q3 = ID.replace(q1, "").replace(q2, "");
        String ip = Mineralindication.getMain().getConfig().getString("SQL.ip");
        String table = Mineralindication.getMain().getConfig().getString("SQL.table");
        String user = Mineralindication.getMain().getConfig().getString("SQL.user");
        String password = Mineralindication.getMain().getConfig().getString("SQL.password");
        String DB_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://" + ip + "/" + table;
        String DB_USERNAME = user;
        String DB_PASSWORD = password;
        try(Connection conn1 = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
            Statement stmt1 = conn1.createStatement();
            Statement stmt2 = conn1.createStatement();
            ResultSet rs = stmt2.executeQuery("SELECT * FROM usermineral");
        ) {
            while(rs.next()) {
            String PLAYERUUID = rs.getString("UUID");
            System.out.println(PLAYERUUID);
            System.out.println(UUid);
            if(uid.equals(PLAYERUUID)){
            x=1;
        }}
            if(x==0){
                p.sendMessage(ChatColor.RED + "YOU NEED TO CREATE AN BANK ACCOUNT FIRST BEFORE YOU MINING,BY USING COMMAND/register <USERNAME> <PASSWORD>");
                event.setCancelled(true);
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            if(x==1){
                if (block.getType() == Material.DIAMOND_ORE || block.getType() == Material.DEEPSLATE_DIAMOND_ORE){
                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET diamond = diamond + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET diamond = diamond + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "diamond+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }
                }
                if (block.getType() == Material.IRON_ORE || block.getType() == Material.DEEPSLATE_IRON_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET iron = iron + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET iron = iron + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "iron+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }
                if (block.getType() == Material.COAL_ORE || block.getType() == Material.DEEPSLATE_COAL_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET coal = coal + 1 WHERE id in (0)";
                        String sqldata1 = "UPDATE usermineral " +
                                "SET coal = coal + 1 WHERE UUID in ('"+UUid+"')";
                        stmt4.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "coal+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        stmt5.executeUpdate(sqldata1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }

                if (block.getType() == Material.GOLD_ORE || block.getType() == Material.DEEPSLATE_GOLD_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET gold = gold + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET gold = gold + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "gold+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }
                if (block.getType() == Material.EMERALD_ORE || block.getType() == Material.DEEPSLATE_EMERALD_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET emerald = emerald + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET emerald = emerald + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "emerald+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }
                if (block.getType() == Material.COPPER_ORE || block.getType() == Material.DEEPSLATE_COPPER_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET copper = copper + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET copper = copper + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "copper+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);
                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }
                if (block.getType() == Material.REDSTONE_ORE || block.getType() == Material.DEEPSLATE_REDSTONE_ORE){

                    try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                        Statement stmt4 = conn.createStatement();
                        Statement stmt5 = conn.createStatement()
                    ) {
                        String sqldata = "UPDATE mineral " +
                                "SET redstone = redstone + 1 WHERE id in (0)";
                        stmt4.executeUpdate(sqldata);
                        String sqldata1 = "UPDATE usermineral " +
                                "SET redstone = redstone + 1 WHERE UUID in ('"+UUid+"')";
                        stmt5.executeUpdate(sqldata1);
                        p.sendMessage(ChatColor.GREEN + "redstone+1");
                        p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
                        event.setCancelled(true);
                        block.setType(Material.AIR);

                    }
                    catch (SQLException ed) {
                        ed.printStackTrace();

                    }

                }
                x=0;
            }

        }
        catch (SQLException ed) {
            ed.printStackTrace();
        }

    }
}

playersmineral:

package mineralindication.mineralindication;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import java.util.UUID;

public class playersmineral implements Listener {

    static final String mineral = "SELECT id, iron, coal, diamond FROM mineral";

    int x= 0;
    Random random = new Random();
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Player p = event.getPlayer();
        UUID UUid = p.getUniqueId();
        Random random = new Random();
        String ID = String.valueOf(p);
        Block block = event.getBlock();
        String q1 = "CraftPlayer{name=";
        String q2 = "}";
        String q3 = ID.replace(q1, "").replace(q2, "");
        String ip = Mineralindication.getMain().getConfig().getString("SQL.ip");
        String table = Mineralindication.getMain().getConfig().getString("SQL.table");
        String user = Mineralindication.getMain().getConfig().getString("SQL.user");
        String password = Mineralindication.getMain().getConfig().getString("SQL.password");
        String DB_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://" + ip + "/" + table;
        String DB_USERNAME = user;
        String DB_PASSWORD = password;
        if (block.getType() == Material.DIAMOND_ORE || block.getType() == Material.DEEPSLATE_DIAMOND_ORE){
            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET diamond = diamond + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "diamond+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }
        }
        if (block.getType() == Material.IRON_ORE || block.getType() == Material.DEEPSLATE_IRON_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET iron = iron + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "iron+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }
        if (block.getType() == Material.COAL_ORE || block.getType() == Material.DEEPSLATE_COAL_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET coal = coal + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "coal+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }

        if (block.getType() == Material.GOLD_ORE || block.getType() == Material.DEEPSLATE_GOLD_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET gold = gold + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "gold+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }
        if (block.getType() == Material.EMERALD_ORE || block.getType() == Material.DEEPSLATE_EMERALD_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET emerald = emerald + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "emerald+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }
        if (block.getType() == Material.COPPER_ORE || block.getType() == Material.DEEPSLATE_COPPER_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET copper = copper + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "copper+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }
        if (block.getType() == Material.REDSTONE_ORE || block.getType() == Material.DEEPSLATE_REDSTONE_ORE){

            try(Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
                Statement stmt4 = conn.createStatement();
            ) {
                String sqldata = "UPDATE usermineral " +
                        "SET redstone = redstone + 1 WHERE UUID in ('"+UUid+"')";
                stmt4.executeUpdate(sqldata);
                p.sendMessage(ChatColor.GREEN + "redstone+1");
                p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
            catch (SQLException ed) {
                ed.printStackTrace();

            }

        }



















        }
    }

register:

package mineralindication.mineralindication;

import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import java.sql.*;
import java.util.Random;
import java.util.UUID;

public class register implements CommandExecutor {

    static final String mineral = "SELECT id, iron, coal, diamond FROM mineral";
    String usermineral = "SELECT id, UUID, username, password, money, copper, iron, redstone, gold, diamond, emerald FROM usermineral";
    private Mineralindication plugin;
    public register() {
        this.plugin = plugin;
    }

    int x= 0;
    Random random = new Random();
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        final Player p = (Player) sender;
        UUID id = p.getUniqueId();
        String ID = String.valueOf(p);
        String q1 = "CraftPlayer{name=";
        String q2 = "}";
        String q3 = ID.replace(q1, "").replace(q2, "");
        String ip = Mineralindication.getMain().getConfig().getString("SQL.ip");
        String table = Mineralindication.getMain().getConfig().getString("SQL.table");
        String user = Mineralindication.getMain().getConfig().getString("SQL.user");
        String password = Mineralindication.getMain().getConfig().getString("SQL.password");
        String DB_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://" + ip + "/" + table;
        String DB_USERNAME = user;
        String DB_PASSWORD = password;
        try(Connection conn1 = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
            Statement stmt1 = conn1.createStatement();
            Statement stmt2 = conn1.createStatement();
            ResultSet rs = stmt2.executeQuery("SELECT MAX(id) FROM usermineral");
        ) {
            rs.next();
            int maxid = rs.getInt(1);
            maxid+=1;
            String sqldata = "INSERT INTO usermineral VALUES ("+maxid+", '"+id+"', '"+args[0]+"', '"+args[1]+"', 0, 0, 0, 0, 0, 0, 0, 0)";
            stmt1.executeUpdate(sqldata);
            p.sendMessage(ChatColor.GREEN + "SUCESSFUL CREATED AN BANK ACCOUNT,YOUR USERNAME IS "+args[0]+" YOUR PASSWORD IS "+args[1]);
            p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
            }
        catch (SQLException ed) {
            ed.printStackTrace();
    }

        return false;}
}

takemineral:

package mineralindication.mineralindication;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.sql.*;
import java.util.UUID;

public class takemineral implements CommandExecutor{

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        final Player p = (Player) sender;
        UUID id = p.getUniqueId();
        String ID = String.valueOf(p);
        String q1 = "CraftPlayer{name=";
        String q2 = "}";
        String q3 = ID.replace(q1, "").replace(q2, "");
        String ip = Mineralindication.getMain().getConfig().getString("SQL.ip");
        String table = Mineralindication.getMain().getConfig().getString("SQL.table");
        String user = Mineralindication.getMain().getConfig().getString("SQL.user");
        String password = Mineralindication.getMain().getConfig().getString("SQL.password");
        String DB_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://" + ip + "/" + table;
        String DB_USERNAME = user;
        String DB_PASSWORD = password;
        try(Connection conn1 = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
            Statement stmt1 = conn1.createStatement();
            Statement stmt2 = conn1.createStatement();
            ResultSet rs = stmt2.executeQuery("SELECT * FROM takemineral where token = ('"+args[0]+"')");
        ) {
            rs.next();
            int iron = rs.getInt("iron");
            int coal = rs.getInt("emerald");
            int diamond = rs.getInt("diamond");
            int copper = rs.getInt("copper");
            int redstone = rs.getInt("redstone");
            int gold = rs.getInt("gold");
            int emerald = rs.getInt("emerald");
            ItemStack Itemiron = new ItemStack(Material.RAW_IRON,iron);
            ItemStack Itemcoal = new ItemStack(Material.COAL,coal);
            ItemStack Itemdiamond = new ItemStack(Material.DIAMOND,diamond);
            ItemStack Itemcopper = new ItemStack(Material.RAW_COPPER,copper);
            ItemStack Itemredstone = new ItemStack(Material.REDSTONE,redstone);
            ItemStack Itemgold = new ItemStack(Material.RAW_GOLD,gold);
            ItemStack Itememerald = new ItemStack(Material.EMERALD,emerald);
            p.getInventory().addItem(new ItemStack(Itemiron));
            p.getInventory().addItem(new ItemStack(Itemcoal));
            p.getInventory().addItem(new ItemStack(Itemdiamond));
            p.getInventory().addItem(new ItemStack(Itemcopper));
            p.getInventory().addItem(new ItemStack(Itemredstone));
            p.getInventory().addItem(new ItemStack(Itemgold));
            p.getInventory().addItem(new ItemStack(Itememerald));
            String sql = "DELETE FROM takemineral WHERE token = ('"+args[0]+"')";
            stmt1.executeUpdate(sql);
            p.sendMessage(ChatColor.GREEN + "SUCESSFUL TAKEN THE MINERAL FROM YOUR BANK ACCOUNT");
            p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 20, 1);
        }
        catch (SQLException ed) {
            ed.printStackTrace();
            p.sendMessage(ChatColor.RED + "THE TOKEN MAY NOT EXIST");
        }

        return false;}
}

janes James ~ 30 Jun 2023 3:15 p.m.

oh the whole, the most direct way to install these stuff: here is my whole work

python web (flask):

https://drive.google.com/file/d/1fa2yr-D9JwK9TfewUy3AWvCtLOb9y29Z/view?usp=sharing minecraft plugin:

https://drive.google.com/file/d/1vD7Ns2OOBZbo1OqQCrS8hxwH1QqTBGST/view?usp=sharing

Also I made a PDF to show how to set up these stuff:

https://drive.google.com/file/d/1Y8mdfvv_7-ZiQiZti-5QWyWhERbIWm23/view?usp=sharing


tjguk Tim Golden ~ 30 Jul 2023 8:41 p.m.

Hi James

Thanks for submitting your project. I can't access the GDrive links you've given for the code and setup

Would it be possible for you to upload the project to Github or some other code-sharing platform? I'm quite happy to assist you through the process of doing that if you need help


janes James ~ 09 Aug 2023 6:49 a.m. (updated: 09 Aug 2023 6:53 a.m.)

sure I uploaded it to github, you can access it through this link, since there are too many file in venv(located in flask project), so I compress it as a .rar file you need to decompress it to use the project https://github.com/siege260/a-mineral-system-of-minecraft (you may need to copy the URL and paste it in another browser, it may not work by click it directly)


Back to top