1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How CE was made

Discussion in 'Plugins and Coding' started by HangarGeek, Jul 23, 2016.

  1. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
    Hi. This is a way to explain a simple (chat) filter with few mor utilities.
    I will explain this:
    Code:
    package ChatEssentials;
    
    import java.util.List;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_9_R1.PacketPlayOutTitle;
    import net.minecraft.server.v1_9_R1.PacketPlayOutTitle.EnumTitleAction;
    import net.minecraft.server.v1_9_R1.PlayerConnection;
    
    public class Main extends JavaPlugin implements Listener {
    
        public final Logger logger = Logger.getLogger("Minecraft");
    
        public static String chatcolor(String s){
            return ChatColor.translateAlternateColorCodes('&', s);
       
            }
    
        @EventHandler(priority=EventPriority.HIGHEST)
        public void handleJoin(PlayerJoinEvent event)
        {
            Player p = event.getPlayer();
            event.setJoinMessage(chatcolor(getConfig().getString("WelcomeMessage")));
       
        }
    
        List<String> blockedMessages = getConfig().getStringList("Blacklist");
    
        @EventHandler
        public void playerChatEvent(AsyncPlayerChatEvent event) {
    
        for (String blockedMessage : blockedMessages) {
        if(event.getMessage().contains(blockedMessage)) {
        event.setCancelled(true);
        event.getPlayer().sendMessage("" + ChatColor.RED + ChatColor.BOLD + getConfig().getString("BlockedMessageERROR") );
        return;
        }
        }
        }   
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    
        public void onDisable()
        {
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
            Player player = (Player)sender;
           if (cmd.getName().equalsIgnoreCase("bc"))
                if (player.hasPermission("CE.Broadcast")) {
                int laengeArray = args.length;
                int indexArray = 0;
                String text = "";
                for (int i = 0; i < args.length; i++) {
                    text = text + args[i] + " ";
                }
            Bukkit.broadcastMessage(ChatColor.DARK_RED + "[Alert] " + ChatColor.RED + text);
            return true;
           }
    
        if (cmd.getName().equalsIgnoreCase("ChatEssentials")) {
            player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------");
            player.sendMessage(ChatColor.BLUE + "ChatEssentials v2 by Hangar555");
    
            player.sendMessage(ChatColor.GREEN + "Commands:");
            player.sendMessage(ChatColor.DARK_GREEN + "/ChatEssentials" + ChatColor.GOLD + ":" + ChatColor.GREEN + " Displays this message");
            player.sendMessage(ChatColor.DARK_GREEN + "/Broadcast" + ChatColor.GOLD + ":" + ChatColor.GREEN + " Broadcast a desired message");
            player.sendMessage(ChatColor.GREEN + "Info:");
            player.sendMessage(ChatColor.DARK_GREEN + "This plugin is able to edit player messages, to prevent curse words");
            player.sendMessage(ChatColor.DARK_GREEN + "It can also intercept heavy messages");
            player.sendMessage(ChatColor.DARK_GREEN + "You are not allowed to edit and/or copy the plugin without the developer permission");
            player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------");
    
    
        return true; 
    }
        return false;
    }
    }
    

    Lets start with the welcome message:
    Code:
        @EventHandler(priority=EventPriority.HIGHEST) //this sets the event priority, in this case the highest
        public void handleJoin(PlayerJoinEvent event) //Player join event: When the player joins the server
        {
            Player p = event.getPlayer(); //sets the player p = event.getPlayer. Simple
            event.setJoinMessage(chatcolor(getConfig().getString("WelcomeMessage")));  //sets the join message from the config. Can also be null or be write here
            
    Now the filter:
    Code:
    List<String> blockedMessages = getConfig().getStringList("Blacklist"); //get the string list called "blacklist" from the config
    
        @EventHandler
        public void playerChatEvent(AsyncPlayerChatEvent event) { //this is the "Chat" event
    
        for (String blockedMessage : blockedMessages) { //gets the String
        if(event.getMessage().contains(blockedMessage)) { //check if the sentece contains a blocked word
        event.setCancelled(true); //cacels the message
        event.getPlayer().sendMessage("" + ChatColor.RED + ChatColor.BOLD + getConfig().getString("BlockedMessageERROR") ); //gets the error from the config.
        return;
        }
        }
        }       

    Now onEnable/Disable methods:
    Code:
    public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this); //register the events
            getConfig().options().copyDefaults(true); //get the config and copy it from the jar
            saveConfig(); //save the config
        }
    
        public void onDisable()
    //nothing
        {
        }  

    Broadcasts, this you should check it here
    Player (name it different, not p.)
    Code:
        Player player = (Player)sender; //the player is the sender, WOW
    Custom CE help (not default, helpful on servers with custom help, like cube)
    Code:
     //you alredy have the onCommand method
            if (cmd.getName().equalsIgnoreCase("ChatEssentials")) { //command "executor"
            if(player.hasPermission("CE.help")) //if the player has the required permissions
            player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------"); //just a line
            player.sendMessage(ChatColor.BLUE + "ChatEssentials v2 by Hangar555"); //I'm famous!
    
            player.sendMessage(ChatColor.GREEN + "Commands:");
            player.sendMessage(ChatColor.DARK_GREEN + "/ChatEssentials" + ChatColor.GOLD + ":" + ChatColor.GREEN + " Displays this message"); //useless message
            player.sendMessage(ChatColor.DARK_GREEN + "/Broadcast" + ChatColor.GOLD + ":" + ChatColor.GREEN + " Broadcast a desired message"); //It have a use, I suppose
            player.sendMessage(ChatColor.GREEN + "Info:"); //Wow, a word
            player.sendMessage(ChatColor.DARK_GREEN + "This plugin is able to edit player messages, to prevent curse words"); //Same as in spigot web. Awesome
            player.sendMessage(ChatColor.DARK_GREEN + "You are not allowed to edit and/or copy the plugin without the developer permission"); //Pls
            player.sendMessage(ChatColor.DARK_BLUE + "----------------------------------------");
    //another line



    Hope you like, if you do not understand it: Java OOP :p
     
    tspacedog and hgbf like this.
  2. Neddypoo

    Neddypoo Member

    Joined:
    May 22, 2015
    Messages:
    2,562
    Likes Received:
    2,239
    Trophy Points:
    113
    Gender:
    Male
    Location:
    The Netherlands, Limburg
    Home Page:
    What is CE?.... Wich game it is?
     
  3. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
  4. Neddypoo

    Neddypoo Member

    Joined:
    May 22, 2015
    Messages:
    2,562
    Likes Received:
    2,239
    Trophy Points:
    113
    Gender:
    Male
    Location:
    The Netherlands, Limburg
    Home Page:
  5. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
    This is a really improved version :p
     
  6. Foodyling

    Foodyling Member

    Joined:
    Dec 25, 2015
    Messages:
    1,937
    Likes Received:
    86
    Trophy Points:
    63
    Gender:
    Male
    The filter is case-sensitive and won't block variations of words with capitalized letters (if the word lol is blocked, LOL can still be said).
     
  7. codexprivateㅤㅤㅤㅤ

    codexprivateㅤㅤㅤㅤ Member

    Joined:
    May 14, 2016
    Messages:
    895
    Likes Received:
    816
    Trophy Points:
    93
    Occupation:
    Love the life you live. Live the life you love.
    Location:
    α муѕтяισυѕ ρƖαcє
    Code:
    package test.modules.combat;
    
    import java.util.ArrayList;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.entity.EntityPlayerSP;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.network.play.client.C02PacketUseEntity;
    import net.minecraft.network.play.client.C02PacketUseEntity.Action;
    import net.minecraft.network.play.client.C03PacketPlayer;
    import net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition;
    import net.minecraft.network.play.client.C03PacketPlayer.C05PacketPlayerLook;
    import net.minecraft.network.play.client.C03PacketPlayer.C06PacketPlayerPosLook;
    import sallos.Sallos;
    import sallos.commands.Command;
    import sallos.events.EventTarget;
    import sallos.events.events.EventPacketSend;
    import sallos.events.events.EventPreMotionUpdates;
    import sallos.managers.CommandManager;
    import sallos.managers.ModuleManager;
    import sallos.managers.PropertyManager.Property;
    import sallos.modules.Module;
    import sallos.modules.Module.Category;
    import sallos.modules.movement.Speed;
    import sallos.modules.movement.Speed.speedMode;
    import sallos.utils.Helper;
    import sallos.utils.Logger;
    import sallos.utils.utils.BlockUtils;
    import sallos.utils.utils.PlayerUtils;
    
    public class Criticals
      extends Module
    {
      public PropertyManager.Property<CritMode> cMode = new PropertyManager.Property(this, "Criticals Mode", CritMode.PACKET);
      private static boolean next = false;
      private static boolean critical = false;
    
      public Criticals()
      {
        super("Criticals", 25, 10712391, Module.Category.COMBAT, "Always critical.", new String[] { "crits", "crts", "crit" }, true);
      }
    
      public static enum CritMode
      {
        PACKET,  GROUND,  JUMPS;
      }
    
      @EventTarget(0)
      public void onPacketSent(EventPacketSend e)
      {
        if (((e.getPacket() instanceof C02PacketUseEntity)) && (this.cMode.value == CritMode.PACKET))
        {
          C02PacketUseEntity packetUseEntity = (C02PacketUseEntity)e.getPacket();
          if (packetUseEntity.getAction() == C02PacketUseEntity.Action.ATTACK)
          {
            EntityLivingBase ent = (EntityLivingBase)packetUseEntity.getEntityFromWorld(this.mc.theWorld);
            if (ent.hurtTime < 3) {
              if (((next = next ? 0 : 1) != 0) && (this.mc.thePlayer.isCollidedVertically)) {
                doCrits();
              }
            }
          }
        }
        if (this.cMode.value != CritMode.GROUND) {
          return;
        }
        if ((e.getPacket() instanceof C03PacketPlayer))
        {
          ((C03PacketPlayer)e.getPacket()).field_149480_h = false;
          ((C03PacketPlayer)e.getPacket()).field_149474_g = false;
          Helper.blockUtils();
          if (BlockUtils.isOnLiquid()) {
            return;
          }
          if ((Sallos.getModManager().getModState("Glide")) && (!Sallos.getModManager().getModState("Phase"))) {
            if ((e.getPacket() instanceof C03PacketPlayer.C04PacketPlayerPosition))
            {
              C03PacketPlayer.C04PacketPlayerPosition playerPos = (C03PacketPlayer.C04PacketPlayerPosition)e.getPacket();
              playerPos.field_149474_g = false;
              this.mc.thePlayer.onGround = false;
            }
            else if ((e.getPacket() instanceof C03PacketPlayer.C05PacketPlayerLook))
            {
              C03PacketPlayer.C05PacketPlayerLook look = (C03PacketPlayer.C05PacketPlayerLook)e.getPacket();
              look.field_149474_g = false;
            }
            else if ((e.getPacket() instanceof C03PacketPlayer.C06PacketPlayerPosLook))
            {
              C03PacketPlayer.C06PacketPlayerPosLook posLook = (C03PacketPlayer.C06PacketPlayerPosLook)e.getPacket();
              posLook.field_149474_g = false;
            }
          }
        }
      }
    
      @EventTarget
      public void onPre(EventPreMotionUpdates pre)
      {
        if (this.cMode.value != CritMode.JUMPS) {
          return;
        }
        if ((Helper.playerUtils().MovementInput()) && (this.mc.thePlayer.isCollidedVertically) && (this.mc.thePlayer.onGround))
        {
          if ((this.mc.thePlayer.ticksExisted % 2 == 0) && (pre.getY() == this.mc.thePlayer.posY) && (this.mc.thePlayer.isSwingInProgress) && (Helper.playerUtils().getDistanceToFall() == 0.0D)) {
            pre.setY(pre.getY() + 0.063D);
          }
          if ((pre.getY() == this.mc.thePlayer.posY) && (pre.isGround())) {
            pre.setGround(false);
          }
        }
      }
    
      public void onDisable()
      {
        super.onDisable();
        next = false;
      }
    
      public static boolean isCriting()
      {
        return critical;
      }
    
      public void doCrits()
      {
        if (!Sallos.getModManager().getModState("Criticals")) {
          return;
        }
        Speed speed = (Speed)Sallos.getModManager().getModule(Speed.class);
        if ((speed.mode.value == Speed.speedMode.ONGROUND) && (Helper.playerUtils().MovementInput()) && (speed.getState())) {
          return;
        }
        critical = true;
        Helper.sendPacket(new C03PacketPlayer.C04PacketPlayerPosition(this.mc.thePlayer.posX, this.mc.thePlayer.posY + 0.05D, this.mc.thePlayer.posZ, false));
        Helper.sendPacket(new C03PacketPlayer.C04PacketPlayerPosition(this.mc.thePlayer.posX, this.mc.thePlayer.posY, this.mc.thePlayer.posZ, false));
        Helper.sendPacket(new C03PacketPlayer.C04PacketPlayerPosition(this.mc.thePlayer.posX, this.mc.thePlayer.posY + 0.012511D, this.mc.thePlayer.posZ, false));
        Helper.sendPacket(new C03PacketPlayer.C04PacketPlayerPosition(this.mc.thePlayer.posX, this.mc.thePlayer.posY, this.mc.thePlayer.posZ, false));
        critical = false;
      }
    
      protected void addCommand()
      {
        Sallos.getCommandManager();CommandManager.cmds.add(new Command(
          "Criticals", "Manages criticals ncp mode", Logger.LogExecutionFail("Option, Options:", new String[] { "Packet", "Ground", "Jumps", "values" }), new String[] { "crits" })
          {
            public void execute(String commandName, String[] arguments)
            {
              String mode = arguments[1];
              String str1;
              switch ((str1 = mode.toLowerCase()).hashCode())
              {
              case -1237460601:
                if (str1.equals("ground")) {}
                break;
              case -995865464:
                if (str1.equals("packet")) {
                  break;
                }
                break;
              case -823812830:
                if (str1.equals("values")) {}
                break;
              case -807058197:
                if (str1.equals("packets")) {
                  break;
                }
                break;
              case 106:
                if (str1.equals("j")) {}
                break;
              case 110:
                if (str1.equals("n")) {
                  break;
                }
                break;
              case 111:
                if (str1.equals("o")) {}
                break;
              case 108960:
                if (str1.equals("new")) {
                  break;
                }
                break;
              case 110119:
                if (str1.equals("old")) {}
                break;
              case 3273774:
                if (str1.equals("jump")) {}
                break;
              case 101487109:
                if (!str1.equals("jumps"))
                {
                  break label355;
                  Criticals.this.cMode.value = Criticals.CritMode.PACKET;
                  Logger.logSetMessage("Criticals", "Mode", Criticals.this.cMode);
                  return;
                
                  Criticals.this.cMode.value = Criticals.CritMode.GROUND;
                  Logger.logSetMessage("Criticals", "Mode", Criticals.this.cMode);
                  return;
                }
                else
                {
                  Criticals.this.cMode.value = Criticals.CritMode.JUMPS;
                  Logger.logSetMessage("Criticals", "Mode", Criticals.this.cMode);
                  return;
                
                  Criticals.this.logValues();
                }
                break;
              }
              label355:
              Logger.logChat(getError());
            }
          });
      }
    }
    
     
  8. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
    You made that?
     
  9. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
    is there a way to make it non case-sensitive?
     
  10. Foodyling

    Foodyling Member

    Joined:
    Dec 25, 2015
    Messages:
    1,937
    Likes Received:
    86
    Trophy Points:
    63
    Gender:
    Male
    Simpleton way is to get the message and call a #toLowerCase() and do a #toLowerCase() on all the blacklisted words.
    For example,
    Message: LoL -> lol
    Blacklisted word -> lol
    a #contains(String) will return true.

    However, a more advanced approach would to some form of indexing of similar character types and do lookups.
     
  11. HangarGeek

    HangarGeek Member

    Joined:
    Sep 15, 2015
    Messages:
    2,948
    Likes Received:
    2,137
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Kepler452B
    Home Page:
    Okay, thanks!