mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2026-01-06 15:42:00 +00:00
beta3
This commit is contained in:
@@ -20,7 +20,9 @@ package net.momirealms.customnameplates.bukkit;
|
||||
import net.momirealms.customnameplates.api.*;
|
||||
import net.momirealms.customnameplates.api.event.NameplatesReloadEvent;
|
||||
import net.momirealms.customnameplates.api.feature.ChatListener;
|
||||
import net.momirealms.customnameplates.api.feature.RespawnListener;
|
||||
import net.momirealms.customnameplates.api.feature.JoinQuitListener;
|
||||
import net.momirealms.customnameplates.api.feature.WorldChangeListener;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.backend.feature.actionbar.ActionBarManagerImpl;
|
||||
import net.momirealms.customnameplates.backend.feature.advance.AdvanceManagerImpl;
|
||||
@@ -54,8 +56,11 @@ import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -78,6 +83,8 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
private final JavaPlugin bootstrap;
|
||||
|
||||
private final List<JoinQuitListener> joinQuitListeners = new ArrayList<>();
|
||||
private final List<WorldChangeListener> worldChangeListeners = new ArrayList<>();
|
||||
private final List<RespawnListener> respawnListeners = new ArrayList<>();
|
||||
|
||||
private boolean loaded = false;
|
||||
|
||||
@@ -154,11 +161,14 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
this.chatManager = new BukkitChatManager(this);
|
||||
this.resourcePackManager = new ResourcePackManagerImpl(this);
|
||||
this.eventManager = EventManager.create(this);
|
||||
this.api = new CustomNameplatesAPI(this);
|
||||
|
||||
this.registerJoinQuitListener((JoinQuitListener) storageManager);
|
||||
this.registerJoinQuitListener((JoinQuitListener) actionBarManager);
|
||||
this.registerJoinQuitListener((JoinQuitListener) bossBarManager);
|
||||
this.registerJoinQuitListener((JoinQuitListener) unlimitedTagManager);
|
||||
this.joinQuitListeners.add((JoinQuitListener) storageManager);
|
||||
this.joinQuitListeners.add((JoinQuitListener) actionBarManager);
|
||||
this.joinQuitListeners.add((JoinQuitListener) bossBarManager);
|
||||
this.joinQuitListeners.add((JoinQuitListener) unlimitedTagManager);
|
||||
this.worldChangeListeners.add((WorldChangeListener) unlimitedTagManager);
|
||||
this.respawnListeners.add((RespawnListener) unlimitedTagManager);
|
||||
this.chatManager.registerListener((ChatListener) bubbleManager);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, getBootstrap());
|
||||
@@ -349,6 +359,26 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChangeWorld(PlayerChangedWorldEvent event) {
|
||||
CNPlayer cnPlayer = getPlayer(event.getPlayer().getUniqueId());
|
||||
if (cnPlayer != null) {
|
||||
for (WorldChangeListener listener : worldChangeListeners) {
|
||||
listener.onChangeWorld(cnPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
CNPlayer cnPlayer = getPlayer(event.getPlayer().getUniqueId());
|
||||
if (cnPlayer != null) {
|
||||
for (RespawnListener listener : respawnListeners) {
|
||||
listener.onRespawn(cnPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitSenderFactory getSenderFactory() {
|
||||
return senderFactory;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class BukkitPlatform implements Platform {
|
||||
int vehicle = (int) Reflections.field$ClientboundSetPassengersPacket$vehicle.get(packet);
|
||||
CNPlayer another = CustomNameplates.getInstance().getPlayer(vehicle);
|
||||
if (another != null) {
|
||||
Set<Integer> otherEntities = player.getTrackedPassengerIds(another);
|
||||
Set<Integer> otherEntities = another.getTrackedPassengerIds(player);
|
||||
for (int passenger : passengers) {
|
||||
otherEntities.add(passenger);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
|
||||
new NameplatesForceUnEquipCommand(this, plugin),
|
||||
new NameplatesForcePreviewCommand(this, plugin),
|
||||
new NameplatesForceEquipCommand(this, plugin),
|
||||
new NameplatesToggleCommand(this, plugin),
|
||||
new BubblesForceUnEquipCommand(this, plugin),
|
||||
new BubblesListCommand(this, plugin),
|
||||
new BubblesUnEquipCommand(this, plugin),
|
||||
|
||||
@@ -79,8 +79,8 @@ public class NameplatesForcePreviewCommand extends BukkitCommandFeature<CommandS
|
||||
player.equippedNameplate(optionalNameplate.get());
|
||||
}
|
||||
|
||||
if (!player.isPreviewing())
|
||||
plugin.getUnlimitedTagManager().setPreviewing(player, true);
|
||||
if (!player.isTempPreviewing())
|
||||
plugin.getUnlimitedTagManager().setTempPreviewing(player, true);
|
||||
|
||||
SchedulerTask task = plugin.getScheduler().asyncLater(() -> {
|
||||
if (!player.isOnline()) {
|
||||
@@ -88,7 +88,7 @@ public class NameplatesForcePreviewCommand extends BukkitCommandFeature<CommandS
|
||||
}
|
||||
|
||||
if (!plugin.getUnlimitedTagManager().isAlwaysShow()) {
|
||||
plugin.getUnlimitedTagManager().setPreviewing(player, false);
|
||||
plugin.getUnlimitedTagManager().setTempPreviewing(player, false);
|
||||
}
|
||||
|
||||
if (specified) {
|
||||
|
||||
@@ -52,17 +52,17 @@ public class NameplatesPreviewCommand extends BukkitCommandFeature<CommandSender
|
||||
if (plugin.getUnlimitedTagManager().isAlwaysShow()) {
|
||||
return;
|
||||
}
|
||||
if (player.isPreviewing()) {
|
||||
if (player.isTempPreviewing()) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_PREVIEW_FAILURE_COOLDOWN);
|
||||
return;
|
||||
}
|
||||
plugin.getUnlimitedTagManager().setPreviewing(player, true);
|
||||
plugin.getUnlimitedTagManager().setTempPreviewing(player, true);
|
||||
|
||||
SchedulerTask task = plugin.getScheduler().asyncLater(() -> {
|
||||
if (!player.isOnline()) {
|
||||
return;
|
||||
}
|
||||
plugin.getUnlimitedTagManager().setPreviewing(player, false);
|
||||
plugin.getUnlimitedTagManager().setTempPreviewing(player, false);
|
||||
}, plugin.getUnlimitedTagManager().previewDuration(), TimeUnit.SECONDS);
|
||||
|
||||
PreviewTasks.delayedTasks.put(player.uuid(), task);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customnameplates.bukkit.command.feature;
|
||||
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.ConfigManager;
|
||||
import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates;
|
||||
import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature;
|
||||
import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager;
|
||||
import net.momirealms.customnameplates.common.locale.MessageConstants;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
public class NameplatesToggleCommand extends BukkitCommandFeature<CommandSender> {
|
||||
|
||||
public NameplatesToggleCommand(CustomNameplatesCommandManager<CommandSender> commandManager, BukkitCustomNameplates plugin) {
|
||||
super(commandManager, plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
|
||||
return builder
|
||||
.senderType(Player.class)
|
||||
.handler(context -> {
|
||||
if (!ConfigManager.nameplateModule()) return;
|
||||
CNPlayer player = plugin.getPlayer(context.sender().getUniqueId());
|
||||
if (player == null || !player.isLoaded()) return;
|
||||
boolean isPreviewing = player.isToggleablePreviewing();
|
||||
plugin.getUnlimitedTagManager().togglePreviewing(player, !isPreviewing);
|
||||
player.save();
|
||||
if (!isPreviewing) {
|
||||
handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_TOGGLE_ON);
|
||||
} else {
|
||||
handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_TOGGLE_OFF);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeatureID() {
|
||||
return "nameplates_toggle";
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,16 @@ nameplates_preview:
|
||||
usage:
|
||||
- /nameplates preview
|
||||
|
||||
# A command to toggle the nameplate previewing
|
||||
# This command conflicts with `/nameplates preview`
|
||||
# You should never enable both of them at the same time
|
||||
# Usage: [COMMAND]
|
||||
nameplates_toggle:
|
||||
enable: false
|
||||
permission: nameplates.command.toggle
|
||||
usage:
|
||||
- /nameplates toggle
|
||||
|
||||
# A command to view the available nameplates
|
||||
# Usage: [COMMAND]
|
||||
nameplates_list:
|
||||
|
||||
Reference in New Issue
Block a user