Skip to content

Instantly share code, notes, and snippets.

@Exerosis
Created March 10, 2018 05:26
Show Gist options
  • Select an option

  • Save Exerosis/9ba2ccb5b7e8834267c8af61c75ebefb to your computer and use it in GitHub Desktop.

Select an option

Save Exerosis/9ba2ccb5b7e8834267c8af61c75ebefb to your computer and use it in GitHub Desktop.
package com.penzzly.engine.core.components.chat;
import com.penzzly.engine.architecture.base.Component;
import com.penzzly.engine.core.components.command.CommandComponent;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.HashSet;
import java.util.Set;
import static com.penzzly.engine.core.base.Events.listen;
public class StaffChatComponent extends Component {
public StaffChatComponent(CommandComponent commands) {
final Set<Player> staffChat = new HashSet<>();
addChild(listen((AsyncPlayerChatEvent event) -> {
if (staffChat.contains(event.getPlayer()))
event.getRecipients().retainAll(staffChat);
}));
addChild(commands.onPlayerCommand("sc"::equals, (player, args) -> {
if (!staffChat.add(player))
staffChat.remove(player);
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment