mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Added PlayerPermissionChangedEvent(#8023)
This commit is contained in:
1 parent
8dc58ad469
commit
675bf8bde2
5 files changed
+131
No files matched your search
@@ -26,9 +26,11 @@ import java.util.function.Consumer;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
|
||||
@@ -121,6 +123,7 @@ import net.minecraftforge.event.entity.player.BonemealEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PermissionsChangedEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
||||
@@ -782,4 +785,15 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static boolean onPermissionChanged(GameProfile gameProfile, int newLevel, PlayerList playerList)
|
||||
{
|
||||
int oldLevel = playerList.getServer().getProfilePermissions(gameProfile);
|
||||
ServerPlayer player = playerList.getPlayer(gameProfile.getId());
|
||||
if (newLevel != oldLevel && player != null)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new PermissionsChangedEvent(player, newLevel, oldLevel));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* This event will fire when the player is opped or deopped.
|
||||
* <p>
|
||||
* This event is cancelable which will stop the op or deop from happening.
|
||||
*/
|
||||
@Cancelable
|
||||
public class PermissionsChangedEvent extends PlayerEvent
|
||||
{
|
||||
private final int newLevel;
|
||||
private final int oldLevel;
|
||||
|
||||
public PermissionsChangedEvent(ServerPlayer player, int newLevel, int oldLevel)
|
||||
{
|
||||
super(player);
|
||||
this.oldLevel = oldLevel;
|
||||
this.newLevel = newLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The new permission level.
|
||||
*/
|
||||
public int getNewLevel()
|
||||
{
|
||||
return newLevel;
|
||||
}
|
||||
/**
|
||||
* @return The old permission level.
|
||||
*/
|
||||
public int getOldLevel()
|
||||
{
|
||||
return oldLevel;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user