Skip to content

Instantly share code, notes, and snippets.

@incredimike
Last active April 7, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incredimike/6882eadcd38fcee04b702ccd0b7a0d51 to your computer and use it in GitHub Desktop.
Save incredimike/6882eadcd38fcee04b702ccd0b7a0d51 to your computer and use it in GitHub Desktop.
Generate a DTLTraders shop in Minecraft with PHP
{
"bat_spawn_egg": {"id":"bat_spawn_egg", "legacy_id":"spawn_egg"},
"blaze_spawn_egg": {"id":"blaze_spawn_egg", "legacy_id":"spawn_egg"},
"cave_spider_spawn_egg": {"id":"cave_spider_spawn_egg", "legacy_id":"spawn_egg"},
"chicken_spawn_egg": {"id":"chicken_spawn_egg", "legacy_id":"spawn_egg"},
"cow_spawn_egg": {"id":"cow_spawn_egg", "legacy_id":"spawn_egg"},
"creeper_spawn_egg": {"id":"creeper_spawn_egg", "legacy_id":"spawn_egg"},
"donkey_spawn_egg": {"id":"donkey_spawn_egg", "legacy_id":"spawn_egg"},
"elder_guardian_spawn_egg": {"id":"elder_guardian_spawn_egg", "legacy_id":"spawn_egg"},
"enderman_spawn_egg": {"id":"enderman_spawn_egg", "legacy_id":"spawn_egg"},
"endermite_spawn_egg": {"id":"endermite_spawn_egg", "legacy_id":"spawn_egg"},
"evoker_spawn_egg": {"id":"evoker_spawn_egg", "legacy_id":"spawn_egg"},
"ghast_spawn_egg": {"id":"ghast_spawn_egg", "legacy_id":"spawn_egg"},
"guardian_spawn_egg": {"id":"guardian_spawn_egg", "legacy_id":"spawn_egg"},
"horse_spawn_egg": {"id":"horse_spawn_egg", "legacy_id":"spawn_egg"},
"husk_spawn_egg": {"id":"husk_spawn_egg", "legacy_id":"spawn_egg"},
"llama_spawn_egg": {"id":"llama_spawn_egg", "legacy_id":"spawn_egg"},
"magma_cube_spawn_egg": {"id":"magma_cube_spawn_egg", "legacy_id":"spawn_egg"},
"mooshroom_spawn_egg": {"id":"mooshroom_spawn_egg", "legacy_id":"spawn_egg"},
"mule_spawn_egg": {"id":"mule_spawn_egg", "legacy_id":"spawn_egg"},
"ocelot_spawn_egg": {"id":"ocelot_spawn_egg", "legacy_id":"spawn_egg"},
"parrot_spawn_egg": {"id":"parrot_spawn_egg", "legacy_id":"spawn_egg"},
"pig_spawn_egg": {"id":"pig_spawn_egg", "legacy_id":"spawn_egg"},
"polar_bear_spawn_egg": {"id":"polar_bear_spawn_egg", "legacy_id":"spawn_egg"},
"rabbit_spawn_egg": {"id":"rabbit_spawn_egg", "legacy_id":"spawn_egg"},
"sheep_spawn_egg": {"id":"sheep_spawn_egg", "legacy_id":"spawn_egg"},
"shulker_spawn_egg": {"id":"shulker_spawn_egg", "legacy_id":"spawn_egg"},
"silverfish_spawn_egg": {"id":"silverfish_spawn_egg", "legacy_id":"spawn_egg"},
"skeleton_spawn_egg": {"id":"skeleton_spawn_egg", "legacy_id":"spawn_egg"},
"skeleton_horse_spawn_egg": {"id":"skeleton_horse_spawn_egg", "legacy_id":"spawn_egg"},
"slime_spawn_egg": {"id":"slime_spawn_egg", "legacy_id":"spawn_egg"},
"spider_spawn_egg": {"id":"spider_spawn_egg", "legacy_id":"spawn_egg"},
"squid_spawn_egg": {"id":"squid_spawn_egg", "legacy_id":"spawn_egg"},
"stray_spawn_egg": {"id":"stray_spawn_egg", "legacy_id":"spawn_egg"},
"vex_spawn_egg": {"id":"vex_spawn_egg", "legacy_id":"spawn_egg"},
"villager_spawn_egg": {"id":"villager_spawn_egg", "legacy_id":"spawn_egg"},
"vindicator_spawn_egg": {"id":"vindicator_spawn_egg", "legacy_id":"spawn_egg"},
"witch_spawn_egg": {"id":"witch_spawn_egg", "legacy_id":"spawn_egg"},
"wither_skeleton_spawn_egg": {"id":"wither_skeleton_spawn_egg", "legacy_id":"spawn_egg"},
"wolf_spawn_egg": {"id":"wolf_spawn_egg", "legacy_id":"spawn_egg"},
"zombie_spawn_egg": {"id":"zombie_spawn_egg", "legacy_id":"spawn_egg"},
"zombie_horse_spawn_egg": {"id":"zombie_horse_spawn_egg", "legacy_id":"spawn_egg"},
"zombie_pigman_spawn_egg": {"id":"zombie_pigman_spawn_egg", "legacy_id":"spawn_egg"},
"zombie_villager_spawn_egg": {"id":"zombie_villager_spawn_egg", "legacy_id":"spawn_egg"},
"cod_spawn_egg": {"id":"cod_spawn_egg", "legacy_id":""},
"dolphin_spawn_egg": {"id":"dolphin_spawn_egg", "legacy_id":""},
"drowned_spawn_egg": {"id":"drowned_spawn_egg", "legacy_id":""},
"phantom_spawn_egg": {"id":"phantom_spawn_egg", "legacy_id":""},
"pufferfish_spawn_egg": {"id":"pufferfish_spawn_egg", "legacy_id":""},
"salmon_spawn_egg": {"id":"salmon_spawn_egg", "legacy_id":""},
"tropical_fish_spawn_egg": {"id":"tropical_fish_spawn_egg", "legacy_id":""},
"turtle_spawn_egg": {"id":"turtle_spawn_egg", "legacy_id":""},
"cat_spawn_egg": {"id":"cat_spawn_egg", "legacy_id":""},
"fox_spawn_egg": {"id":"fox_spawn_egg", "legacy_id":""},
"panda_spawn_egg": {"id":"panda_spawn_egg", "legacy_id":""},
"pillager_spawn_egg": {"id":"pillager_spawn_egg", "legacy_id":""},
"ravager_spawn_egg": {"id":"ravager_spawn_egg", "legacy_id":""},
"trader_llama_spawn_egg": {"id":"trader_llama_spawn_egg", "legacy_id":""},
"wandering_trader_spawn_egg": {"id":"wandering_trader_spawn_egg", "legacy_id":""}
}
<?php
$unique_id = 10060;
$item_template = yaml_parse(file_get_contents('./template.yaml'));
$egg_json = file_get_contents('./eggs_ids.json');
$eggs = json_decode($egg_json, JSON_OBJECT_AS_ARRAY);
$pets = array_map('str_getcsv', file('./pets.csv'));
unset($pets[0]); // remove first header row
$pages = [];
foreach ($pets as $pet) {
$item = array_merge([], $item_template); // New item template
$item['id'] = $unique_id; // pseudo unqiue ID
$page_name = $pet[0]; // Name Shop Page
$page_id = $pet[1]; // Shop Page Order
$display_name = $pet[3]; // Pet Display Name
$permission_node = $pet[4];
$price = (float)$pet[5];
$type = $pet[6]; // Block Type
$description = [
$pet[7]
];
// Create new page if it doesn't already exist
if (!isset($pages['page-'.$page_id])) {
$pages['page-'.$page_id] = [
'size' => 54,
'page-name' => $page_name,
'page-permission' => '',
];
}
$item['item']['type'] = $type;
if (!empty($eggs[strtolower($type)]['legacy_id'])) {
$item['item']['meta'] = create_item_meta($eggs[strtolower($type)]['legacy_id'], $type);
}
$item['display-name'] = $display_name;
$item['description'] = $description;
$item['run-mode'] = 'BUY_AND_RUN';
$item['trade-price'] = $price;
$item['commands'] = add_command(
'givepet %player% ' . $permission_node // %player% is placeholder according to dtl plugin dev
);
// increase item-n object
$i = @count($pages['page-'.$page_id]['buy-items']);
$pages['page-'.$page_id]['buy-items']['item-'.$i] = $item;
$unique_id++;
}
$shop_yaml = <<<SHOP
petshop:
title: Petshop
command: none
permission: none
default-shop: buy
buy-shop-enabled: true
sell-shop-enabled: true
trade-shop-enabled: false
logging-enabled: true
pages:
SHOP;
$shop_array = yaml_parse($shop_yaml);
$shop_array['petshop']['pages'] = $pages;
$yaml = trim(yaml_emit($shop_array, YAML_UTF8_ENCODING));
$yaml = trim($yaml, '-.'); // clean tops and bottoms --- & ...
$yaml = trim($yaml); // remove whitespace
$yaml = str_replace(["'''"], ["'"], $yaml); // clean up triple quotes
file_put_contents('./shop.yaml', $yaml); // Dump out to local file
function create_item_meta($meta_type, $parent_type)
{
$item_meta = [
'==' => 'ItemMeta',
'meta-type' => strtoupper($meta_type),
'lore' => [
// '§bDiscount price: §c0.00',
// '§bDiscount start: §c' . date('d/m/Y h:i:s'),
// '§bDiscount duration: §c-',
// '§bDiscount end: §c' . date('d/m/Y h:i:s'),
// '§b0 /0',
// '§b-'
]
];
if (empty($meta_type)) {
$item_meta['meta-type'] = $parent_type;
}
return $item_meta;
}
function add_command($command, $context='CONSOLE')
{
return [
"'0'" => [
'executor' => $context,
'command' => $command
]
];
}
id: 0
type: commands
item:
==: org.bukkit.inventory.ItemStack
v: 2230
type: ''
meta:
==: ItemMeta
meta-type: SPAWN_EGG
lore: []
display-name: ''
display-lore: []
show-description: true
description: []
run-mode: ''
commands: []
Discount:
discount-percentage: 0.0
show-discount-price: false
discount-price: 0.0
show-discount-start: false
discount-start: 05/04/2020 13:10:54
show-discount-duration: false
discount-duration: 0
show-discount-end: false
discount-end: 05/04/2020 13:10:54
show-price: true
trade-price: 0.0
custom-input-enabled: false
stack-sale-enabled: false
show-trade-limit: true
trade-limit: -1
show-limit-time: true
limit-reset-seconds: -1
show-broadcast-message: false
broadcast-message: ''
drop-item-on-full-inventory: false
sell-all-when-not-enough-items: true
permission: ''
logging-enabled: true
custom-display-text-enabled: false
custom-display-text: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment