diff --git a/scripts/animated_text.js b/scripts/animated_text.js new file mode 100644 index 0000000..fade160 --- /dev/null +++ b/scripts/animated_text.js @@ -0,0 +1,22 @@ +var messages = ["This is", "This is a", "This is a test message"]; +var numdata = "%player_name%." + IDv + "." + messages; +var IDv = 0; + +function getMessage(ID) { + if ( args.length == 4) { + IDv = args[0]; + messages = [args[1], args[2], args[3]]; + } + + var msgnumber = Data.exists(numdata) ? Data.get(numdata) : 0; + msgnumber++; + + if (msgnumber >= 3) { + msgnumber = 0; + } + + Data.set(numdata, msgnumber); + + return messages[msgnumber]; +} +getMessage(IDv); \ No newline at end of file diff --git a/scripts/cooldown.js b/scripts/cooldown.js new file mode 100644 index 0000000..949a74f --- /dev/null +++ b/scripts/cooldown.js @@ -0,0 +1,70 @@ +var monthSymbol = "mo"; +var daySymbol = "d"; +var hourSymbol = "h"; +var minuteSymbol = "m"; +var secondSymbol = "s"; + +var arg = args[0].split("_"); +if (arg.length === 2) { + var ID = arg[0]; + var cooldown = arg[1]; +} + +var dataLoc = "%player_name%." + ID + ".date"; +var currentDate = new Date(); + +function Cooldown() { + if (!Data.exists(dataLoc)) { + return "0s"; + } else { + var startDate = new Date(Data.get(dataLoc)); + var difference = currentDate - startDate; + var result = Math.floor(difference / 1000); + if (result >= cooldown) { + return "0s"; + } else { + startDate = new Date(startDate.getTime() + (cooldown * 1000)); + var result = startDate - currentDate; + + var months = Math.floor(result / (1000 * 60 * 60 * 24 * 31)); + var days = Math.floor(result % (1000 * 60 * 60 * 24 * 31) / (1000 * 60 * 60 * 24)); + var hours = Math.floor(result % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)); + var minutes = Math.floor(result % (1000 * 60 * 60) / (1000 * 60)); + var seconds = Math.floor(result % (1000 * 60) / (1000)); + + if (months === 0 && days === 0 && hours === 0 && minutes === 0) { + return seconds + secondSymbol; + } else if (months === 0 && days === 0 && hours === 0) { + return minutes + minuteSymbol + seconds + secondSymbol; + } else if (months === 0 && days === 0) { + return hours + hourSymbol + minutes + minuteSymbol + seconds + secondSymbol; + } else if (months === 0) { + return days + daySymbol + hours + hourSymbol + minutes + minuteSymbol + seconds + secondSymbol; + } else { + return months + monthSymbol + days + daySymbol + hours + hourSymbol + minutes + minuteSymbol + seconds + secondSymbol; + } + } + } +} + +function start() { + var data = currentDate.toString(); + + Data.set(dataLoc, data); + Placeholder.saveData(); +} + +function run() { + if (args.length !== 1 || arg.length !== 2) { + return "&cInvalid syntax, Please use this syntax:\n&7%" + "javascript_cooldown_[ID]_[Cooldown/Start]" + "%"; + } else if (cooldown.toUpperCase() === "START") { + return start(); + } else if (isNaN(cooldown)) { + return "&cPlease set a valid cooldown."; + } else if (!isNaN(cooldown)) { + return Cooldown(); + } else { + return "&cInvalid syntax, Please use this syntax:\n&7%" + "javascript_cooldown_[ID]_[Cooldown/Start]" + "%"; + } +} +run(); diff --git a/scripts/data_example.js b/scripts/data_example.js new file mode 100644 index 0000000..230e8d8 --- /dev/null +++ b/scripts/data_example.js @@ -0,0 +1,88 @@ +function set(path, data) { + Data.set(path, data); + return ""; +} +function add(path, amount) { + if (isNaN(amount)) { + return ""; + } + var amt = Data.exists(path) ? Data.get(path) : 0; + if (isNaN(amt)) { + amt = 0; + } + amt = parseInt(amt) + parseInt(amount); + Data.set(path, amt.toFixed()); + return ""; +} +function subtract(path, amount) { + if (isNaN(amount)) { + return ""; + } + var amt = Data.exists(path) ? parseInt(Data.get(path)) : 0; + if (isNaN(amt)) { + amt = 0; + } + amt = parseInt(amt) - parseInt(amount); + Data.set(path, amt.toFixed()); + return ""; +} +function get(path) { + return Data.exists(path) ? Data.get(path) : ""; +} +function getInt(path) { + if (Data.exists(path)) { + var amt = Data.get(path); + if (isNaN(amt)) { + return 0; + } else { + return parseInt(amt).toFixed(); + } + } + return 0; +} +function getUsage(firstArg) { + switch(firstArg) { + case "get": + return "get,"; + case "getint": + return "getint,"; + case "add": + return "add,,"; + case "subtract": + return "subtract,,"; + case "set": + return "set,,"; + default: + return "first argument must be get, getint, set, add, subtract"; + } +} +function runPlaceholder() { + if (args.length == 0) { + return getUsage("no args"); + } + else if (args.length == 1) { + return getUsage(args[0]); + } + + if (args.length == 2) { + if (args[0].equals("get")) { + return get(args[1]); + } + else if (args[0].equals("getint")) { + return getInt(args[1]); + } + } + else if (args.length == 3) { + if (args[0].equals("set")) { + return set(args[1], args[2]); + } + else if (args[0].equals("add")) { + return add(args[1], args[2]); + } + else if (args[0].equals("subtract")) { + return subtract(args[1], args[2]); + } + } + return getUsage(args[0]); +} +runPlaceholder(); \ No newline at end of file diff --git a/scripts/difference_dates.js b/scripts/difference_dates.js new file mode 100644 index 0000000..18b488d --- /dev/null +++ b/scripts/difference_dates.js @@ -0,0 +1,17 @@ +function time() { + // year, month, day, hour, minute, second + // months start at 0 and end at 11 + // January is 0. December is 11 + var startDate = new Date(2018, 0, 1); + var endDate = new Date(); + var difference = endDate - startDate; + + var months = Math.floor(difference / (1000 * 60 * 60 * 24 * 31)); + var days = Math.floor(difference % (1000 * 60 * 60 * 24 * 31) / (1000 * 60 * 60 * 24)); + var hours = Math.floor(difference % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)); + var minutes = Math.floor(difference % (1000 * 60 * 60) / (1000 * 60)); + var seconds = Math.floor(difference % (1000 * 60) / (1000)); + + // XXmo XXd XXh XXm XXs (changeable) + return months + "mo "+ days + "d " + hours + "h " + minutes + "m " + seconds + "s"; +} \ No newline at end of file diff --git a/scripts/has_item.js b/scripts/has_item.js new file mode 100644 index 0000000..305ea81 --- /dev/null +++ b/scripts/has_item.js @@ -0,0 +1,85 @@ +var player = BukkitPlayer; + +var mat; +var data = '0'; +var amt = 1; +var name; +var lore; + +var hasitemv = 'no'; +var matchlores = 0; + +function hasitem() { + + if ( args.length === 1 ) { + mat = args[0].replace("mat: ", ""); + } else if ( args.length === 2 ) { + mat = args[0].replace("mat: ", ""); + data = args[1].replace("data: ", ""); + } else if ( args.length === 3 ) { + mat = args[0].replace("mat: ", ""); + data = args[1].replace("data: ", ""); + amt = args[2].replace("amt: ", ""); + } else if ( args.length === 4 ) { + mat = args[0].replace("mat: ", ""); + data = args[1].replace("data: ", ""); + amt = args[2].replace("amt: ", ""); + name = args[3].replace("name: ", ""); + } else if ( args.length === 5 ) { + mat = args[0].replace("mat: ", ""); + data = args[1].replace("data: ", ""); + amt = args[2].replace("amt: ", ""); + name = args[3].replace("name: ", ""); + lore = args[4].replace("lore: ", "").split("|"); + } + + var invItems = player.getInventory().getContents(); + + for ( s = 0; s < invItems.length; s++ ) { + if ( invItems[s] !== null ) { + if ( lore !== undefined && invItems[s].getItemMeta().hasLore() === false ) { + hasitemv = 'no'; + } else if ( lore !== undefined ) { + if ( invItems[s].getType().toString() === mat || invItems[s].getTypeId() === parseInt(mat) ) { + if ( invItems[s].getData().toString().match(/\d+/)[0] === data ) { + if ( invItems[s].getAmount() >= parseInt(amt) ) { + if ( invItems[s].getItemMeta().getDisplayName() === name ) { + for ( l = 0; l < lore.length; l++ ) { + if ( invItems[s].getItemMeta().getLore()[l] === lore[l] ) { + matchlores++; + } + } + } + } + } + } + if ( matchlores === lore.length ) { + hasitemv = 'yes'; + } + } else if ( name !== undefined ) { + if ( invItems[s].getType().toString() === mat || invItems[s].getTypeId() === parseInt(mat) ) { + if ( invItems[s].getData().toString().match(/\d+/)[0] === data ) { + if ( invItems[s].getAmount() >= parseInt(amt) ) { + if ( invItems[s].getItemMeta().getDisplayName() === name ) { + hasitemv = 'yes'; + } + } + } + } + } else if ( mat === undefined ) { + return '&cInvalid syntax, Please use this syntax:\n &7%' + 'javascript_hasitem_mat: [MATERIAL/ID],data: [DATA],amt: [AMOUNT],name: [DISPLAYNAME],lore: [LORE]' + '%'; + } else { + if ( invItems[s].getType().toString() === mat || invItems[s].getTypeId() === parseInt(mat) ) { + if ( invItems[s].getData().toString().match(/\d+/)[0] === data ) { + if ( invItems[s].getAmount() >= parseInt(amt) ) { + hasitemv = 'yes'; + } + } + } + } + } + } + return hasitemv; +} + +hasitem(); \ No newline at end of file diff --git a/scripts/health_rounded.js b/scripts/health_rounded.js new file mode 100644 index 0000000..efa01be --- /dev/null +++ b/scripts/health_rounded.js @@ -0,0 +1,4 @@ +function hp() { + return Math.round(parseInt('%player_health%') * 100) / 100; +} +hp(); \ No newline at end of file diff --git a/scripts/holding_displayname.js b/scripts/holding_displayname.js new file mode 100644 index 0000000..15ee199 --- /dev/null +++ b/scripts/holding_displayname.js @@ -0,0 +1,21 @@ +var player = BukkitPlayer; +var material = '%player_item_in_hand%'; + +function displayname() { + if ( material !== 'AIR' ) { + var has = player.getInventory().getItemInHand().getItemMeta().hasDisplayName(); + var name = player.getInventory().getItemInHand().getItemMeta().getDisplayName(); + } + + if ( material === 'AIR' ) { + // return 'AIR' when you aren't holding an item (You can change it to whatever you want) + return 'AIR'; + } else if ( has ) { + return name; + } else { + // returns the material name (%player_item_in_hand%) when it an item doesn't has a display name + // You can change it to whatever you want by replacing material with 'WHAT YOU WANT' + return material; + } +} +displayname(); \ No newline at end of file diff --git a/scripts/holding_lore.js b/scripts/holding_lore.js new file mode 100644 index 0000000..ec257b5 --- /dev/null +++ b/scripts/holding_lore.js @@ -0,0 +1,43 @@ +var player = BukkitPlayer; +var material = '%player_item_in_hand%'; + +var line = ' '; + + +function itemlore() { + if ( material !== 'AIR' ) { + var has = player.getInventory().getItemInHand().getItemMeta().hasLore(); + var linelore = player.getInventory().getItemInHand().getItemMeta().getLore(); + } + + if ( material !== 'AIR' && has === true ) { + var lore = player.getInventory().getItemInHand().getItemMeta().getLore().toString(); + } + + if ( material !== 'AIR' && has === true && lore.indexOf(', ,') !== -1 ) { + lore = lore.replace(/, ,/g, ', ,'); + } + + if ( args.length == 1 ) { + line = args[0]; + } + + if ( material === 'AIR' ) { + // return 'AIR' when you aren't holding an item (You can change it to whatever you want) + return 'AIR'; + } else if ( has && line === ' ' ) { + return lore.replace(/^\[/, "").replace(/.$/,"").replace(/, /g, '\n'); + } else if ( has && line !== ' ' ) { + if (linelore.length >= line) { + line = parseInt(line) - 1; + return linelore[line]; + } + // return ' ' (Nothing/blank line) when the item you're holding doesn't has the requested line (You can change it to whatever you want) + return ' '; + } else { + // return ' ' (Nothing/blank line) when the item you're holding doesn't has lore (You can change it to whatever you want) + return ' '; + } + +} +itemlore(); \ No newline at end of file diff --git a/scripts/holding_lore_lines.js b/scripts/holding_lore_lines.js new file mode 100644 index 0000000..de8e372 --- /dev/null +++ b/scripts/holding_lore_lines.js @@ -0,0 +1,21 @@ +var player = BukkitPlayer; +var material = '%player_item_in_hand%'; + + +function lorelines() { + if ( material !== 'AIR' ) { + var lore = player.getInventory().getItemInHand().getItemMeta().getLore(); + var has = player.getInventory().getItemInHand().getItemMeta().hasLore(); + } + + if ( material === 'AIR' ) { + // return 'AIR' when you aren't holding an item (You can change it to whatever you want) + return 'AIR'; + } else if ( has ) { + return lore.length; + } else { + // return '0' when the item you're holding doesn't has lore (You can change it to whatever you want) + return '0'; + } +} +lorelines(); \ No newline at end of file diff --git a/scripts/master_list.json b/scripts/master_list.json index ae5844a..022e839 100644 --- a/scripts/master_list.json +++ b/scripts/master_list.json @@ -19,5 +19,89 @@ "version": "1.0.0", "description": "A simple placeholder which formats DeluxeTags tag spacing", "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/tags.js" + }, + { + "name": "random_letter", + "author": "NathanG", + "version": "1.0.0", + "description": "Prints a random letter from A to Z", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/random_letter.js" + }, + { + "name": "random_integer_between", + "author": "NathanG", + "version": "1.0.0", + "description": "Generates a random integer between two given integers. %javascript_randomintbetween_,%", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/random_integer_between.js" + }, + { + "name": "data_example", + "author": "clip", + "version": "1.0.0", + "description": "Placeholder that allows you to get and set custom data via the placeholder arguments specified when the placeholder is called", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/data_example.js" + }, + { + "name": "animated_text", + "author": "aBooDyy && NathanG", + "version": "1.0.0", + "description": "Change the return value every 1 seconds the placeholder called. it have 3 different values (you can add more). This placeholder is useful for plugins which don't have animated text feature (e.g. DeluxeMenus Lore).", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/animated_text.js" + }, + { + "name": "health_rounded", + "author": "xDizasterCYx", + "version": "1.0.0", + "description": "Changes the ugly health placeholder to rounded integer", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/health_rounded.js" + }, + { + "name": "max_health_rounded", + "author": "xDizasterCYx", + "version": "1.0.0", + "description": "Changes the ugly max health placeholder to rounded integer", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/health_rounded.js" + }, + { + "name": "has_item", + "author": "aBooDyy", + "version": "1.0.0", + "description": "Check if player has an item you set in the placeholder (Material, Data, Amount, Name, Lore), It supports color codes for Name and Lore also it supports more than one lore line. It returns 'yes' if the player has the item, and 'no' if he doesn't.\nUsage: %javascript_hasitem_mat: [MATERIAL/ID],data: [DATA],amt: [AMOUNT],name: [DISPLAYNAME],lore: [LORE]%", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/has_item.js" + }, + { + "name": "holding_displayname", + "author": "aBooDyy", + "version": "1.0.0", + "description": "Return the display name of the item you're holding in your hand", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/holding_displayname.js" + }, + { + "name": "holding_lore", + "author": "aBooDyy", + "version": "1.0.0", + "description": "eturns the lore of the item you're holding all the lines of one line you specify", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/holding_lore.js" + }, + { + "name": "holding_lore_lines", + "author": "aBooDyy", + "version": "1.0.0", + "description": "Returns how many lore line of the item you're holding", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/holding_lore_lines.js" + }, + { + "name": "difference_dates", + "author": "aBooDyy", + "version": "1.0.0", + "description": "Give you the difference between 2 dates you set or how many until that date or how many time passed from that date", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/difference_dates.js" + }, + { + "name": "cooldown", + "author": "aBooDyy", + "version": "1.0.0", + "description": "Gcooldown placeholder made for DeluxeMenus (not only for DeluxeMenus) to set a duration between clicking an item.\nUsage: %javascript_cooldown_[ID]_[COOLDOWN/Start]%", + "url": "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/cooldown.js" } ] diff --git a/scripts/max_health_rounded.js b/scripts/max_health_rounded.js new file mode 100644 index 0000000..0a51e7e --- /dev/null +++ b/scripts/max_health_rounded.js @@ -0,0 +1,4 @@ +function hp() { + return Math.round(parseInt('%player_max_health%') * 100) / 100; +} +hp(); \ No newline at end of file diff --git a/scripts/random_integer_between.js b/scripts/random_integer_between.js new file mode 100644 index 0000000..02d93d1 --- /dev/null +++ b/scripts/random_integer_between.js @@ -0,0 +1,17 @@ + +var min = 1; +var max = 25; + +function randomInteger() { + if (args.length == 2) { + min = args[0]; + max = args[1]; + } + + var random = Math.random() * (max - min); + random += min; + + return Math.floor(random); +} + +randomInteger(); \ No newline at end of file diff --git a/scripts/random_letter.js b/scripts/random_letter.js new file mode 100644 index 0000000..ee69880 --- /dev/null +++ b/scripts/random_letter.js @@ -0,0 +1,8 @@ +function randomLetter() { + var start = "A".charCodeAt(0); + var random = Math.random() * 26; + + return String.fromCharCode(start + Math.floor(random)); +} + +randomLetter(); \ No newline at end of file