[LIB] PrettyScaryLib

Discussion in 'Resources' started by stirante, Nov 9, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    aviator14

    Ok, I'll fork and submit as I find issues. I haven't even had time to use this yet D:
     
  2. stirante I'm looking for a way to block the placement of a block if is has a certain name. Any suggestions?
     
  3. Offline

    stirante

    Check PlayerInteractEvent. If in hand is block and has a name cancel event.
     
  4. Oh lol, that was easy. I was trying to do it with the BlockPlaceEvent - silly me. Thanks! :)
     
  5. Offline

    stirante

    Code updated and formatted. Now works with packages like:
    net.minecraft.server.v1_4_5.NBTTagCompound
     
    TfT_02 likes this.
  6. Offline

    monstuhs

    Thanks for this. However, I get this error when I try to addLore to an item:

    Show Spoiler
    12:18:19 [WARNING] Failed to handle packet for monstuhs/127.0.0.1: java.lang.Ill
    egalArgumentException: Empty string not allowed
    java.lang.IllegalArgumentException: Empty string not allowed
    at net.minecraft.server.v1_4_5.NBTTagString.<init>(SourceFile:15)
    at net.minecraft.server.v1_4_5.NBTTagString.clone(SourceFile:39)
    at net.minecraft.server.v1_4_5.NBTTagList.clone(SourceFile:87)
    at net.minecraft.server.v1_4_5.NBTTagCompound.clone(NBTTagCompound.java:
    244)
    at net.minecraft.server.v1_4_5.NBTTagCompound.clone(NBTTagCompound.java:
    244)
    at net.minecraft.server.v1_4_5.ItemStack.cloneItemStack(ItemStack.java:2
    32)
    at net.minecraft.server.v1_4_5.ItemStack.b(ItemStack.java:259)
    at net.minecraft.server.v1_4_5.NetServerHandler.a(NetServerHandler.java:
    708)
    at net.minecraft.server.v1_4_5.Packet15Place.handle(SourceFile:58)
    at net.minecraft.server.v1_4_5.NetworkManager.b(NetworkManager.java:290)
    at net.minecraft.server.v1_4_5.NetServerHandler.d(NetServerHandler.java:
    113)
    at net.minecraft.server.v1_4_5.ServerConnection.b(SourceFile:39)
    at net.minecraft.server.v1_4_5.DedicatedServerConnection.b(SourceFile:30
    )
    at net.minecraft.server.v1_4_5.MinecraftServer.r(MinecraftServer.java:59
    5)
    at net.minecraft.server.v1_4_5.DedicatedServer.r(DedicatedServer.java:22
    2)
    at net.minecraft.server.v1_4_5.MinecraftServer.q(MinecraftServer.java:49
    3)
    at net.minecraft.server.v1_4_5.MinecraftServer.run(MinecraftServer.java:
    426)
    at net.minecraft.server.v1_4_5.ThreadServerApplication.run(SourceFile:85
    6)
    12:18:19 [WARNING] Failed to save player data for monstuhs
    >


    Here's my code (please note, adding the name works great, I only get this error when adding Lore):
    Code:
                ItemStack heldItem = wizard.getItemInHand();
                if(heldItem.getType() == Material.BLAZE_ROD){
                    Namer.setName(heldItem, "Fire Staff");          
                    Namer.addLore(heldItem, "Even novice wizards know how to sling fire at their enemies");
                    wizard.setItemInHand(heldItem);
                }
     
  7. Offline

    hawkfalcon

    Fireworks? :O
     
  8. Offline

    Chlorek

    Very usable, I just needed that in my current project! I love you man!
     
  9. Offline

    stirante

    Fixed :) (problem was in new NBTTagString(), it was new NBTTagString(name), should be new NBTTagString("", name))

    Added Custom recipes. It allows adding recieps which gives player item with NBT tags.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  10. Offline

    bobacadodl

    Thanks a lot! This is great!
     
  11. Offline

    stirante

    Added EnchantGlow class which allows adding enchant-like glow to items and javadocs for all new classes.
     
    monstuhs likes this.
  12. Offline

    monstuhs

    Ownage
     
  13. Offline

    iTidez

    Question stirante

    Can I say apply PotionEffectType.NIGHT_VISION to a beacon block? I try and it just resets it back to default settings.
     
  14. Offline

    chasechocolate

    Amazing job. Thanks! :cool:
     
  15. Offline

    Tux2

    Excellent work! As it seems you didn't have an interest in posting your work to bukkit dev I decided to include the classes (with some minor edits) in my new TuxTwoLib. http://dev.bukkit.org/server-mods/tuxtwolib/ (I also changed the licensing on it from all rights reserved to LGPL 3)

    That way users can use the classes without having to include them with their project, or so that they don't have to compile for every version of Minecraft.
     
  16. Offline

    stirante

    I should work, but I haven't tested it much.
     
  17. Offline

    iTidez

    Let me describe what happens when I run this and all the extra steps I have tried:

    1. Defined a beacon command that utilizes every method in the beacon helper.
    2. Called a setPrimaryEffect() on /beacon setpeffect <effect> (/beacon setpeffect NIGHT_VISION)
    3. Called a setActive() on /beacon on
    1. Called a setActive() on /beacon on
    2. Called a setPrimaryEffect on /beacon setpeffect <effect>
    When I call setActive() it doesn't allow the method to run correctly. I defined a player.sendMessage(); to run before the arguments are even called and whenever I use a BeaconHelper.setActive(block, <true/false>); the whole method doesn't run and I don't get the message, however there is no error called and no stack trace given. The beacon does nothing and the player gets nothing. When I call the setPrimaryEffect(PotionEffectType.NIGHT_VISION); and do a check with the following code:
    Code:
    PotionEffectType pet = PotionEffectType.getFromString(arg2);//Note i forgot the actual method used here but its something like this
    BeaconHelper.setPrimaryEffect(targetB, pet);
    if(BeaconHelper.getPrimaryEffect(targetB) == pet) {
    player.sendMessage(ChatColor.GREEN+"Applied "+pet.toString()+" to beacon block!");
    } else {
    player.sendMessage(ChatColor.RED+"Error applying "+pet.toString+" to beacon block!");
    }
    The code passes and I get the 2 messages sent to the player. However if the beacon's effects are reset and you have to put in the item and activate from the GUI which can't be done as you have to select one of the defined effects. Perhaps there is a problem in the setActive() method, or perhaps you can only do it with the defined effects for beacons. If you can figure out a workaround, it would be much appreciated! I am trying to work on a huge stage for my server for concerts and there is too much space to consider lighting it all. I could always just define if a player walks into this area, the specified effect is applied but I want something simple with beacons acting as spotlights.

    Hope this clears things up and helps you out a bit!
     
  18. Offline

    stirante

    Removed some classes and functions implemented in newest bukkit. Code updated to recommended build.
     
  19. Offline

    NinjaW0lf

    stirante or anyone else.
    Ive been trying to add the enchant glow to a block, but it doesnt show up.
    i also tested it with a d sword, no work.

    Code:java
    1.  
    2. public void test(Player player) {
    3. ItemStack bomb = new ItemStack(Material.OBSIDIAN);
    4. ItemStack test = new ItemStack(Material.DIAMOND_SWORD);
    5. addGlow(test);
    6. addGlow(bomb);
    7.  
    8. player.getInventory().addItem(bomb);
    9. player.getInventory().addItem(test);
    10. }
    11.  


    and im using your latest method.
    straight from github

    Code:java
    1.  
    2. public static ItemStack addGlow(ItemStack item) {
    3. net.minecraft.server.v1_4_5.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
    4. NBTTagCompound tag = null;
    5. if (!nmsStack.hasTag()) {
    6. tag = new NBTTagCompound();
    7. nmsStack.setTag(tag);
    8. }
    9. if (tag == null) tag = nmsStack.getTag();
    10. NBTTagList ench = new NBTTagList();
    11. tag.set("ench", ench);
    12. nmsStack.setTag(tag);
    13. return CraftItemStack.asBukkitCopy(nmsStack);
    14. }
    15.  
     
  20. Offline

    Uniclaw

    Your a genius. Nothing more to say :D
     
  21. Offline

    ftbastler

    Should be a part of the BukkitAPI. Do it! :)
     
  22. Offline

    stirante

    I'll try to fix it. I haven't done anything tested on newest version of bukkit.
     
  23. Offline

    doomboy00

    Firstly, stirante you are awesome! Great code library :)
    Found glow the other day and am loving it, also just updated to 1.4.6 dev build and got the same problem, I overcame it by changing
    Code:
    return CraftItemStack.asBukkitCopy(nmsStack);
    to
    Code:
    return CraftItemStack.asCraftMirror(nmsStack);
    My guess is that asBukkitCopy is stripping some 'unused' stuff, where as asCraftMirror is doing as it says and mirroring it exactly, could be wrong, but hey that fixes it :)
     
    stirante likes this.
  24. Offline

    stirante

    Thanks :D
     
  25. Offline

    NinjaW0lf

    tested again with the new code and again didnt work on sword.
    am i doing something wrong ? :D
     
  26. Offline

    doomboy00

    From your code posted earlier try
    Code:
    test = addGlow(test);
    So with your previously posted code:
    Code:
    public void test(Player player) {
            ItemStack bomb = new ItemStack(Material.OBSIDIAN);
            ItemStack test = new ItemStack(Material.DIAMOND_SWORD);
            test = addGlow(test);
            bomb = addGlow(bomb);
     
            player.getInventory().addItem(bomb);
            player.getInventory().addItem(test);
    }
    I'm not at my home computer right now so could be wrong, but give it a go and i'll test it when I get back tonight if that doesn't work.
     
  27. Offline

    hice3000

    Under which license can I release projects that use this lib?
     
  28. Offline

    stirante

    Any license that you like :D, but it would be nice if you'll credit me :).

    Unfortunately I haven't much time to test every class in lib.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  29. Offline

    hice3000

    Ok, sure i will notice you in the plugin!
     
Thread Status:
Not open for further replies.

Share This Page