Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Adapt bungee to support my BungeeCord PR. Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
literalplus committed Jul 3, 2015
1 parent 06a479f commit 1a12818
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@

package io.github.xxyy.cmdblocker.bungee.listener;

import io.github.xxyy.cmdblocker.bungee.CommandBlockerPlugin;
import io.github.xxyy.cmdblocker.common.util.CommandHelper;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.event.TabCompleteEvent;
import net.md_5.bungee.api.event.TabCompleteResponseEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;

import io.github.xxyy.cmdblocker.bungee.CommandBlockerPlugin;
import io.github.xxyy.cmdblocker.common.util.CommandHelper;

import java.util.Iterator;
import java.util.List;

/**
* Listens for tab-complete events and removes BungeeCord commands.
* Listens for tab-complete events and removes BungeeCord (and Bukkit!) replies.
*
* @author <a href="http://xxyy.github.io/">xxyy</a>
* @since 16.7.14
Expand All @@ -41,30 +45,55 @@ public TabCompleteListener(CommandBlockerPlugin plugin) {
this.plugin = plugin;
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void onTabComplete(TabCompleteEvent evt) {
CommandSender sender = null;
if (evt.isCancelled()) {
return;
}

CommandSender sender = null;
if (evt.getSender() instanceof CommandSender) {
sender = (CommandSender) evt.getSender();
}

if(sender.hasPermission(plugin.getConfigAdapter().getBypassPermission())) {
return; //Don't need to check if sender has bypass
}
evt.setCancelled(removeBlocked(evt.getSuggestions(), sender));
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onTabCompleteResponse(TabCompleteResponseEvent evt) {
if (evt.isCancelled()) {
return;
}

Iterator<String> it = evt.getSuggestions().iterator();
while(it.hasNext()) {
CommandSender messageRecipient = null;
if (evt.getReceiver() instanceof CommandSender) {
messageRecipient = (CommandSender) evt.getReceiver();
}

evt.setCancelled(removeBlocked(evt.getSuggestions(), messageRecipient));
}

//Returns whether the event is to be cancelled
private boolean removeBlocked(List<String> suggestions, CommandSender messageRecipient) {
if (messageRecipient != null &&
messageRecipient.hasPermission(plugin.getConfigAdapter().getBypassPermission())) {
return false; //Don't need to recipient if sender has bypass
}

Iterator<String> it = suggestions.iterator();
while (it.hasNext()) {
String suggestion = it.next();

if(plugin.getConfigAdapter().isBlocked(CommandHelper.getRawCommand(suggestion))) {
if(plugin.getConfigAdapter().isTabRestrictiveMode()) {
evt.setCancelled(true);
plugin.sendErrorMessageIfEnabled(sender);
if (plugin.getConfigAdapter().isBlocked(CommandHelper.getRawCommand(suggestion))) {
if (plugin.getConfigAdapter().isTabRestrictiveMode()) {
plugin.sendErrorMessageIfEnabled(messageRecipient);
return true;
} else {
it.remove(); //Remove suggestion from mutable list
}
} else {
it.remove(); //Remove suggestion from mutable list
}
}

return false;
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
<minecraft.version>1.7.9</minecraft.version>
<spigot.version>${minecraft.version}-R0.2-SNAPSHOT</spigot.version>
<java.version>1.7</java.version>
<bungee.version>1.7-SNAPSHOT</bungee.version>
<bungee.version>1.8-SNAPSHOT</bungee.version>
</properties>

<repositories>
<repository> <!-- Spigot, BungeeCord -->
<repository> <!-- Spigot -->
<id>md5-repo</id>
<url>http://repo.md-5.net/content/repositories/public/</url>
</repository>
Expand Down

0 comments on commit 1a12818

Please sign in to comment.