forked from Upstream/Velocitab
Added support for VanishIntegration
This commit is contained in:
parent
5ad41e041f
commit
857d6a9b07
@ -47,6 +47,7 @@ import net.william278.velocitab.player.Role;
|
|||||||
import net.william278.velocitab.player.TabPlayer;
|
import net.william278.velocitab.player.TabPlayer;
|
||||||
import net.william278.velocitab.sorting.SortingManager;
|
import net.william278.velocitab.sorting.SortingManager;
|
||||||
import net.william278.velocitab.tab.PlayerTabList;
|
import net.william278.velocitab.tab.PlayerTabList;
|
||||||
|
import net.william278.velocitab.vanish.VanishManager;
|
||||||
import org.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bstats.velocity.Metrics;
|
import org.bstats.velocity.Metrics;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -76,6 +77,8 @@ public class Velocitab {
|
|||||||
private List<Hook> hooks;
|
private List<Hook> hooks;
|
||||||
private ScoreboardManager scoreboardManager;
|
private ScoreboardManager scoreboardManager;
|
||||||
private SortingManager sortingManager;
|
private SortingManager sortingManager;
|
||||||
|
@Getter
|
||||||
|
private VanishManager vanishManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Velocitab(@NotNull ProxyServer server, @NotNull Logger logger, @DataDirectory Path dataDirectory) {
|
public Velocitab(@NotNull ProxyServer server, @NotNull Logger logger, @DataDirectory Path dataDirectory) {
|
||||||
@ -91,6 +94,7 @@ public class Velocitab {
|
|||||||
prepareSortingManager();
|
prepareSortingManager();
|
||||||
prepareScoreboardManager();
|
prepareScoreboardManager();
|
||||||
prepareTabList();
|
prepareTabList();
|
||||||
|
prepareVanishManager();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
registerMetrics();
|
registerMetrics();
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
@ -180,6 +184,10 @@ public class Velocitab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void prepareVanishManager() {
|
||||||
|
this.vanishManager = new VanishManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Optional<ScoreboardManager> getScoreboardManager() {
|
public Optional<ScoreboardManager> getScoreboardManager() {
|
||||||
return Optional.ofNullable(scoreboardManager);
|
return Optional.ofNullable(scoreboardManager);
|
||||||
|
@ -173,6 +173,13 @@ public class ScoreboardManager {
|
|||||||
|
|
||||||
siblings.forEach(s -> {
|
siblings.forEach(s -> {
|
||||||
s.getPlayersConnected().forEach(p -> {
|
s.getPlayersConnected().forEach(p -> {
|
||||||
|
|
||||||
|
boolean canSee = !plugin.getVanishManager().isVanished(p.getUsername()) || plugin.getVanishManager().canSee(player.getUsername(), player.getUsername());
|
||||||
|
|
||||||
|
if (!canSee) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) p;
|
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) p;
|
||||||
connectedPlayer.getConnection().write(packet);
|
connectedPlayer.getConnection().write(packet);
|
||||||
|
@ -89,6 +89,7 @@ public class PlayerTabList {
|
|||||||
final TabPlayer tabPlayer = plugin.getTabPlayer(joined);
|
final TabPlayer tabPlayer = plugin.getTabPlayer(joined);
|
||||||
players.add(tabPlayer);
|
players.add(tabPlayer);
|
||||||
|
|
||||||
|
boolean isVanished = plugin.getVanishManager().isVanished(joined.getUsername());
|
||||||
// Update lists
|
// Update lists
|
||||||
plugin.getServer().getScheduler()
|
plugin.getServer().getScheduler()
|
||||||
.buildTask(plugin, () -> {
|
.buildTask(plugin, () -> {
|
||||||
@ -100,13 +101,26 @@ public class PlayerTabList {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isVanished || plugin.getVanishManager().canSee(player.getPlayer().getUsername(), joined.getUsername())) { // check if current player can see the joined player
|
||||||
|
addPlayerToTabList(player, tabPlayer);
|
||||||
|
} else {
|
||||||
|
player.getPlayer().getTabList().removeEntry(joined.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((plugin.getVanishManager().isVanished(player.getPlayer().getUsername()) ||
|
||||||
|
!plugin.getVanishManager().canSee(joined.getUsername(), player.getPlayer().getUsername())) && player.getPlayer() != joined) { // check if joined player can see the current player
|
||||||
|
tabList.removeEntry(player.getPlayer().getUniqueId());
|
||||||
|
} else {
|
||||||
|
|
||||||
tabList.getEntries().stream()
|
tabList.getEntries().stream()
|
||||||
.filter(e -> e.getProfile().getId().equals(player.getPlayer().getUniqueId())).findFirst()
|
.filter(e -> e.getProfile().getId().equals(player.getPlayer().getUniqueId())).findFirst()
|
||||||
.ifPresentOrElse(
|
.ifPresentOrElse(
|
||||||
entry -> player.getDisplayName(plugin).thenAccept(entry::setDisplayName),
|
entry -> player.getDisplayName(plugin).thenAccept(entry::setDisplayName),
|
||||||
() -> createEntry(player, tabList).thenAccept(tabList::addEntry)
|
() -> createEntry(player, tabList).thenAccept(tabList::addEntry)
|
||||||
);
|
);
|
||||||
addPlayerToTabList(player, tabPlayer);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
player.sendHeaderAndFooter(this);
|
player.sendHeaderAndFooter(this);
|
||||||
|
|
||||||
@ -201,12 +215,22 @@ public class PlayerTabList {
|
|||||||
tabPlayer.getDisplayName(plugin).thenAccept(displayName -> {
|
tabPlayer.getDisplayName(plugin).thenAccept(displayName -> {
|
||||||
if (displayName == null || displayName.equals(lastDisplayName)) return;
|
if (displayName == null || displayName.equals(lastDisplayName)) return;
|
||||||
|
|
||||||
players.forEach(player ->
|
boolean isVanished = plugin.getVanishManager().isVanished(tabPlayer.getPlayer().getUsername());
|
||||||
|
|
||||||
|
players.forEach(player -> {
|
||||||
|
|
||||||
|
if (isVanished && !plugin.getVanishManager().canSee(player.getPlayer().getUsername(), tabPlayer.getPlayer().getUsername())) {
|
||||||
|
System.out.println("Player " + player.getPlayer().getUsername() + " cannot see " + tabPlayer.getPlayer().getUsername());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
player.getPlayer().getTabList().getEntries().stream()
|
player.getPlayer().getTabList().getEntries().stream()
|
||||||
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
|
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
|
||||||
.ifPresent(entry -> entry.setDisplayName(displayName)));
|
.ifPresent(entry -> entry.setDisplayName(displayName));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDisplayNames() {
|
public void updateDisplayNames() {
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Velocitab, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.velocitab.vanish;
|
||||||
|
|
||||||
|
public class DefaultVanishIntegration implements VanishIntegration {
|
||||||
|
@Override
|
||||||
|
public boolean canSee(String name, String otherName) {
|
||||||
|
if (otherName.equals("AlexDev_") && name.equals("AlexDalf03")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVanished(String name) {
|
||||||
|
if (name.equals("AlexDev_")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Velocitab, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.velocitab.vanish;
|
||||||
|
|
||||||
|
public interface VanishIntegration {
|
||||||
|
|
||||||
|
boolean canSee(String name, String otherName);
|
||||||
|
|
||||||
|
boolean isVanished(String name);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Velocitab, licensed under the Apache License 2.0.
|
||||||
|
*
|
||||||
|
* Copyright (c) William278 <will27528@gmail.com>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.william278.velocitab.vanish;
|
||||||
|
|
||||||
|
import net.william278.velocitab.Velocitab;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class VanishManager {
|
||||||
|
|
||||||
|
private final Velocitab plugin;
|
||||||
|
private VanishIntegration integration;
|
||||||
|
|
||||||
|
public VanishManager(Velocitab plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
setIntegration(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntegration(VanishIntegration integration) {
|
||||||
|
this.integration = Objects.requireNonNullElseGet(integration, DefaultVanishIntegration::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canSee(String name, String otherName) {
|
||||||
|
return integration.canSee(name, otherName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVanished(String name) {
|
||||||
|
return integration.isVanished(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void vanish(String name) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unvanish(String name) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user