mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 14:38:46 +00:00
Create PlayerPunishEvent, implementing #206
This commit is contained in:
1 parent
031e7b145b
commit
3a48e8c602
4 files changed
+102
-10
No files matched your search
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.rammelkast.anticheatreloaded.api;
|
package com.rammelkast.anticheatreloaded.api.event;
|
||||||
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* AntiCheatReloaded for Bukkit and Spigot.
|
||||||
|
* Copyright (c) 2012-2015 AntiCheat Team
|
||||||
|
* Copyright (c) 2016-2022 Rammelkast
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package com.rammelkast.anticheatreloaded.api.event;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.rammelkast.anticheatreloaded.util.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when a player is punished by AntiCheatReloaded
|
||||||
|
*/
|
||||||
|
public final class PlayerPunishEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private final User user;
|
||||||
|
private final List<String> actions;
|
||||||
|
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public PlayerPunishEvent(final User user, final List<String> actions) {
|
||||||
|
this.user = user;
|
||||||
|
this.actions = actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link com.rammelkast.anticheatreloaded.util.User} who failed the check
|
||||||
|
*
|
||||||
|
* @return a {@link com.rammelkast.anticheatreloaded.util.User}
|
||||||
|
*/
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions the punishment will perform
|
||||||
|
*
|
||||||
|
* @return a a list of punishment strings
|
||||||
|
*/
|
||||||
|
public List<String> getActions() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ import java.util.UUID;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.rammelkast.anticheatreloaded.api.CheckFailEvent;
|
import com.rammelkast.anticheatreloaded.api.event.CheckFailEvent;
|
||||||
import com.rammelkast.anticheatreloaded.util.Permission;
|
import com.rammelkast.anticheatreloaded.util.Permission;
|
||||||
import com.rammelkast.anticheatreloaded.util.User;
|
import com.rammelkast.anticheatreloaded.util.User;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||||
|
import com.rammelkast.anticheatreloaded.api.event.PlayerPunishEvent;
|
||||||
import com.rammelkast.anticheatreloaded.check.CheckType;
|
import com.rammelkast.anticheatreloaded.check.CheckType;
|
||||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||||
import com.rammelkast.anticheatreloaded.util.Group;
|
import com.rammelkast.anticheatreloaded.util.Group;
|
||||||
@@ -188,17 +189,26 @@ public final class UserManager {
|
|||||||
if (user.getPlayer() == null) {
|
if (user.getPlayer() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final PlayerPunishEvent event = new PlayerPunishEvent(user, actions);
|
||||||
|
{
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String name = user.getName();
|
final String name = user.getName();
|
||||||
for (String event : actions) {
|
for (String action : actions) {
|
||||||
event = event.replaceAll("%player%", name)
|
action = action.replaceAll("%player%", name)
|
||||||
.replaceAll("%world%", user.getPlayer().getWorld().getName())
|
.replaceAll("%world%", user.getPlayer().getWorld().getName())
|
||||||
.replaceAll("%check%", type.name());
|
.replaceAll("%check%", type.name());
|
||||||
|
|
||||||
if (event.startsWith("COMMAND[")) {
|
if (action.startsWith("COMMAND[")) {
|
||||||
for (String cmd : Utilities.getCommands(event)) {
|
for (String cmd : Utilities.getCommands(action)) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("KICK")) {
|
} else if (action.equalsIgnoreCase("KICK")) {
|
||||||
user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', kickReason));
|
user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', kickReason));
|
||||||
AntiCheatReloaded.getPlugin().onPlayerKicked();
|
AntiCheatReloaded.getPlugin().onPlayerKicked();
|
||||||
String msg = ChatColor.translateAlternateColorCodes('&',
|
String msg = ChatColor.translateAlternateColorCodes('&',
|
||||||
@@ -208,14 +218,14 @@ public final class UserManager {
|
|||||||
manager.log(msg);
|
manager.log(msg);
|
||||||
manager.playerLog(msg);
|
manager.playerLog(msg);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("WARN")) {
|
} else if (action.equalsIgnoreCase("WARN")) {
|
||||||
List<String> message = warning;
|
List<String> message = warning;
|
||||||
for (String string : message) {
|
for (String string : message) {
|
||||||
if (!string.equals("")) {
|
if (!string.equals("")) {
|
||||||
user.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
user.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("BAN")) {
|
} else if (action.equalsIgnoreCase("BAN")) {
|
||||||
Bukkit.getBanList(Type.NAME).addBan(user.getPlayer().getName(),
|
Bukkit.getBanList(Type.NAME).addBan(user.getPlayer().getName(),
|
||||||
ChatColor.translateAlternateColorCodes('&', banReason), null, null);
|
ChatColor.translateAlternateColorCodes('&', banReason), null, null);
|
||||||
user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', banReason));
|
user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', banReason));
|
||||||
@@ -226,7 +236,7 @@ public final class UserManager {
|
|||||||
manager.log(msg);
|
manager.log(msg);
|
||||||
manager.playerLog(msg);
|
manager.playerLog(msg);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("RESET")) {
|
} else if (action.equalsIgnoreCase("RESET")) {
|
||||||
user.resetLevel();
|
user.resetLevel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user