PwnFilterSignListener extends AbstractBukkitListener { void onSignChange(SignChangeEvent event) { if (event.isCancelled()) return; MessageAuthor signAuthor = plugin.getFilterService().getAuthor((event.getPlayer().getUniqueId())); if (signAuthor.hasPermission("pwnfilter.bypass.signs")) { return; } StringBuilder builder = new StringBuilder(); for (String l : event.getLines()) { builder.append(l).append("\t"); } String signLines = builder.toString().trim(); FilterContextImpl filterTask = new FilterContextImpl(new ColoredString(signLines), signAuthor, this); ruleChain.execute(filterTask, filterServiceImpl); if (filterTask.messageChanged()) { List<String> newLines = new ArrayList<>(); if ((BukkitConfig.decolor()) && !(signAuthor.hasPermission("pwnfilter.color"))) { Collections.addAll(newLines, filterTask.getModifiedMessage().toString().split("\t")); } else { Collections.addAll(newLines, filterTask.getModifiedMessage().getRaw().split("\t")); } String[] outputLines = new String[4]; for (int i = 0; i < 4 && i < newLines.size(); i++) { if (newLines.get(i).length() > 15) { outputLines[i] = newLines.get(i).substring(0, 15); } else { outputLines[i] = newLines.get(i); } } for (int i = 0; i < 4; i++) { if (outputLines[i] != null) { event.setLine(i, outputLines[i]); } else { event.setLine(i, ""); } } } if (filterTask.isCancelled()) { event.setCancelled(true); filterTask.getAuthor().sendMessage("Your sign broke, there must be something wrong with it."); filterTask.addLogMessage("SIGN " + filterTask.getAuthor().getName() + " sign text: " + filterTask.getOriginalMessage().getRaw()); } } PwnFilterSignListener(PwnFilterPlugin plugin); @Override String getShortName(); @Override void activate();  }
@Test public void testBasicFunctionWorks() throws Exception { final String[] input = new String[]{"Test", "chat", "message", ""}; signChangeEvent = new SignChangeEvent(mockBlock, mockPlayer, input); signListener.loadRuleChain("blank.txt"); signListener.onSignChange(signChangeEvent); for (int i = 0; i < 4; i++) { assertEquals(input[i], signChangeEvent.getLine(i)); } }
@Test public void testOneLineReplacement() throws Exception { String[] input = new String[]{"replaceme", "test", "message", ""}; String[] output = new String[]{"PASS", "test", "message", ""}; signChangeEvent = new SignChangeEvent(mockBlock, mockPlayer, input.clone()); signListener.loadRuleChain("replace.txt"); signListener.onSignChange(signChangeEvent); String[] changedLines = signChangeEvent.getLines(); for (int i = 0; i < 4; i++) { assertEquals(output[i], changedLines[i]); } }