Snowball FFA plugin

Discussion in 'Archived: Plugin Requests' started by ShadowRaidNET, Nov 27, 2013.

?

Would you like this plugin on your server too?

  1. Yes

    0 vote(s)
    0.0%
  2. No

    2 vote(s)
    100.0%
  1. Offline

    ShadowRaidNET

    Plugin category: Fun

    Suggested name: SnowballFun

    What I want: When you hit someone else with a snowball you get a point! In chat everytime you hit someone with a snowball it will say "&cYou have hit &6%player &cand received a point! You now have &6%amount &cpoints!" And when you get hit... it says "&cYou have been hit with a snowball by &6%player&c!" This plugin should work throughout the server.

    Ideas for commands: /toplist | This will show who has the most points a player has

    Ideas for permissions: snowball.player | This allows them to to the following above.

    When I'd like it by: Two weeks before christmas :)
     
  2. Offline

    ShadowRaidNET

  3. This can be done using a plugin called Skript. There is already a script on the Skript forums for paintball. You can just modify it slightly and use it.
     
  4. Offline

    blablubbabc

  5. Offline

    jakeyray18

    I actually made a plugin very similar to this for someone else, I am sure I could modify it for your needs if you still need it?
     
  6. Offline

    beaudigi

    I could make ths using SKRIPT (im pro at that ) but when it comes to java :D im still elarning, I may try complete this project
     
  7. Offline

    PieMan456

  8. Offline

    ShadowRaidNET

    That would be wonderful! PieMan456
     
  9. Offline

    PieMan456

    @ShadowRaidNETok I won't be able to start it until Thursday because I am away right now. If anyone else can do this before me please go ahead.

    ShadowRaidNET
    Last post. Look up.
     
  10. Offline

    PieMan456

    ShadowRaidNET
    I don't know how to get the top player but if anyone else wants to do this here is all the other stuff besides getting the top player
    Code:
    Code:java
    1. package me.pieman.sfun;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.ProjectileHitEvent;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class SnowballFun extends JavaPlugin implements Listener{
    13.  
    14.  
    15. public void onEnable(){
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. saveConfig();
    18. }
    19.  
    20. public void onDisable(){
    21. saveConfig();
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerJoin(PlayerJoinEvent e){
    26. Player p = e.getPlayer();
    27. if(getConfig().get("points." + p.getName()) == null){
    28. getConfig().set("points." + p.getName(), 0.0);
    29. return;
    30. }
    31. }
    32.  
    33. @EventHandler
    34. public void onProjectileHit(ProjectileHitEvent e){
    35. if(e.getEntity().getShooter() instanceof Player && e.getEntity() instanceof Player){
    36. Player shooter = (Player) e.getEntity().getShooter();
    37. Player hurt = (Player) e.getEntity();
    38. if(!(shooter.hasPermission("snowball.player"))) return;
    39. int points = getConfig().getInt("points." + shooter.getName());
    40. getConfig().set("points." + shooter.getName(), points + 1);
    41. shooter.sendMessage(ChatColor.RED + "You have hit " + hurt.getName() + " and received a point!"
    42. + ChatColor.RED + " You now have " + ChatColor.RED
    43. + getConfig().getInt("points." + shooter.getName()) + ChatColor.RED + " points!");
    44. hurt.sendMessage(ChatColor.RED + "You have been hit with a snowball by " + shooter.getName() + "!");
    45. saveConfig();
    46. return;
    47. }
    48. }
    49. }
    50.  

    plugin.yml:
    Code:
    name: SnowballFun
    main: me.pieman.sfun.SnowballFun
    version: 1.0
    author: PieMan456
    permissons:
      snowball.player:
        default: true
     
  11. Online

    timtower Administrator Administrator Moderator

    PieMan456 Untested code:
    Code:java
    1. public String topPlayer(){
    2. Set<String> keys = getConfig().getConfigurationSection("points").getKeys(false);
    3. String currentRecord = "";
    4. int currentPoints = -1;
    5. for(String key:keys){
    6. if(getConfig().getInt("points."+key)>currentPoints){
    7. currentPoints = getConfig().getInt("points."+key);
    8. currentRecord = key;
    9. }
    10. }
    11. return currentRecord;
    12. }
     
  12. Offline

    blablubbabc

    PieMan456
    You could improve that by not saving the stats back to file on each snowball hit, but cache all player stats (from online players) and write changes back every once and a while.
    For getting the top player you could go through all players, one by one, and if you have no "suggested" player yet, or the player has more points than your last "top" player, you overwrite your "top" player with the new, current player you are looking at. Pseudo code:
    bestPlayer = null;
    bestPlayerPoints = 0;
    for (String player : allPlayers) {
    if (bestPlayer == null || getPointsOf(player) > bestPlayerPoints) {
    bestPlayer = player;
    bestPlayerPoints = getPointsOf(player);
    }
    }
    return bestPlayer;

    Edit: ninja'd
     
  13. Offline

    PieMan456

  14. Online

    timtower Administrator Administrator Moderator

    blablubbabc That was a damn long ninja :p
    And right about the cashing, prefer using hashmaps for that, and if I want to store multiple vars for players in different worlds: hashmap in a hashmap in a hashmap :p ( world, player, value )
    int points = getConfig.getInt("points."+topPlayer());
     
  15. Offline

    ShadowRaidNET

  16. Offline

    Ender_Mouse

    i like this but there needs to be a cooldown inbetween a hit and the next on the same player cause without that people would just spam snowballs at some whos afk
     

Share This Page