Advertisement
fiveriverflow

YellCommand

Sep 3rd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.52 KB | None | 0 0
  1. package server.model.players.content.command.impl;
  2.  
  3. import org.jetbrains.annotations.NotNull;
  4. import server.Config;
  5. import server.model.players.DonatorRights;
  6. import server.model.players.Player;
  7. import server.model.players.PlayerSettings.PlayerSetting;
  8. import server.model.players.World;
  9. import server.model.players.content.command.Command;
  10. import server.model.players.content.command.CommandContainer;
  11. import server.model.players.content.command.CommandEntry;
  12. import server.model.players.content.world_events.double_drop_rate.ItemDonation;
  13. import server.model.players.content.world_events.double_drop_rate.TurtleDonation;
  14. import server.model.players.content.world_events.timed_events.ReactionBot;
  15. import server.net.discord.BotConfigurations;
  16. import server.net.discord.ImagineBot;
  17. import server.util.Misc;
  18.  
  19. import java.util.Arrays;
  20. import java.util.List;
  21.  
  22. public class YellCommandExecutor implements CommandContainer {
  23.  
  24.     private boolean canReceiveYell(final Player receiver, final Player sender) {
  25.         if (receiver.getPM().isIgnored(sender.getUsernameHash()) && !sender.getRights().isStaff())
  26.             return false;
  27.         return receiver.getSettings().isEnabled(PlayerSetting.DISPLAY_YELL_MESSAGES);
  28.     }
  29.  
  30.     private boolean canYell(Player c, @NotNull String text) {
  31.         if (!c.getSettings().isEnabled(PlayerSetting.DISPLAY_YELL_MESSAGES)) {
  32.             c.sendMessage("<col=44444444><shad=1>You currently have yell disabled.");
  33.             return false;
  34.         }
  35.         if (c.yellMute) {
  36.             c.sendMessage("<col=44444444><shad=1>You have been limited from using Yell.");
  37.             return false;
  38.         }
  39.         if (c.inJail() || c.isInJail() || c.Jail || System.currentTimeMillis() < c.jailEnd) {
  40.             c.sendMessage("<col=44444444><shad=1>You cannot yell while in jail.");
  41.             return false;
  42.         }
  43.         if (System.currentTimeMillis() < c.yellEnd) {
  44.             c.sendMessage("<col=44444444><shad=1>You are limited from using yell for "
  45.                     + (c.yellEnd - System.currentTimeMillis()) / 60000 + " more minutes.");
  46.             return false;
  47.         }
  48.         if (System.currentTimeMillis() < c.muteEnd) {
  49.             c.sendMessage("<col=44444444><shad=1>You are muted for " + (c.muteEnd - System.currentTimeMillis()) / 60000
  50.                     + " more minutes.");
  51.             return false;
  52.         }
  53.         if (c.getAttributes().is("muted")) {
  54.             c.sendMessage("<col=44444444><shad=1>You cannot yell while you are muted.");
  55.             return false;
  56.         }
  57.         if (!c.enoughPlaytime(6) && c.getNpcKills(-1) < 500 && !c.getRights().isStaff()
  58.                 && !c.getDonatorRights().isDonator()) {
  59.             c.sendMessage("<col=44444444><shad=1>Sorry, " + Misc.optimizeText(c.getDisplayName())
  60.                     + ", you must have 500 npc kills to yell. ");
  61.             return false;
  62.         }
  63.         int yellWait = c.getRights().isStaff() ? 0
  64.                 : c.getDonatorRights().equals(DonatorRights.DONATOR) ? 25000
  65.                 : c.getDonatorRights().equals(DonatorRights.EXTREME_DONATOR) ? 20000
  66.                 : c.getDonatorRights().equals(DonatorRights.SPONSOR) ? 15000 : 30000;
  67.         if (Config.limitedYell && System.currentTimeMillis() - c.YellTimer <= yellWait) {
  68.             c.sendMessage(
  69.                     "You must wait " + (yellWait / 1000 - Math.round(System.currentTimeMillis() - c.YellTimer) / 1000)
  70.                             + " seconds before you can yell again.");
  71.             return false;
  72.         }
  73.         String[] tags = text.split("@");
  74.         if (tags.length > 2) {
  75.             c.sendMessage("Alert##Yell Violation##Please refrain from using colors in yell.##250");
  76.             return false;
  77.         }
  78.         if (text.contains(c.playerPass) || text.contains(c.pin)) {
  79.             World.messageAllStaff(
  80.                     "<col=150>" + Misc.formatString(c.getDisplayName()) + " said his password/pin in Yell.", true);
  81.             c.sendMessage("<col=255>Please refrain from saying your password or pin.");
  82.             return false;
  83.         }
  84.         String[] bad = {"chalreq", "<trans", "<col", "<shad", "duelreq", "tradereq", ". com", "biz", ". net", ". org",
  85.                 ". biz", ". no-ip", "- ip", ".no-ip.biz", "no-ip.org", ".com", ".net", ".org", "no-ip", "****", "<",
  86.                 "is gay", "****", ". com", ". serve", ". no-ip", ". net", ". biz", "snitch", ".tv",
  87.                 "discord##40041p1r2o3m4o5", "forums##90243p5r4o3m2o1"};
  88.         for (String element : bad)
  89.             if (text.indexOf(element) >= 0) {
  90.                 c.sendMessage("Alert##Yell Violation##Please refrain from using: '" + element + "'##250");
  91.                 return false;
  92.             }
  93.         return true;
  94.     }
  95.  
  96.     private void displayAlert(Player c, @NotNull String text) {
  97.         String[][] keyWords = {
  98.                 {"what is update", "what is the update", "what's update?", "whats update", "update",
  99.                         "Check the '?' tab for the Latest Updates!"},
  100.                 {"upgrade", "heaven stone", "finest stone", "lucky ore", "lucky heaven stone", "lucky hs",
  101.                         "Try '::thread upgrade equipment' for more information on upgrading."},
  102.                 {"double drop rate", "check my dr", "check my drop rate", "whats my dr", "what is my dr",
  103.                         "what's my dr",
  104.                         "Type '::mydroprate' to check your drop rate and time left on double drop rate."},
  105.                 {"im new", "where to stat", "where do i start", "where start",
  106.                         "Check out '::ckey', '::gkey' if you're new. Thieve from stalls for easy money."},
  107.                 {"beta client", "where beta", "how beta",
  108.                         "A link to the Beta Player can be found above the Forums' chatbox."},
  109.                 {"stalls", "You can get to the thieving stalls by click on the Thieving skill in Skills Tab."},
  110.                 {"turtle box", "Turtle boxes can be obtained from '::turtle', they give a random Turtle Piece."},
  111.                 {"f game", "game suck", "Yeah fuck you too mate. Feel free to click the 'X' button."},
  112.                 {"donation well", "item well", "item donation", "where well", "how well", "location well",
  113.                         "The donation well is located on the south-east side of home. Total Donated: "
  114.                                 + Misc.format(World.getAttributes().getLong(ItemDonation.DONATED)) + "B"},
  115.                 {"scroll of e", "efficiency scroll", "rol scroll", "row scroll",
  116.                         "Scroll of efficiency provides 0 to 10% extra DRB when used on LRoL and RoW."},
  117.                 {c.getDisplayName(), "That's your name, don't ware it out homie."},
  118.                 {"teleport lag", "slow teleport", "loading screen", "freeze", "tele lag", "lag tele",
  119.                         "If you're experiencing long loading screen times, please restart client."},
  120.                 {"conversion", "convert", "osgp", "rs3gp",
  121.                         "'::osrsconvert' & '::rs3convert' are conversion commands you can use."},
  122.                 {"turtle stone", "turtle donat", "stone donat",
  123.                         "There are currently " + Misc.format(World.getAttributes().getInt(TurtleDonation.DONATED))
  124.                                 + " turtle stones donated. Get them at '::turtle'."},
  125.                 {"gambling pass", "gamble pass", "Gambling Pass can be obtained from the Donation Store."},
  126.                 {"discord", "voice chat", "voice c", "v chat", "Type '::discord' to access discord."},
  127.                 {"yell color", "option", "yell level", "yell extra", "[level", "extra yell",
  128.                         "Yell options can be accessed by clicking 'More Options' in 'Options'."},
  129.                 {"row", "ring of w", "Ring of Wealth gives 10% drop rate bonus. Do '::mydroprate' to check."},
  130.                 {"broken drop rate", "Drop rates", "Drop rates are not 'broken', I promise."},
  131.                 {"paper", "sonic ring", "gold ring", "hell powder", "This item is used to upgrade Dragon Square."},
  132.                 {"best food", "top food", "Food (Class #) heals the most while Bandages have a limited supply on singular item."},
  133.                 {"long double", "time double", "Double Potions last for 30 minutes and have 1 use."},
  134.                 {"gadorx", "We are not GadorX. We are Imagine-PS, where anything you imagine comes true."},
  135.                 {"turtle", "Only turtles we allow exist at '::turtle'."},
  136.                 {"hydra", "Yeah... you'll have to use your imagination to make that come true."},
  137.                 {"pet ninja", "ninja pet", "Ninja pet makes thieving 100% more successful. (Not 100% successful)"},
  138.                 {"pet vorago", "vorago pet", "Vorago Pet has a 10% chance of doubling your max hit, next hit."},
  139.                 {"pet corp", "corp pet", "corporeal pet", "corporeal beast pet",
  140.                         "Corporeal Pet has a 10% chance to reduce next damage taken by 50%."},
  141.                 {"pet prestige", "prestige pet", "p pet",
  142.                         "Prestige Pet has a 10% chance to do maximum damage (::maxhit) next hit."},
  143.                 {"pet td", "pet tormented", "tormented pet", "tormented demon pet", "td pet", "tds pet",
  144.                         "Tormented Demon Pet gives 15% DRB towards Tormented Demons."},
  145.                 {"pet pika", "pikachu pet", "pika pet",
  146.                         "Pikachu pet gives 10% DRB, if you're under 5,000 NPC Kills, 5% otherwise."},
  147.                 {"pet raic", "raichu pet", "raic pet",
  148.                         "Raichu pet gives 10% DRB if NPC Kills < 5k, 7% DRB if NPC Kills < 10k, 5% otherwise."},
  149.                 {"vet'ion pet", "pet vet", "vetion pet",
  150.                         "Vet'ion pet makes special recover 2 times as fast as usual."},
  151.                 {"celestial pet", "pet cel", "celes pet", "celest pet", "celestial dragon pet",
  152.                         "celestial dragon (pet)", "Celestial Pet increases experience gained by Bone Crusher by 2x."},
  153.                 {"warped terrorbird pet", "warped pet", "terrorbird pet",
  154.                         "Warped Terrorbird pet cuts all prayer drainage in half."},
  155.                 {"veteran", "To obtain the veteran rank, you need an account 9+ months old & 30+ days playtime."},
  156.                 {"hell key", "hell chest",
  157.                         "Hell keys are used to open Hell Chests which are also dropped by monsters."},
  158.                 {"rare drop", "Type '::raredrops NPC NAME' to check rare drops of an NPC."},
  159.                 {"drop potential", "Type '::thread Drop Potential' to learn more about Drop Potential."},
  160.                 {"imagination", "You're gonna need that... lmfao. Sad."},
  161.                 {"price c", "check price", "price of", "how much are", "how much is",
  162.                         "Type '::pc NAME' or right click an item to check its price."},
  163.                 {"tired", "bored", "You're not tired/bored man the FUCK up."},
  164.                 {"server is nice", "server is cool", "server is awesome", "server is great",
  165.                         "The server loves you very much."},
  166.                 {"max skill", "The max skill level is 125."},
  167.                 {"ice diamond", "Ice diamond is used to fix a Lucky Ring of Life [Damaged]"},
  168.                 {"guardian", "Talk to Aggressive Mage at home to start the Guardian Assault/Resistance"},
  169.                 {"immortal", "Type ::thread topic 3017 to learn about Immortal Band/Charm"},
  170.                 {"req", "Type ::req to show you the list of Requirements."},
  171.                 {"drop Catcher", "Type ::thread topic 2557 to learn about Drop Catchers."},
  172.                 {"buffs", "Buffs come from Admin+, click the icon to view benefits."},
  173.                 {"gear", "Type ::thread topic 2930 for the Gear Guide."},
  174.                 {"start", "Type ::thread topic 3012 for the Starter Guide."},
  175.                 {"minigame", "Type ::thread topic 2902 for the Korasi Minigame."},
  176.                 {"trophy", "Talk to Mr.Trophy in varrock to claim trophies."},
  177.                 {"milestone", "King Milestone is located in varrock, trade him required pieces."},
  178.                 {"pet", "Type ::thread topic 1977 for the Pet Effect Guide."},
  179.                 {"ss", "Type ::thread topic 1444 for the Spirit Shield Effects guide."},
  180.                 {"attendance", "Talk to king milestone to learn about Attendance."},
  181.                 {"drop potential", "Type ::thread topic 1449 to learn about Drop Potential."},
  182.                 {"auction", "The auctioneer is loacted north east at home."},
  183.                 {"vote", "Type ::vote to vote, and ::redeem to claim your votes."},
  184.                 {"thread", "Type ::thread topic #### to open a thread "},
  185.                 {"benefits", "Type ::thread donor benefits to view Donator benefits."},
  186.                 {"staff", "feedback", "leave your staff feedback by typing ::thread topic 3109"}
  187.  
  188.         };
  189.         keyWords:
  190.         for (int i = 0; i < keyWords.length; i++)
  191.             for (int j = 0; j < keyWords[i].length - 1; j++)
  192.                 if (text.indexOf(keyWords[i][j]) > -1) {
  193.                     c.sendMessage("Alert##Yell Assistance##" + keyWords[i][keyWords[i].length - 1] + "##250");
  194.                     break keyWords;
  195.                 }
  196.  
  197.         for (String inapporpriate : Config.inappropriate)
  198.             if (text.toLowerCase().contains(inapporpriate))
  199.                 c.sendMessage(
  200.                         "Alert##Yell Violation##Please refrain from using: '" + inapporpriate + "' in yell.##250");
  201.  
  202.     }
  203.  
  204.     @NotNull
  205.     @Override
  206.     public List<Command> execute() {
  207.         return Arrays.asList(new Command("yell", "Yell command") {
  208.             @Override
  209.             public void execute(@NotNull Player player, @NotNull CommandEntry command) {
  210.                 try {
  211.                     if (command.getArguments().length() < 1)
  212.                         return;
  213.  
  214.                     final String text = command.getArguments();
  215.  
  216.                     if (!canYell(player, text))
  217.                         return;
  218.  
  219.                     player.YellTimer = System.currentTimeMillis();
  220.  
  221.                     displayAlert(player, text);
  222.  
  223.                     String yellColor = getYellColor(player);
  224.  
  225.                     String yellRank = player.getRights().toString();
  226.  
  227.                     if (player.getDisplayName().equalsIgnoreCase("moon")) {
  228.                         yellRank = "Administrator";
  229.                     }
  230.  
  231.                     if (!player.getRights().isStaff() || player.getRights().isSuper())
  232.                         if (player.getDonatorRights().isDonator())
  233.                             if (player.getDonatorRights().isSuperiorOrEqual(DonatorRights.SPONSOR)) {
  234.                                 if (!player.customYellTag.equalsIgnoreCase("Default Tag")
  235.                                         && !player.customYellTag.isEmpty())
  236.                                     yellRank = player.customYellTag;
  237.                                 else
  238.                                     yellRank = player.getDonatorRights().toString();
  239.                             } else
  240.                                 yellRank = player.getDonatorRights().toString();
  241.  
  242.                     yellRank = yellRank.replaceAll("ADMINISTRATOR", "Admin").replaceAll("MODERATOR", "Mod")
  243.                             .replaceAll("EXTREME", "E").replaceAll("LEGENDARY", "L")
  244.                             .replaceAll("SUPER", "S").replaceAll("DIVINE", "D");
  245.  
  246.                     boolean displayExtras = player.getSettings().isEnabled(PlayerSetting.DISPLAY_YELL_EXTRAS);
  247.                     boolean displayLevel = player.getSettings().isEnabled(PlayerSetting.DISPLAY_YELL_LEVEL);
  248.  
  249.                     String yellExtras = !displayExtras ? ""
  250.                             : (player.getNpcKills(-1) > 1000
  251.                             ? !displayLevel ? "[" + Misc.format(player.getNpcKills(-1)) + " KC]"
  252.                             : "[Level " + player.getNpcKills(-1) / 1000 + "]"
  253.                             : "") + (player.prestige > 0 ? "[P" + player.prestige + "]" : "");
  254.  
  255.                     String yellTitle = player.getCrownsAsString() + yellExtras
  256.                             + (!yellRank.isEmpty() ? "[" + Misc.formatString(yellRank) + "]" : "");
  257.  
  258.                     String yellMessage = modifiedYell(player, text, false);
  259.  
  260.                     if (ReactionBot.isRunning()
  261.                             && ReactionBot.getString().startsWith("bot")
  262.                             && command.getArguments().startsWith("bot")) {
  263.                         ReactionBot.rewardPlayer(player, command.getArguments());
  264.                     }
  265.  
  266.                     World.getPlayerStream().filter(p -> canReceiveYell(p, player))
  267.                             .forEach(i -> {
  268.                                 String title = yellTitle;
  269.                                 if (!i.getAttribute("toggleyelltitle", false)) {
  270.                                     title = "[" + player.getCrownsAsString() + "]";
  271.                                 }
  272.                                 i.getPacketSender().sendYell(
  273.                                         (i.getAttribute("toggleyellcolor", true) ? yellColor : "") + title,
  274.                                         Misc.formatString(player.getDisplayName()),
  275.                                         yellMessage);
  276.                             });
  277.  
  278.                     if (!Config.limitedDiscord) {
  279.                         String discordMessage = modifiedYell(player, text, true);
  280.                         ImagineBot.sendMessage(player.getDisplayName(), discordMessage, ImagineBot.Type.YELL);
  281.                     }
  282.  
  283.                     player.getAttributes().set("discord_yell", false);
  284.  
  285.                 } catch (Exception e) {
  286.                     e.printStackTrace();
  287.                 }
  288.             }
  289.         });
  290.     }
  291.  
  292.     private String getYellColor(Player player) {
  293.         switch (player.getRights()) {
  294. //      case OWNER:
  295. //          return "<shad=FF90DB>";
  296.             case ADMINISTRATOR:
  297.                 return "<shad=FF7373>";
  298.             case MODERATOR:
  299.                 return "<shad=00C5FF>";
  300.             case SUPPORT:
  301.                 return "<shad=48AEFF>";
  302.             default:
  303.                 return player.yellColor;
  304.         }
  305.     }
  306.  
  307.     private String modifiedYell(@NotNull Player c, String text, boolean discord) {
  308.         text = text.toLowerCase();
  309.         if (discord) {
  310.             for (String bad : BotConfigurations.PROHIBITED_WORDS) {
  311.                 text = text.replaceAll(bad, "");
  312.             }
  313.             for (Player player : World.getPlayers()) {
  314.                 if (player != null) {
  315.                     if (text.indexOf(player.getDisplayName().toLowerCase()) > -1
  316.                             && player.getAttributes().get("discord_user") != null
  317.                             && !((String) player.getAttributes().get("discord_user")).isEmpty()) {
  318.                         if (player.getAttributes().get("discord_user") == null)
  319.                             break;
  320.                         if (ImagineBot.getApi()
  321.                                 .getUsersByName(((String) player.getAttributes().get("discord_user")).substring(
  322.                                         0, ((String) player.getAttributes().get("discord_user")).indexOf("#")),
  323.                                         true).size() > 0)
  324.                             text = text.replaceAll("@" + player.getDisplayName().toLowerCase(),
  325.                                     ImagineBot.getApi()
  326.                                             .getUsersByName(((String) player.getAttributes().get("discord_user")).substring(
  327.                                                     0, ((String) player.getAttributes().get("discord_user")).indexOf("#")),
  328.                                                     true)
  329.                                             .get(0).getAsMention());
  330.                     }
  331.                 }
  332.             }
  333.             return text;
  334.         }
  335.         String[] names = new String[5];
  336.         int name = 0;
  337.         boolean start = false;
  338.         try {
  339.             players:
  340.             for (int j = 0; j < World.getPlayers().capacity(); j++)
  341.                 if (World.getPlayer(j) != null)
  342.                     if (text.toLowerCase().indexOf(World.getPlayer(j).getDisplayName().toLowerCase()) > -1) {
  343.                         int index = text.toLowerCase().indexOf(World.getPlayer(j).getDisplayName().toLowerCase());
  344.                         if (index == 0 || !text.substring(index - 1, index).equalsIgnoreCase("@"))
  345.                             break;
  346.                         else {
  347.                             text = text.split("@")[0] + text.split("@")[1];
  348.                             index--;
  349.                         }
  350.                         if (index == 0)
  351.                             start = true;
  352.                         int length = World.getPlayer(j).getDisplayName().toLowerCase().length();
  353.                         if (index > 0 && text.charAt(index - 1) != ' ' || index + length != text.toLowerCase().length()
  354.                                 && text.toLowerCase().charAt(index + length) != ' '
  355.                                 && text.toLowerCase().substring(index + length, index + length + 1)
  356.                                 .matches("[a-zA-Z]+(?:'[a-zA-Z]+)*"))
  357.                             continue;
  358.                         names[name] = World.getPlayer(j).getDisplayName().toLowerCase();
  359.                         name++;
  360.                         if (World.getPlayer(j) != c)
  361.                             World.getPlayer(j).sendMessage(
  362.                                     "<col=255>" + Misc.formatString(c.getDisplayName()) + " said your name in Yell.");
  363.                         break players;
  364.                     }
  365.         } catch (Exception e) {
  366.             e.printStackTrace();
  367.         }
  368.         text = Misc.optimizeText(text);
  369.         if (start)
  370.             text = text.substring(0, 1).toLowerCase() + text.substring(1);
  371.         for (String name2 : names) {
  372.             if (name2 == null)
  373.                 continue;
  374.             if (name2.length() < 1)
  375.                 continue;
  376.             text = text.replace(name2, "'" + Misc.formatString(name2) + "'");
  377.         }
  378.         if (text.indexOf(":") > 0) {
  379.             String[] parts = text.split(":");
  380.             text = "";
  381.             for (int p = 0; p < parts.length; p++) {
  382.                 if (p != 0)
  383.                     parts[p] = Misc.optimizeText(parts[p]);
  384.                 text += parts[p] + (p != parts.length - 1 ? ":" : "");
  385.             }
  386.         }
  387.         if (text.indexOf("`") > -1) {
  388.             text += " ";
  389.             for (int z = 0; z < text.length(); z++)
  390.                 if (text.charAt(z) == '`') {
  391.                     String s1 = text.substring(z + 1, z + 2).toUpperCase();
  392.                     text = text.substring(0, z) + s1 + text.substring(z + 2);
  393.                 }
  394.         }
  395.         if (text.toLowerCase().indexOf("ree") > -1) {
  396.             String[] words = text.split(" ");
  397.             for (String word : words) {
  398.                 if (word.toLowerCase().startsWith("ree") || word.toLowerCase().contains("reee"))
  399.                     text = text.replaceAll(word, "");
  400.             }
  401.         }
  402.         return text;
  403.     }
  404.  
  405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement