2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* 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
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* 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;
|
2016-07-11 20:27:44 +02:00
|
|
|
|
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;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
2016-07-11 20:27:44 +02:00
|
|
|
import java.util.UUID;
|
2023-02-12 11:44:25 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2016-07-11 20:27:44 +02:00
|
|
|
|
2016-09-26 22:30:59 +02:00
|
|
|
public abstract class ViaListener {
|
2016-07-11 20:27:44 +02:00
|
|
|
private final Class<? extends Protocol> requiredPipeline;
|
2020-03-10 13:22:22 +01:00
|
|
|
private boolean registered;
|
|
|
|
|
2021-04-27 18:21:51 +02:00
|
|
|
protected ViaListener(Class<? extends Protocol> requiredPipeline) {
|
2020-03-10 13:22:22 +01:00
|
|
|
this.requiredPipeline = requiredPipeline;
|
|
|
|
}
|
2016-07-11 20:27:44 +02:00
|
|
|
|
|
|
|
/**
|
2023-10-08 12:19:48 +02:00
|
|
|
* Get the UserConnection from a UUID
|
2016-07-11 20:27:44 +02:00
|
|
|
*
|
|
|
|
* @param uuid UUID object
|
|
|
|
* @return The UserConnection
|
|
|
|
*/
|
2021-04-02 14:15:30 +02:00
|
|
|
protected @Nullable UserConnection getUserConnection(UUID uuid) {
|
2021-03-24 15:21:18 +01:00
|
|
|
return Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
2016-07-11 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2016-07-11 20:27:44 +02:00
|
|
|
UserConnection userConnection = getUserConnection(uuid);
|
|
|
|
return userConnection != null &&
|
2020-06-07 12:19:36 +02:00
|
|
|
(requiredPipeline == null || userConnection.getProtocolInfo().getPipeline().contains(requiredPipeline));
|
2016-07-11 20:27:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-26 22:30:59 +02:00
|
|
|
* Register the event
|
2016-07-11 20:27:44 +02:00
|
|
|
*/
|
2016-09-26 22:30:59 +02:00
|
|
|
public abstract void register();
|
2020-03-10 13:22:22 +01:00
|
|
|
|
|
|
|
protected Class<? extends Protocol> getRequiredPipeline() {
|
|
|
|
return requiredPipeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isRegistered() {
|
|
|
|
return registered;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setRegistered(boolean registered) {
|
|
|
|
this.registered = registered;
|
|
|
|
}
|
2016-07-11 20:27:44 +02:00
|
|
|
}
|