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.sorting.SortingManager;
|
||||
import net.william278.velocitab.tab.PlayerTabList;
|
||||
import net.william278.velocitab.vanish.VanishManager;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -76,6 +77,8 @@ public class Velocitab {
|
||||
private List<Hook> hooks;
|
||||
private ScoreboardManager scoreboardManager;
|
||||
private SortingManager sortingManager;
|
||||
@Getter
|
||||
private VanishManager vanishManager;
|
||||
|
||||
@Inject
|
||||
public Velocitab(@NotNull ProxyServer server, @NotNull Logger logger, @DataDirectory Path dataDirectory) {
|
||||
@ -91,6 +94,7 @@ public class Velocitab {
|
||||
prepareSortingManager();
|
||||
prepareScoreboardManager();
|
||||
prepareTabList();
|
||||
prepareVanishManager();
|
||||
registerCommands();
|
||||
registerMetrics();
|
||||
checkForUpdates();
|
||||
@ -180,6 +184,10 @@ public class Velocitab {
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareVanishManager() {
|
||||
this.vanishManager = new VanishManager(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<ScoreboardManager> getScoreboardManager() {
|
||||
return Optional.ofNullable(scoreboardManager);
|
||||
|
@ -95,8 +95,8 @@ public class ScoreboardManager {
|
||||
createdTeams.put(player.getUniqueId(), role);
|
||||
this.nametags.put(role, prefix + ":::" + suffix);
|
||||
dispatchGroupPacket(UpdateTeamsPacket.create(plugin, role, "", prefix, suffix, name), player);
|
||||
} else if (!this.nametags.getOrDefault(role, "").equals(prefix + ":::" + suffix)) {
|
||||
this.nametags.put(role, prefix + ":::" + suffix);
|
||||
} else if (!this.nametags.getOrDefault(role, "").equals(prefix + ":::" + suffix)) {
|
||||
this.nametags.put(role, prefix + ":::" + suffix);
|
||||
dispatchGroupPacket(UpdateTeamsPacket.changeNameTag(plugin, role, prefix, suffix), player);
|
||||
}
|
||||
}).exceptionally(e -> {
|
||||
@ -108,7 +108,7 @@ public class ScoreboardManager {
|
||||
|
||||
public void resendAllNameTags(Player player) {
|
||||
|
||||
if(!plugin.getSettings().areNametagsEnabled()) {
|
||||
if (!plugin.getSettings().areNametagsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -173,6 +173,13 @@ public class ScoreboardManager {
|
||||
|
||||
siblings.forEach(s -> {
|
||||
s.getPlayersConnected().forEach(p -> {
|
||||
|
||||
boolean canSee = !plugin.getVanishManager().isVanished(p.getUsername()) || plugin.getVanishManager().canSee(player.getUsername(), player.getUsername());
|
||||
|
||||
if (!canSee) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final ConnectedPlayer connectedPlayer = (ConnectedPlayer) p;
|
||||
connectedPlayer.getConnection().write(packet);
|
||||
|
@ -89,6 +89,7 @@ public class PlayerTabList {
|
||||
final TabPlayer tabPlayer = plugin.getTabPlayer(joined);
|
||||
players.add(tabPlayer);
|
||||
|
||||
boolean isVanished = plugin.getVanishManager().isVanished(joined.getUsername());
|
||||
// Update lists
|
||||
plugin.getServer().getScheduler()
|
||||
.buildTask(plugin, () -> {
|
||||
@ -100,13 +101,26 @@ public class PlayerTabList {
|
||||
continue;
|
||||
}
|
||||
|
||||
tabList.getEntries().stream()
|
||||
.filter(e -> e.getProfile().getId().equals(player.getPlayer().getUniqueId())).findFirst()
|
||||
.ifPresentOrElse(
|
||||
entry -> player.getDisplayName(plugin).thenAccept(entry::setDisplayName),
|
||||
() -> createEntry(player, tabList).thenAccept(tabList::addEntry)
|
||||
);
|
||||
addPlayerToTabList(player, tabPlayer);
|
||||
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()
|
||||
.filter(e -> e.getProfile().getId().equals(player.getPlayer().getUniqueId())).findFirst()
|
||||
.ifPresentOrElse(
|
||||
entry -> player.getDisplayName(plugin).thenAccept(entry::setDisplayName),
|
||||
() -> createEntry(player, tabList).thenAccept(tabList::addEntry)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
player.sendHeaderAndFooter(this);
|
||||
|
||||
@ -201,12 +215,22 @@ public class PlayerTabList {
|
||||
tabPlayer.getDisplayName(plugin).thenAccept(displayName -> {
|
||||
if (displayName == null || displayName.equals(lastDisplayName)) return;
|
||||
|
||||
players.forEach(player ->
|
||||
player.getPlayer().getTabList().getEntries().stream()
|
||||
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
|
||||
.ifPresent(entry -> entry.setDisplayName(displayName)));
|
||||
});
|
||||
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()
|
||||
.filter(e -> e.getProfile().getId().equals(tabPlayer.getPlayer().getUniqueId())).findFirst()
|
||||
.ifPresent(entry -> entry.setDisplayName(displayName));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
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