Skip to content

Commit cdecc83

Browse files
committed
WebEditItem v1
1 parent 802cc22 commit cdecc83

14 files changed

+362
-0
lines changed

WebItemEditor/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
WebItemEditor
2+
-------------
3+
4+
A web-page item editor for Minecraft using Denizen.
5+
6+
![](screenshot.png)
7+
8+
Note that this does not edit every detail of an item. Just the display name, lore, enchantments, and the data hides toggle.
9+
10+
### Installation
11+
12+
- Add `scripts/web_item_helper.dsc` into your scripts folder.
13+
- If you don't already have a Denizen webserver:
14+
- Add `scripts/webserver.dsc` and configure it.
15+
- Copy the files under `webroot/`. Consider editing the `index.htm` file and replacing the `favicon.ico`
16+
- If you intend to make this tool accessible outside of localhost, configure a reverse proxy like Nginx or Apache.
17+
- If you do already have a Denizen webserver:
18+
- just copy out the `data` script named `webtools_config` from `webserver.dsc` and configure that.
19+
- Copy over the webroot contents, excluding `favicon.ico` and `index.htm`
20+
21+
### Usage
22+
23+
- Give permission `dscript.webedititem` to those who should have access
24+
- Just hold an item and do `/webedititem`
25+
- Click the link it gives you
26+
- Edit item details on the page however you wish (do not leave the minecraft server while you're editing)
27+
- Click `Send Back To Game`
28+
- It will open an inventory in-game, which you can pull the item from
29+
30+
### Licenses
31+
32+
- Made using the [Minecraft Regular font from OnlineWebFonts.com](https://www.onlinewebfonts.com/download/6ab539c6fc2b21ff0b149b3d06d7f97c), licensed as CC-BY 3.0
33+
- Made using the [Darkly Bootstrap Theme](https://bootswatch.com/darkly/) by Thomas Park, which was released under the [MIT License](https://github.com/thomaspark/bootswatch/blob/7fcf822114e71cfb3b89e98afb58055d21f5e240/LICENSE).
34+
- All other content is the work of Alex 'mcmonkey' Goodwin, [licensed under the same license as the rest of this repo](https://github.com/mcmonkeyprojects/DenizenSampleScripts/blob/master/LICENSE.txt).

WebItemEditor/screenshot.png

51.2 KB
Loading
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
staff_item_edit_command:
3+
type: command
4+
debug: false
5+
name: webedititem
6+
usage: /webedititem
7+
description: Lets you open a webpage to edit the item in your hand.
8+
permission: dscript.webedititem
9+
aliases:
10+
- itemwebedit
11+
- webitemedit
12+
- edititemweb
13+
script:
14+
- if <player.item_in_hand.material.name> == air:
15+
- narrate "<&[error]>Cannot edit AIR. Please hold an item to edit."
16+
- stop
17+
- define new_session <util.random_uuid>
18+
- definemap session_data:
19+
item: <player.item_in_hand>
20+
- flag player web_edit_item_session.<[new_session]>:<player.item_in_hand> expire:1d
21+
- define url <script[webtools_config].parsed_key[url_base]>web_edit_item?user=<player.uuid>&session=<[new_session]>
22+
- narrate "<&[base]>Please open <element[<&[emphasis]>this link].on_click[<[url]>].type[open_url].on_hover[Click me!]>."
23+
24+
webedititem_invalid_sess:
25+
type: task
26+
debug: false
27+
script:
28+
- determine code:403 passively
29+
- determine headers:[Content-Type=text/plain] passively
30+
- determine "raw_text_content:Invalid access session. Use the command in-game to generate a session link."
31+
32+
webedititem_session_validate:
33+
type: task
34+
debug: false
35+
script:
36+
- define user <context.query.get[user]||null>
37+
- define session <context.query.get[session]||null>
38+
- if <[user]> == null || <[session]> == null:
39+
- inject webedititem_invalid_sess
40+
- define charset 0123456789abcdef-
41+
- if !<[user].matches_character_set[<[charset]>]> || !<[session].matches_character_set[<[charset]>]>:
42+
- inject webedititem_invalid_sess
43+
- if !<server.online_players.parse[uuid].contains[<[user]>]>:
44+
- inject webedititem_invalid_sess
45+
- define player <player[<[user]>]>
46+
- if !<[player].has_flag[web_edit_item_session.<[session]>]>:
47+
- inject webedititem_invalid_sess
48+
- define item <[player].flag[web_edit_item_session.<[session]>]>
49+
# General backup safety check
50+
- if <[item].material.name||air> == air:
51+
- inject webedititem_invalid_sess
52+
53+
webserver_webitemedit_world:
54+
type: world
55+
debug: false
56+
events:
57+
on server start:
58+
- flag server webedititem_cache_ench:<server.enchantments.parse[key.after[:]].alphabetical>
59+
on player quits flagged:web_edit_item_session:
60+
- flag player web_edit_item_session:!
61+
on webserver web request path:/web_edit_item method:get:
62+
- inject webedititem_session_validate
63+
- determine code:200 passively
64+
- determine headers:[Content-Type=text/html] passively
65+
- determine cached_file:web_edit_item.htm
66+
on webserver web request path:/web_edit_item.json method:post:
67+
- inject webedititem_session_validate
68+
- determine code:200 passively
69+
- determine headers:[Content-Type=application/json] passively
70+
- definemap out_data:
71+
material: <[item].material.name>
72+
display: <[item].display.replace_text[<&ss>].with[&]||>
73+
lore: <[item].lore.separated_by[<n>].replace_text[<&ss>].with[&]||>
74+
enchantments: <[item].enchantment_map||<map>>
75+
available_ench_types: <server.flag[webedititem_cache_ench]>
76+
hides: <[item].hides.any>
77+
- determine raw_text_content:<[out_data].to_json>
78+
on webserver web request path:/web_edit_item_upload method:post:
79+
- inject webedititem_session_validate
80+
- determine code:200 passively
81+
- define data <util.parse_yaml[<context.body>]>
82+
- definemap alterations:
83+
hides: <[data].get[hides].if_true[all].if_false[]>
84+
display: <[data].get[display].parse_color>
85+
lore: <[data].get[lore].parse_color.lines_to_colored_list>
86+
enchantments: <[data].get[enchantments]>
87+
- define inv <inventory[webitemedit]>
88+
- give <[item].with_map[<[alterations]>]> to:<[inv]>
89+
- inventory open player:<[player]> d:<[inv]>
90+
- determine raw_text_content:Accepted.
91+
on webserver web request path:/js/webedititem.js method:get:
92+
- determine code:200 passively
93+
- determine headers:[Content-Type=application/javascript] passively
94+
- determine cached_file:/js/webedititem.js
95+
on webserver web request path:/font/minecraft* method:get:
96+
- if <context.path.after[/font/minecraft]> not in .tff|.woff|.woff2:
97+
- stop
98+
- determine code:200 passively
99+
- determine cached_file:<context.path>
100+
101+
webitemedit:
102+
type: inventory
103+
debug: false
104+
inventory: chest
105+
size: 9
106+
title: Here's your web item!

WebItemEditor/scripts/webserver.dsc

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
webtools_config:
3+
type: data
4+
debug: false
5+
# Configure this to your EXTERNAL web address. It used to generate links.
6+
url_base: http://localhost:8081/
7+
8+
webserver_startup_world:
9+
type: world
10+
debug: false
11+
events:
12+
on server start:
13+
- webserver start port:8081 ignore_errors
14+
15+
webserver_corefiles_handler_world:
16+
type: world
17+
debug: false
18+
events:
19+
on webserver web request path:/|/index|/index.html method:get:
20+
- determine code:403 passively
21+
- determine headers:[Content-Type=text/html] passively
22+
- determine cached_file:index.htm
23+
on webserver web request path:/favicon.ico method:get:
24+
- determine code:200 passively
25+
- determine cached_file:favicon.ico
26+
on webserver web request path:/robots.txt method:get:
27+
- determine code:200 passively
28+
- determine "raw_text_content:User-agent: *<n>Disallow: /<n>"
29+
on webserver web request path:/css/bootstrap_dark.min.css method:get:
30+
- determine code:200 passively
31+
- determine headers:[Content-Type=text/css] passively
32+
- determine cached_file:/css/bootstrap_dark.min.css
33+
on webserver web request path:/js/jquery.min.js|/js/bootstrap.min.js method:get:
34+
- determine code:200 passively
35+
- determine headers:[Content-Type=application/javascript] passively
36+
- determine cached_file:<context.path>
37+
38+
webserver_fallback_handler_world:
39+
type: world
40+
debug: false
41+
events:
42+
on webserver web request priority:1000 has_response:false:
43+
- determine code:404 passively
44+
- determine headers:[Content-Type=text/plain] passively
45+
- determine "raw_text_content:Invalid path"

WebItemEditor/webroot/css/bootstrap_dark.min.css

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebItemEditor/webroot/favicon.ico

123 KB
Binary file not shown.
15.3 KB
Binary file not shown.
4.04 KB
Binary file not shown.
2.32 KB
Binary file not shown.

WebItemEditor/webroot/index.htm

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Placeholder</title>
5+
<meta charset="utf-8" />
6+
</head>
7+
<body>
8+
<center>
9+
<br>
10+
<h1>Placeholder page. Maybe you'll make more a website here?</h3>
11+
</center>
12+
</body>
13+
</html>

WebItemEditor/webroot/js/bootstrap.min.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WebItemEditor/webroot/js/jquery.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
enchantsKnown = {};
2+
3+
function loaditemdata() {
4+
fetch("/web_edit_item.json" + window.location.search, { method: 'POST' }).then(res => res.json()).then(obj => {
5+
document.getElementById('material_name').textContent = obj.material;
6+
document.getElementById('display_name').textContent = obj.display;
7+
document.getElementById('lore').textContent = obj.lore;
8+
for (var key in obj.enchantments) {
9+
listEnchant(key, obj.enchantments[key]);
10+
}
11+
let enchantmentDropdown = document.getElementById('add_enchantment_type');
12+
for (var enchant_type in obj.available_ench_types) {
13+
enchantmentDropdown.insertAdjacentHTML("beforeend", "<option>" + obj.available_ench_types[enchant_type] + "</option>");
14+
}
15+
document.getElementById('hide_data').checked = obj.hides == "true";
16+
});
17+
document.getElementById('add_ench_button').addEventListener("click", function() {
18+
let type = document.getElementById('add_enchantment_type').value;
19+
let level = document.getElementById('add_enchant_level').value;
20+
listEnchant(type, level);
21+
});
22+
document.getElementById('sendback_button').addEventListener("click", function() {
23+
let object = {
24+
hides: document.getElementById('hide_data').checked ? "true" : "false",
25+
display: document.getElementById('display_name').value,
26+
lore: document.getElementById('lore').value,
27+
enchantments: enchantsKnown
28+
};
29+
console.log(JSON.stringify(object));
30+
fetch("/web_edit_item_upload" + window.location.search, { method: 'POST', body: JSON.stringify(object) });
31+
});
32+
}
33+
34+
function listEnchant(enchant, level) {
35+
let existing = document.getElementById("ench_list_" + enchant);
36+
if (existing) {
37+
existing.remove();
38+
}
39+
enchantsKnown[enchant] = level;
40+
document.getElementById('existing_enchants').insertAdjacentHTML("beforeend", '<li class="list-group-item" id="ench_list_' + enchant + '"><center>'
41+
+ enchant + ' &nbsp; ' + level + ' &nbsp; <button type="button" class="btn btn-danger" id="remove_ench_' + enchant + '">Remove</button></center></li>');
42+
document.getElementById("remove_ench_" + enchant).addEventListener("click", function() {
43+
document.getElementById("ench_list_" + enchant).remove();
44+
delete enchantsKnown[enchant];
45+
});
46+
}
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="/css/bootstrap_dark.min.css" media="screen">
7+
<title>Minecraft Web Item Editor</title>
8+
<script src="/js/jquery.min.js"></script>
9+
<style>
10+
@font-face {
11+
font-family: minecraft;
12+
src: url("/font/minecraft.woff2") format("woff2"), /* chrome、firefox */
13+
url("/font/minecraft.woff") format("woff"), /* chrome、firefox */
14+
url("/font/minecraft.ttf") format("truetype"); /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
15+
}
16+
.limit_size {
17+
max-width: 1000px;
18+
}
19+
.input_block {
20+
max-width: 600px;
21+
}
22+
hr {
23+
border-color: #FFFFFF;
24+
}
25+
.form-control {
26+
background-color: #101010;
27+
}
28+
textarea {
29+
background: transparent;
30+
width: 100%;
31+
color: #FFFFFF;
32+
font-family: minecraft, Arial, Helvetica, sans-serif;
33+
font-size: 16px;
34+
font-weight: 100;
35+
}
36+
.oneline_text {
37+
overflow: hidden;
38+
height: 2rem;
39+
}
40+
.material_name {
41+
padding: 5px;
42+
padding-top: 2px;
43+
border: 1px dotted #ffffff;
44+
border-radius: 10px;
45+
}
46+
</style>
47+
</head>
48+
<body onload="loaditemdata()">
49+
<center>
50+
<br>
51+
<h1>Minecraft Web Item Editor</h1>
52+
<hr>
53+
<div class="limit_size">
54+
<br><br>
55+
Material
56+
<br>
57+
<span class="material_name" id="material_name">Error?</span>
58+
<br><br>
59+
Display Name
60+
<br>
61+
<textarea class="oneline_text" id="display_name" type="text" rows="1" wrap="off" maxlength="500"></textarea>
62+
<br><br>
63+
Lore
64+
<br>
65+
<textarea id="lore" style="height:15rem;"></textarea>
66+
<br><br>
67+
<input class="form-check-input" type="checkbox" id="hide_data">
68+
<label class="form-check-label" for="hide_data">Hide Default Lore Data</label>
69+
<br><br>
70+
Enchantments
71+
<br>
72+
<ul class="list-group" id="existing_enchants">
73+
</ul>
74+
<br>
75+
Add Enchantment:
76+
<select id="add_enchantment_type"></select>
77+
Level: <input id="add_enchant_level" type="number" value="1" max="100" min="1" style="max-width:4rem;">
78+
<button type="button" class="btn btn-primary" id="add_ench_button">Add</button>
79+
<br><br>
80+
<hr>
81+
<button type="button" class="btn btn-success" id="sendback_button">Send Back To Game</button>
82+
</div>
83+
<br><br><br>
84+
<hr>
85+
<br>
86+
<footer>
87+
<a href="https://github.com/mcmonkeyprojects/DenizenSampleScripts/tree/master/WebItemEditor">WebItemEditor</a> was Created by Alex 'mcmonkey' Goodwin and is licensed under <a href="https://github.com/mcmonkeyprojects/DenizenSampleScripts/blob/802cc2271f525c112eeb2f5a299c18174b0d93d0/LICENSE.txt">the MIT license</a>.
88+
<br>Made using the <a href="https://www.onlinewebfonts.com/download/6ab539c6fc2b21ff0b149b3d06d7f97c">Minecraft Regular font from OnlineWebFonts.com</a>, licensed as CC-BY 3.0
89+
<br>Made using the <a href="https://bootswatch.com/darkly/">Darkly Bootstrap Theme</a> by Thomas Park, which was released under the <a href="https://github.com/thomaspark/bootswatch/blob/7fcf822114e71cfb3b89e98afb58055d21f5e240/LICENSE">MIT License</a>.
90+
<br>
91+
</footer>
92+
</center>
93+
<script src="/js/webedititem.js"></script>
94+
<script src="/js/bootstrap.min.js"></script>
95+
</body>
96+
</html>

0 commit comments

Comments
 (0)