Updating Damaging Darkness

Discussion in 'Spigot Plugin Development' started by Omanoctoa, Jun 14, 2018.

  1. Hello Spigot!
    I'm not certain this is the correct place to ask this, but I'm not putting it in Recruitment yet. I'm using the spigot plugin DamagingDarkness - https://www.spigotmc.org/resources/damaging-darkness-anti-xray-solution.9137/ - to injure players as they enter lightless shadows. In this regards the plugin works great, but it has some major flaws. I've attempted to contact the dev in these regards to no avail, so I'm coming here.

    I'd like to mention I have no experience with plugin development but I'd be happy to learn if it fixes this problem. Just not sure what I need to look for. Any help would be appreciated.

    1) How would I go about adding a configuration option to toggle the message sent to players when they enter the darkness? Or could such a message be staggered so it only appears say, once every so many seconds instead of every time the player takes darkness damage?

    2) How do I add a custom death message for when a player dies from the darkness. I'm sure I could change the vanilla death message when falling into the void for this, but a separate one would be more helpful.

    3) Most importantly however... When a player is swimming, they take damage. This has huge implications as the moment a player goes underwater more than 1 block, they take damage. While this would be fine if it were deep under water, it doesn't work quite as well if someone simply jumps in a pond or their private swimming pool. Is it possible to set up a toggle in the config to cancel darkness damage in the water?

    Thanks in advance,
  2. 1. I think an easy, yet good way to achieve this would be to send the message as an action bar message. The action bar doesn't spam but just makes a text that seems to be static.
    2. Check if the player's health is 0 after damaging the player. If he is, add him to a collection and modify the death message in a PlayerDeathEvent listener if the collection contains the player who died.
    3. Just add a condition that prevents the player from getting damaged when the type of the block matching his location is water.
    • Agree Agree x 1
  3. Thanks for the advice. Again I know nothing about java programming but I know google. I've searched a bunch of threads and decompiled two class files but have no idea where to actually begin. However, I have deduced the line I need to add is
    Code (Text):
     && (player.getLocation().getBlock().getType() != Material.stationary_water))
    with the end result being...
    Code (Text):
                (player.getLocation().getY() <= DamagingDarkness.this.activeHeight) && (player.getLocation().getBlock().getLightLevel() <= DamagingDarkness.this.activeLightLevel) && (player.getGameMode() == GameMode.SURVIVAL)) && (player.getLocation().getBlock().getType() != Material.stationary_water))
    This makes sense but....now what do I do? I can't simply copy/paste because the new class file is full of error lines mixed in with encrypted code. It took me an hour to figure out how to decompile it to Read the code, and about 5 minutes to fix the problem (I hope).
  4. I wrote this so if it is the code you are looking for you can use it and edit what you want.. but test it to make sure there are no issues.
  5. Whoa. Thanks for this! What is the part about the aliases and creating commands? Is that necessary for adding non-vanilla commands?

    How do I implement this? As I said I have no (well, minimal now) java coding experience. Is this a class file on its own or would I replace the existing DamagingDarkness.class with this?

    Guess I need to look into compiling next eh? :D
  6. The thing with commands is that you can't just do something like Bukkit.registerCommand(new HelpCommand()), you need to put them in plugin.yml and then set your CommandExecutor but that is annoying so with reflection you can make yourself a method that will create and register command without needing to add it to plugin.yml, you can change/remove it if you want to...

    You can move the classes to separate files but you don't have to, all you need is: create new project in your IDE (if you haven't already), create your package (if you haven't already), create class named DD and copy-paste the code to it replacing the generated
    Code (Java):
    public class DD {

    If you have eclipse you can press Ctrl+Shift+O to "organize imports" and make sure you use bukkit imports.
    Then just create basic plugin.yml, compile it and it should work.

    Few notes:
    -the code is written the way it is because it is more readable for me, this might not be true for you so change it if it isn't
    -there are few issues:
    ~no custom death message
    ~if you type "/dd someRandomLetters" you won't get any message
    (these(down) might be intended)
    ~if player is outside at night he won't get damaged because getLightLevel returns block and sky light, use getBlockLight instead
    ~if player places and breaks torch or enters no darkness blocks, his "inDarknessSince" gets reset
  7. Aha. I figured that's what you were doing with those parts but hadn't gone over them in depth enough.

    Alright. that doesn't sound like too much of a headache. A couple questions:
    - The existing plugin.yml shows 2 permissions. Do I need to define all the permissions there, or are the defined permissions only to configure basic options like setting the permission to OP-only or to default?
    -Do I need to define commands in the same manner?
    -Can I use the original author's namespace or should I create my own? Will this cause problems?
  8. JanTuck


    Have you heard about ACF?
  9. Commands on their own aren't much trouble, though I see how this would be beneficial during the actual plugin development and compilation. For commands on their own, I use SimpleAlias. It is unmatched so far in terms of setting up commands in-game - https://dev.bukkit.org/projects/xsimplealias

    I know this was unrelated to your comment, just felt like mentioning it.
  10. I did look at the thread some time ago but i forgot about it.. For now, my method is good enough for me..
    I didn't look at the original resource, i just assumed what it does from the link name and your post..
    The class i posted is the whole plugin, you just need to make plugin.yml with main, name and version values since those are required and compile it.
    I also assumed you would edit it to be exactly what you want / you would look at the class as an example how it can be done and make your own.
    So learn atleast few basic things about java and then bukkit so you would be able to edit it and understand what it does.
    (tl;dr - learning more will answer your questions)

    And also a basic security tip: If you don't know what the software does then you shouldn't run it.
  11. Ah that explains why it looks so different from the original... I was wondering about that. Thanks even moreso.
    I've used some of the programs before, just never got anywhere. This is the furthest I've gotten. It helps having an example that I know how it works.

    Thanks for your help :)