Пример #1
0
  public boolean chat(String s) {
    if (!this.player.dead) {
      if (s.startsWith("/")) {
        this.handleCommand(s);
        return true;
      } else {
        Player player = getPlayer();
        PlayerChatEvent event = new PlayerChatEvent(player, s);
        server.getPluginManager().callEvent(event);

        if (event.isCancelled()) {
          return true;
        }

        s =
            String.format(
                event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
        a.info(s);
        for (Player recipient : event.getRecipients()) {
          recipient.sendMessage(s);
        }
      }
    }

    return false;
    // CraftBukkit end
  }
Пример #2
0
 /** On player chat, if the server is set to prefix the chat or not. */
 @Override
 public void onPlayerChat(PlayerChatEvent event) {
   if (event.isCancelled()) {
     return;
   }
   /**
    * Check whether the Server is set to prefix the chat with the World name. If not we do nothing,
    * if so we need to check if the World has an Alias.
    */
   if (this.configuration.getBoolean("prefix", false)) {
     /** Grab the name of the World the player is in. */
     String world = event.getPlayer().getWorld().getName();
     /** Setup a String called 'prefix' */
     String prefix;
     /**
      * Check whether the Alias for the world is not empty and is longer than 0 Letters. If so we
      * apply it to the 'prefix' String.
      */
     if (this.plugin.MVWorlds.containsKey(world)
         && this.plugin.MVWorlds.get(world).getAlias() != ""
         && this.plugin.MVWorlds.get(world).getAlias().length() > 0) {
       prefix = this.plugin.MVWorlds.get(world).getAlias();
     }
     /**
      * If the World doesn't have a prefix we'll just sent the full World name, can get messy :).
      */
     else {
       prefix = world;
     }
     /** Format the output of the String to add in the Prefix before the rest of the message. */
     String format = event.getFormat();
     /** Set the formatting. */
     event.setFormat("[" + prefix + "]" + format);
   }
 }
 @EventHandler
 public void HeMan(PlayerChatEvent e) {
   if (e.isCancelled()) return;
   if (!e.getMessage().matches("(?i)by the power of gr[a|e]yskull!?")) return;
   Player p = e.getPlayer();
   if (!plugin.isAuthorized(p, "rcmds.heman")) return;
   ItemStack is = p.getItemInHand();
   if (is.getType() != Material.DIAMOND_SWORD) return;
   if (is.getEnchantments().isEmpty()) return;
   e.setCancelled(true);
   p.getWorld().strikeLightningEffect(p.getLocation());
   Matcher m = Pattern.compile("(?i)by the power of gr[a|e]yskull!?").matcher(e.getMessage());
   StringBuilder sb = new StringBuilder();
   int last = 0;
   while (m.find()) {
     sb.append(e.getMessage().substring(last, m.start()));
     sb.append(m.group(0).toUpperCase());
     last = m.end();
   }
   sb.append(e.getMessage().substring(last));
   plugin
       .getServer()
       .broadcastMessage(
           e.getFormat().replaceAll("(?i)by the power of gr[a|e]yskull!?", sb.toString()));
   e.setFormat("");
   List<PotionEffect> effects = new ArrayList<PotionEffect>();
   effects.add(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.REGENERATION, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1200, 2));
   effects.add(new PotionEffect(PotionEffectType.SPEED, 1200, 2));
   p.addPotionEffects(effects);
 }
Пример #4
0
 @Override
 public void onPlayerChat(PlayerChatEvent event) {
   if (event.isCancelled()) return;
   Player player = event.getPlayer();
   String message = event.getMessage();
   if (message == null) return;
   event.setFormat(ichat.API.parseChat(player, message, ichat.chatFormat));
 }
Пример #5
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPlayerChat(PlayerChatEvent event) {
   if (!event.isCancelled()) {
     Player p = event.getPlayer();
     String fulltag = plugin.getClansConfig().getTagFormat();
     String format = plugin.getClansConfig().getMessageFormat();
     event.setFormat(insertData(format, fulltag, p.getDisplayName()));
   }
 }
Пример #6
0
  @EventHandler
  public void syncChatTrigger(final PlayerChatEvent event) {
    if (event.isCancelled()) return;

    // Return if "Use asynchronous event" is true in config file
    if (Settings.ChatAsynchronous()) return;

    Boolean cancelled = process(event.getPlayer(), event.getMessage());
    event.setCancelled(cancelled);
  }
  @Override
  public void onPlayerCommand(PlayerChatEvent event) {
    String[] split = event.getMessage().split(" ");
    Player player = event.getPlayer();
    String command = split[0];

    if ((!event.isCancelled()) && command.equalsIgnoreCase("/" + DailyBibleVerse.command)) {
      plugin.displayVOTD(player);
      event.setCancelled(true);
    }
  }
Пример #8
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) return;

    Player me = event.getPlayer();
    VPlayer vme = VPlayers.i.get(me);

    if (Conf.nameColorize == false) return;
    if (!vme.isVampire()) return;

    me.setDisplayName("" + Conf.nameColor + ChatColor.stripColor(me.getDisplayName()));
  }
 @EventHandler(priority = EventPriority.LOW)
 public void onPlayerChat(PlayerChatEvent event) {
   if (event.isCancelled()) return;
   if (AFKUtils.isAfk(event.getPlayer())) {
     AFKUtils.unsetAfk(event.getPlayer());
     plugin.getServer().broadcastMessage(event.getPlayer().getName() + " is no longer AFK.");
   }
   if (PConfManager.getPValBoolean(event.getPlayer(), "muted")) {
     if (PConfManager.getPVal(event.getPlayer(), "mutetime") != null
         && !RUtils.isTimeStampValid(event.getPlayer(), "mutetime"))
       PConfManager.setPValBoolean(event.getPlayer(), false, "muted");
     event.setFormat("");
     event.setCancelled(true);
     event.getPlayer().sendMessage(ChatColor.RED + "You are muted.");
     plugin.log.info(
         "[RoyalCommands] "
             + event.getPlayer().getName()
             + " tried to speak, but has been muted.");
   }
 }
Пример #10
0
  @EventHandler(event = PlayerChatEvent.class)
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Matcher matcher = cuipattern.matcher(event.getMessage());
    if (matcher.find()) {
      String type = matcher.group(1);
      String args = matcher.group(2);

      if (type.equals("v")) {
        try {
          plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args));
          event.setCancelled(true);
        } catch (NumberFormatException e) {
        }
      }
    }
  }
	/***
	 * The main function which replaces chat with matched replacements.
	 * @param e
	 * @return
	 */
	@EventHandler(priority = EventPriority.LOWEST)
	public void replaceChat(PlayerChatEvent e) {
		if (e.isCancelled()) return;
		
		try {
			ScriptEnvironment env = new ScriptEnvironment(); {
				env.setCommandSender(e.getPlayer());
				env.setServer(e.getPlayer().getServer());
			}
			ArrayList<ReplacementPair> preparedEffects = new ArrayList<ReplacementPair>(); //holds all effects until all replacements done

			for (ReplacementPair rp : pairs) {
				StringBuffer sb = new StringBuffer();
				Matcher m = rp.getRegex().matcher(e.getMessage());
				if (!m.find()) continue;
				env.setMatcher(m);

				if (rp.playerWillVanish()) { //the player will vanish as a result of this, special handling
					int cutlen = CommandsEX.getConf().getInt("replacements.cutoff.length", 1);
					String cuttext = CommandsEX.getConf().getString("replacements.cutoff.indicator", "--*");
	
					String rep = m.group().substring(0, cutlen).concat(cuttext);
					m.appendReplacement(sb, rep);
					e.setMessage(sb.toString());
					//e.setCancelled(true);
					//e.getPlayer().chat(sb.toString()); //chat first
	
					rp.executeEffects(env); //then execute the replacement
					return;
				}

				//loop through with find/replace
				do { //use do while, due to the find() invocation above
					// test if it is all upper, and replace with all upper (if we have this set up in the regex itself - in config file)
					if (rp.getSameOutputCase() && allUpper && m.group().toUpperCase().equals(m.group())) {
						m.appendReplacement(sb, rp.executeString(env).toUpperCase());
					} else {
						m.appendReplacement(sb, rp.executeString(env));
					}
				} while (m.find());
				m.appendTail(sb);

				if (!preparedEffects.contains(rp)) {
					preparedEffects.add(rp);
				}
				e.setMessage(sb.toString());
			}
			
			//after all replacements are in: execute the effects
			if (!preparedEffects.isEmpty()) {
				//e.setCancelled(true);
				//e.getPlayer().chat(sb.toString()); //chat first
	
				env.setMatcher(null);
				for (ReplacementPair rp : preparedEffects){
					rp.executeEffects(env);
				}
			}
		} catch (Exception ex){
			LogHelper.logSevere("[CommandsEX] " + _("cmdOrChatreplacementFailed", ""));
			LogHelper.logDebug("Message: " + ex.getMessage() + ", cause: " + ex.getCause());
		}
	}
Пример #12
0
  @Override
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player talkingPlayer = event.getPlayer();
    String msg = event.getMessage();

    // ... it was not a command. This means that it is a chat message!
    FPlayer me = FPlayer.get(talkingPlayer);

    // Are we to insert the Faction tag into the format?
    // If we are not to insert it - we are done.
    if (!Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {
      return;
    }

    int InsertIndex = 0;
    String eventFormat = event.getFormat();

    if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) {
      // we're using the "replace" method of inserting the faction tags
      // if they stuck "{FACTION_TITLE}" in there, go ahead and do it too
      if (eventFormat.contains("{FACTION_TITLE}")) {
        eventFormat = eventFormat.replace("{FACTION_TITLE}", me.getTitle());
      }
      InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
      eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
      Conf.chatTagPadAfter = false;
      Conf.chatTagPadBefore = false;
    } else if (!Conf.chatTagInsertAfterString.isEmpty()
        && eventFormat.contains(Conf.chatTagInsertAfterString)) {
      // we're using the "insert after string" method
      InsertIndex =
          eventFormat.indexOf(Conf.chatTagInsertAfterString)
              + Conf.chatTagInsertAfterString.length();
    } else if (!Conf.chatTagInsertBeforeString.isEmpty()
        && eventFormat.contains(Conf.chatTagInsertBeforeString)) {
      // we're using the "insert before string" method
      InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
    } else {
      // we'll fall back to using the index place method
      InsertIndex = Conf.chatTagInsertIndex;
      if (InsertIndex > eventFormat.length()) return;
    }

    String formatStart =
        eventFormat.substring(0, InsertIndex)
            + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
    String formatEnd =
        ((Conf.chatTagPadAfter && !me.getChatTag().isEmpty()) ? " " : "")
            + eventFormat.substring(InsertIndex);

    String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd;

    // Relation Colored?
    if (Conf.chatTagRelationColored) {
      // We must choke the standard message and send out individual messages to all players
      // Why? Because the relations will differ.
      event.setCancelled(true);

      for (Player listeningPlayer : event.getRecipients()) {
        FPlayer you = FPlayer.get(listeningPlayer);
        String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
        try {
          listeningPlayer.sendMessage(
              String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
        } catch (UnknownFormatConversionException ex) {
          Factions.log(
              Level.SEVERE,
              "Critical error in chat message formatting! Complete format string: " + yourFormat);
          Factions.log(Level.SEVERE, "First half of event.getFormat() string: " + formatStart);
          Factions.log(Level.SEVERE, "Second half of event.getFormat() string: " + formatEnd);
          Factions.log(
              Level.SEVERE,
              "NOTE: To fix this quickly, running this command should work: f config chatTagInsertIndex 0");
          Factions.log(
              Level.SEVERE,
              "For a more proper fix, please read the chat configuration notes on the configuration page of the Factions user guide.");
          ex.printStackTrace();
          return;
        }
      }

      // Write to the log... We will write the non colored message.
      String nonColoredMsg =
          ChatColor.stripColor(
              String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
      Logger.getLogger("Minecraft").info(nonColoredMsg);
    } else {
      // No relation color.
      event.setFormat(nonColoredMsgFormat);
    }
  }