Created
July 21, 2017 02:25
-
-
Save maple3142/6265c3c239f2af06da1f7a2877ca26f2 to your computer and use it in GitHub Desktop.
ScriptCraft範例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package | |
var boss=org.bukkit.boss; | |
var utils=require('utils'); | |
function bc(text,time,sep){ | |
text=text.replace('&','\u00A7'); | |
var bar=server.createBossBar(text,boss.BarColor.BLUE,boss.BarStyle.SOLID,boss.BarFlag.DARKEN_SKY); | |
var olp=server.getOnlinePlayers(); | |
for(var i in olp) | |
bar.addPlayer(olp[i]); | |
var c=0; | |
var it=setInterval(function(){ | |
c++; | |
if(c==sep){ | |
bar.removeAll(); | |
bar=null; | |
clearInterval(it); | |
} | |
else{ | |
bar.setProgress(1-c/sep); | |
} | |
},time/sep); | |
} | |
exports.broadcast=bc; | |
command('broadcast',function(params,sender){ | |
if(!isOp(sender))echo(sender,'only op can use this command!'); | |
else if(params.length<2)echo(sender,'need 2 arguments to execute!'); | |
else bc(params[0],parseInt(params[1]),100); | |
});//jsp broadcast &6test 5000 | |
/* | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Server.html | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/boss/package-frame.html | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events.playerCommandPreprocess(function(e){ | |
var cmd=e.getMessage().split(' '); | |
if(cmd[0].equalsIgnoreCase('/openinv')){ | |
cmd[0]='/jsp openinv'; | |
} | |
if(cmd[0].equalsIgnoreCase('/dragoncast')){ | |
cmd[0]='/jsp broadcast'; | |
} | |
if(cmd[0].equalsIgnoreCase('/spawn')){ | |
cmd[0]='/warp spawn';//essential | |
} | |
cmd=cmd.join(' '); | |
console.log(cmd); | |
e.setMessage(cmd); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _=require('lodash'); | |
exports.lodashTest=function(){ | |
echo(self,_.join(['C',8,7,6,3],' ')); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var utils=require('utils'); | |
function open(target,sender){ | |
(this.self||sender).openInventory(target.getInventory()); | |
} | |
exports.openinv=open; | |
command('openinv',function(params,sender){ | |
var p=utils.player(params[0]); | |
if(!isOp(sender))echo(sender,'only op can use this command!'); | |
else if(!p)echo(sender,'player id not found') | |
else open(p,sender); | |
});//openinv <player id> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var items=require('items'); | |
var fac=server.getItemFactory(); | |
//package | |
var bukkit=org.bukkit; | |
var Inv=bukkit.inventory; | |
var E=bukkit.enchantments; | |
addRecipe({ | |
item: items.book(), | |
name: '\u00A7bSword Art Online', | |
shape: [' B ','BBB',' B '], | |
ingredient: [ | |
{ch: 'B', item: items.book()} | |
], | |
enchant: [ | |
{ | |
type: E.Enchantment.KNOCKBACK, | |
level: 48763, | |
over: true | |
} | |
], | |
unbreakable: true, | |
lore: ['C','8','7','6','3'] | |
}); | |
addRecipe({ | |
item: items.diamondSword(), | |
name: '\u00A70Obsidian Sword', | |
shape: [' O ',' O ',' S '], | |
ingredient: [ | |
{ch: 'O', item: items.obsidian()}, | |
{ch: 'S', item: items.stick()} | |
], | |
enchant: [ | |
{ | |
type: E.Enchantment.KNOCKBACK, | |
level: 3, | |
over: true | |
}, | |
{ | |
type: E.Enchantment.DURABILITY, | |
level: 3, | |
over: true | |
}, | |
{ | |
type: E.Enchantment.DAMAGE_ALL, | |
level: 3, | |
over: true | |
} | |
], | |
unbreakable: true, | |
lore: ['very very very hard sword'] | |
}); | |
function addRecipe(r){ | |
r.item=r.item||items.air(); | |
r.name=r.name||'null'; | |
r.lore=r.lore||[]; | |
r.unbreakable=r.unbreakable||false; | |
r.enchant=r.enchant||[]; | |
r.ingredient=r.ingredient||[]; | |
r.shape=r.shape||[]; | |
r.shape[0]=r.shape[0]||' '; | |
r.shape[1]=r.shape[1]||' '; | |
r.shape[2]=r.shape[2]||' '; | |
(function(){ | |
var stack=new Inv.ItemStack(r.item,1); | |
var meta=fac.getItemMeta(r.item); | |
meta.setDisplayName(r.name); | |
for(var i in r.enchant){ | |
meta.addEnchant(r.enchant[i].type,r.enchant[i].level,r.enchant[i].over||false); | |
} | |
meta.setLore(new java.util.ArrayList(r.lore)); | |
stack.setItemMeta(meta); | |
var recipe=new Inv.ShapedRecipe(stack); | |
recipe.shape(r.shape[0],r.shape[1],r.shape[2]); | |
for(var i in r.ingredient){ | |
recipe.setIngredient(r.ingredient[i].ch,r.ingredient[i].item); | |
} | |
if(server.addRecipe(recipe)){ | |
console.log('[Recipe]'+meta.getDisplayName()+' added'); | |
} | |
})(); | |
} | |
exports.addRecipe=addRecipe; | |
/* | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ShapedRecipe.html | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/ItemMeta.html | |
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
/jsp addRecipe <recipe name> | |
/jsp removeRecipe <recipe name> | |
Minecraft Gson Library *Required | |
https://www.spigotmc.org/resources/gson-for-1-8-3-or-older.30852/ | |
Installation: put it into "plugins" directory | |
*/ | |
var ItemStack=org.bukkit.inventory.ItemStack; | |
var ShapedRecipe=org.bukkit.inventory.ShapedRecipe; | |
var Material=org.bukkit.Material; | |
var store=persist('recipes',[]); | |
function update(){ | |
if(com.google.gson.Gson){ | |
var gson=new com.google.gson.Gson(); | |
for(var i in store){ | |
var res=ItemStack.deserialize(gson.fromJson(store[i].result,java.util.Map.class)); | |
var recipe=new ShapedRecipe(res); | |
recipe.shape(store[i].shape); | |
for(var j in store[i].ingredient){ | |
var ig=store[i].ingredient[j]; | |
recipe.setIngredient(ig.ch,Material.getMaterial(ig.material)); | |
} | |
server.addRecipe(recipe); | |
} | |
} | |
} | |
update(); | |
var sess={}; | |
function showUI(player,name){ | |
var inv=server.createInventory(null,27,'Recipe'); | |
var ok=createItem(Material.WOOL,'\u00A7aOK','',5); | |
var none=createItem(Material.STAINED_GLASS_PANE,'\u00A78NONE','',7); | |
for(var i=0;i<27;i++){ | |
var im3=parseInt(i/3); | |
if(!(im3==1||im3==4||im3==7)){ | |
inv.setItem(i,none); | |
} | |
} | |
inv.setItem(16,ok); | |
player.openInventory(inv); | |
sess[player.getName()]=name; | |
} | |
command('addRecipe',function(params,sender){ | |
if(!isOp(sender))echo(sender,'\u00A74only op can use this command!'); | |
else{ | |
if(sender.getInventory().getItemInMainHand().getType()==Material.AIR)echo(sender,'need a item in hand to create recipe'); | |
else if(params.length<1)echo(sender,'\u00A74need recipe name to create'); | |
else{ | |
for(var i in store){ | |
if(store[i].name==params[0]){ | |
echo(sender,'\u00A74recipe name already exists.'); | |
break; | |
} | |
} | |
showUI(sender,params[0]); | |
} | |
} | |
}); | |
command('removeRecipe',function(params,sender){ | |
if(!isOp(sender))echo(sender,'\u00A74only op can use this command!'); | |
else{ | |
if(params.length<1)echo(sender,'\u00A74need recipe name to remove'); | |
else{ | |
for(var i in store){ | |
if(store[i].name==params[0]){ | |
store.splice(i,1); | |
echo(sender,'\u00A76Recipe Removed!'); | |
server.clearRecipes(); | |
update(); | |
return; | |
} | |
} | |
echo(sender,'\u00A74Recipe Not Found!'); | |
} | |
} | |
}); | |
events.inventoryClick(function(e){ | |
try{ | |
var player=e.getWhoClicked(); | |
var clicked=e.getCurrentItem(); | |
var inv=e.getInventory(); | |
if(inv.getName()=='Recipe'){ | |
var type=clicked.getType(); | |
if(type==Material.STAINED_GLASS_PANE){ | |
e.setCancelled(true); | |
} | |
if(type==Material.WOOL){ | |
e.setCancelled(true); | |
var chars=['A','B','C','D','E','F','G','H','I']; | |
var cc=0; | |
var map={};//Material -> char | |
var umap={}; | |
var shape=['','','']; | |
var s=3; | |
for(var l=0;l<=20;l+=10){ | |
for(var i=s;i<=s+2;i++){ | |
var idx=l+i; | |
var item=inv.getItem(idx); | |
if(item==null){ | |
shape[l/10]+=' '; | |
} | |
else if(!map[item.getType()]){ | |
umap[chars[cc]]=item.getType(); | |
map[item.getType()]=chars[cc++]; | |
shape[l/10]+=map[item.getType()]; | |
} | |
else{ | |
shape[l/10]+=map[item.getType()]; | |
} | |
} | |
s--; | |
} | |
var res=player.getInventory().getItemInMainHand(); | |
console.log(res); | |
var recipe=new ShapedRecipe(res); | |
recipe.shape(shape[0],shape[1],shape[2]); | |
for(var i in umap){ | |
recipe.setIngredient(i,umap[i]); | |
} | |
if(server.addRecipe(recipe)){ | |
echo(player,'\u00A76Recipe Added!'); | |
if(com.google.gson.Gson){ | |
var gson=new com.google.gson.Gson(); | |
var o={}; | |
o.name=sess[player.getName()]; | |
o.result=gson.toJson(res.serialize()); | |
o.shape=shape; | |
o.ingredient=[]; | |
for(var i in umap){ | |
o.ingredient.push({ch: i,material: umap[i].toString()}); | |
} | |
store.push(o); | |
} | |
} | |
player.closeInventory(); | |
} | |
} | |
}catch(e){ | |
} | |
}); | |
function createItem(material,name,lore,m) { | |
var item; | |
if(!m){ | |
item=new ItemStack(material,1); | |
} | |
else{ | |
item=new ItemStack(material,1,new java.lang.Byte(m)); | |
} | |
var meta=item.getItemMeta(); | |
meta.setDisplayName(name); | |
var Lore = new java.util.ArrayList(); | |
Lore.add(lore); | |
if(!lore)meta.setLore(Lore); | |
item.setItemMeta(meta); | |
return item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment