Chat with Range/Muffling

Discussion in 'Archived: Plugin Requests' started by azalon99, Feb 10, 2014.

  1. Offline

    azalon99

    From what I've searched, I could not find a chat plugin suitable enough! Please correct me if I'm wrong!

    Plugin category: Chat

    Suggested name: ChatMuffler (Or anything, really)

    What I want: Hopefully my request is simple enough! I'm looking for a chat plugin for 1.7.2 that can give the chat two separate channels. One channel is global, and the other is local. Local would have volumes, or a hearing range. If you too far away from a player, or if there are blocks in the way, then only some of the message is shown.
    Example:
    "Hello I am here." is the normal message, but if you're too far, or there is an obstacle, it would become something like "H-ll- I a- her-."
    Some features (if possible) would be that the message is more garbled the farther away you are, and less garbled the closer you are. Also that the volume/range can be selected. (5 for a whisper, 10 is louder, 15 is average, and 20-25-30 are louder.)

    Ideas for commands: /channel local volume <#> , or /channel local range <#> to set the volume/range of the local channel. (/channel local v <#> perhaps?)
    /channel <channel name> or /local - /global to select a channel.

    Ideas for permissions: pluginname.channel.select to be able to choose a channel
    pluginname.channel.volume(or range) to be able to choose the volume/range

    When I'd like it by: I don't really know how long it takes to create a plugin, much less how long it would take to attempt this plugin, so maybe 1-2 weeks? Three if there are complications.
     
  2. Offline

    azalon99

    I'm still in need of this plugin! Any help would be appreciated!
     
  3. Offline

    JRL1004

    azalon99 This is actually not all that hard to do. For any dev that wants to take this (since I doubt I can find the time), here is how I would go about it:
    For the channels, monitor the AsyncPlayerChatEvent and use MetaData to store the channel the player is on (also incorporate a flatfile backup since Metadata could bug out or fail on reset (not sure why but I't happened to me). For the muffling, convert the sending and receiving player's locations to vectors then run a subtract method to get the vector pointing at the receiver and loop through the blocks (BlockIterator). Every X blocks replace a character (StringBuilder maybe?). At the end of the Iterator, convert the Stringbuilder to a string and send it to the receiver. Granted, this could cause a bit of lag on large servers, maybe use the getNearbyEntities method and just use the player's within that radius. Granted this isn't completely thought through but it is an idea for how it could be done.
     
  4. I'll definitely look into this if nobody else does, but not at the moment (I got projects for school :p)... The idea of JRL1004 seems like it could work, I'd do something like getting the distance between the players and then if the player is further than a defined radius, start adding a percentage of noise. Than each letter of the message has a chance to be replaced (defined by the noise).
     
  5. Offline

    azalon99

    bendem Thanks for looking into this for me! If possible, do you know when it'll be completed? There's no rush, I would just like to know.
     
  6. I don't really know... Maybe 2 or 3 weeks?
    Also, a friend of mine pointed out a way to go with the chat to not use commands.
    What do you think of something like instead of using a command like /shout, /whisp or /g, adding a symbol at the beginning of the message. Like say you want to shout "hello everybody", you type "+Hello everybody" (customizable) instead of "/shout Hello everybody" to keep the role play spirit.
    I can implement the 2 ways, just tell me your preference.
     
  7. Offline

    CoderCloud

    Just as a tipp, its faster to do this:
    Code:java
    1. Location loc = ?;
    2. int dist = ?;
    3. int d2 = dist*dist;
    4. int x = loc.x*loc.x+loc.y*loc.y+/*(loc.z*loc.z)*/;
    5. if(x>d2)
    6. /*Dont Send*/;
    7. else
    8. /*Send*/;

    instead of the code you used, because Math.sqrt and Math.pow are way slower than the default math operators.
     
    bendem likes this.
  8. Offline

    timtower Administrator Administrator Moderator

    CoderCloud Location.distance(otherlocation) ?
     
    bendem likes this.
  9. CoderCloud, Didn't know that java librairies were slower... Thanks for the advice!
    timtower, Thanks! I wasn't aware that it already existed...
     
    CoderCloud and timtower like this.
  10. Offline

    azalon99

    bendem Oh I like that symbol instead of command idea!
    Thanks everyone who has pitched in as well!
     
  11. Offline

    CoderCloud

    timtower The problem is, that if you use math.sqrt(), you are using way more computationpower, than it takes to just square the maximum distance allowed. You don't get the exact distance of the object, but you know, if its futher away than the distance you gave in.

    Also Math.pow() is a function like this:
    Code:java
    1. public int pow(int value, int pow) {
    2. int res = 1;
    3. for(;pow>0;pow--)
    4. res *= value;
    5. return res;
    6. }

    You can see, that this function is way slower than just this:
    Code:java
    1. public int square(int i) {
    2. return i*i;
    3. }


    Edit:
    I let my computer run both methods 5000 times in a row and checked how long it took:
    When i let both methods execute 1000000 times, Math.pow used '82524076ns' and just multiplying took '16361502ns', which is about 5 times more time for Math.pow(). (Its not much, but can make a diffrence, when a server is already at its limits)
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. I guess he's referencing to the fact that the api uses Math.sqrt which is slower than the method he gave.

    I don't think it's quite useful to use another method since it already implemented inside bukkit. If it has to be changed, it would also be better to change it inside bukkit itself. So if I ever got some optimization problem, I'll cook a bukkit PR instead of changing my code ;-)
    (Also, Bukkit use x*x...)
     
  14. azalon99, Just as an update, here is a first preview of the plugin... I still need to balance the default config and implement shout and whisper, but it's pretty close to done now ;-)

    (as always, keep in mind that the plugin has not been approved by bukkit and could still be buggy, bla... bla... bla... :p )
     
  15. Offline

    azalon99

    bendem Looks good so far! I can't wait for it to be finished! Thanks for all the work you've put into it!
     
  16. Offline

    ZodiacTheories

    azalon99

    This reminds me of the plugin used in UHC Season 14, did you get it from there?
     
  17. azalon99 There we go, Here's a first beta, the config may need adjustments but all the functionalities are in... If you can test it and let me know if anything goes wrong (I don't have many players to test it by myself)...

    By default, if you post a message, it uses the normal message type, if you post a message with a "+", it uses shout config, "-" is for whispering and "#" for the global chat.

    There is only one command : "/chatmuffler reload" To reload the config.
    Config informations are in the config.yml file :)

    Since I need testers, I also posted it on dev.bukkit.org.
     

Share This Page