ViaVersion/common/src/main/java/com/viaversion/viaversion/ViaListener.java

73 lines
2.3 KiB
Java
Raw Normal View History

/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
2024-01-01 12:39:45 +01:00
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* 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
* (at your option) 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 <http://www.gnu.org/licenses/>.
*/
2021-04-26 21:16:10 +02:00
package com.viaversion.viaversion;
2021-04-26 21:16:10 +02:00
import com.viaversion.viaversion.api.Via;
2021-04-26 21:35:29 +02:00
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.Protocol;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
2016-09-26 22:30:59 +02:00
public abstract class ViaListener {
private final Class<? extends Protocol> requiredPipeline;
private boolean registered;
protected ViaListener(Class<? extends Protocol> requiredPipeline) {
this.requiredPipeline = requiredPipeline;
}
/**
* Get the UserConnection from a UUID
*
* @param uuid UUID object
* @return The UserConnection
*/
protected @Nullable UserConnection getUserConnection(UUID uuid) {
return Via.getManager().getConnectionManager().getConnectedClient(uuid);
}
/**
* Checks if the UUID is on the selected pipe
*
* @param uuid UUID Object
* @return True if on pipe
*/
2016-07-11 22:06:00 +02:00
protected boolean isOnPipe(UUID uuid) {
UserConnection userConnection = getUserConnection(uuid);
return userConnection != null &&
2020-06-07 12:19:36 +02:00
(requiredPipeline == null || userConnection.getProtocolInfo().getPipeline().contains(requiredPipeline));
}
/**
2016-09-26 22:30:59 +02:00
* Register the event
*/
2016-09-26 22:30:59 +02:00
public abstract void register();
protected Class<? extends Protocol> getRequiredPipeline() {
return requiredPipeline;
}
protected boolean isRegistered() {
return registered;
}
protected void setRegistered(boolean registered) {
this.registered = registered;
}
}