2012-04-26 23:36:43 +02:00
|
|
|
package fr.neatmonster.nocheatplus;
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-11 02:36:46 +02:00
|
|
|
import java.lang.reflect.Field;
|
2012-04-05 18:24:39 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-08-11 16:43:27 +02:00
|
|
|
import net.minecraft.server.DedicatedServer;
|
|
|
|
import net.minecraft.server.EntityPlayer;
|
2012-08-11 02:36:46 +02:00
|
|
|
import net.minecraft.server.NetServerHandler;
|
|
|
|
import net.minecraft.server.NetworkManager;
|
|
|
|
|
2012-04-05 18:24:39 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2012-08-11 02:36:46 +02:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
2012-04-05 18:24:39 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2012-08-12 15:28:37 +02:00
|
|
|
import org.bukkit.event.player.PlayerLoginEvent;
|
2012-04-05 18:24:39 +02:00
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2012-08-08 20:07:13 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.ExecuteActionsEvent;
|
2012-08-03 16:48:06 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.Workarounds;
|
2012-04-26 23:36:43 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener;
|
2012-08-06 02:43:01 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractListener;
|
2012-04-26 23:36:43 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener;
|
|
|
|
import fr.neatmonster.nocheatplus.checks.chat.ChatListener;
|
2012-08-05 13:09:57 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.fight.FightListener;
|
2012-08-05 20:00:05 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
|
2012-04-26 23:36:43 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
|
|
|
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
|
|
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
2012-08-03 16:48:06 +02:00
|
|
|
import fr.neatmonster.nocheatplus.players.Permissions;
|
2012-04-26 23:36:43 +02:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
/*
|
|
|
|
* M"""""""`YM MM'""""'YMM dP dP MM"""""""`YM dP
|
|
|
|
* M mmmm. M M' .mmm. `M 88 88 MM mmmmm M 88
|
|
|
|
* M MMMMM M .d8888b. M MMMMMooM 88d888b. .d8888b. .d8888b. d8888P M' .M 88 dP dP .d8888b.
|
|
|
|
* M MMMMM M 88' `88 M MMMMMMMM 88' `88 88ooood8 88' `88 88 MM MMMMMMMM 88 88 88 Y8ooooo.
|
|
|
|
* M MMMMM M 88. .88 M. `MMM' .M 88 88 88. ... 88. .88 88 MM MMMMMMMM 88 88. .88 88
|
|
|
|
* M MMMMM M `88888P' MM. .dM dP dP `88888P' `88888P8 dP MM MMMMMMMM dP `88888P' `88888P'
|
|
|
|
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* This is the main class of NoCheatPlus. The commands, events listeners and tasks are registered here.
|
|
|
|
*/
|
2012-04-26 23:36:43 +02:00
|
|
|
public class NoCheatPlus extends JavaPlugin implements Listener {
|
2012-08-03 17:34:52 +02:00
|
|
|
public static long time = System.currentTimeMillis();
|
|
|
|
|
2012-08-11 02:36:46 +02:00
|
|
|
/** The listeners. */
|
2012-04-26 23:36:43 +02:00
|
|
|
private List<Listener> listeners;
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
|
|
|
|
*/
|
2012-04-05 18:24:39 +02:00
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
|
|
|
final PluginDescriptionFile pdfFile = getDescription();
|
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Stop the lag measuring task.
|
|
|
|
LagMeasureTask.cancel();
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Cleanup the configuration manager.
|
2012-04-26 23:36:43 +02:00
|
|
|
ConfigManager.cleanup();
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Just to be sure nothing gets left out.
|
2012-04-05 18:24:39 +02:00
|
|
|
getServer().getScheduler().cancelTasks(this);
|
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Tell the server administrator the we finished unloading NoCheatPlus.
|
|
|
|
System.out.println("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
|
2012-04-05 18:24:39 +02:00
|
|
|
}
|
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
|
|
|
|
*/
|
2012-04-05 18:24:39 +02:00
|
|
|
@Override
|
|
|
|
public void onEnable() {
|
2012-08-03 16:48:06 +02:00
|
|
|
// Read the configuration files.
|
|
|
|
ConfigManager.init(this);
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// List the events listeners.
|
2012-04-26 23:36:43 +02:00
|
|
|
listeners = new ArrayList<Listener>();
|
|
|
|
listeners.add(new BlockBreakListener());
|
2012-08-06 02:43:01 +02:00
|
|
|
listeners.add(new BlockInteractListener());
|
2012-04-26 23:36:43 +02:00
|
|
|
listeners.add(new BlockPlaceListener());
|
|
|
|
listeners.add(new ChatListener());
|
2012-08-05 13:09:57 +02:00
|
|
|
listeners.add(new FightListener());
|
2012-08-05 20:00:05 +02:00
|
|
|
listeners.add(new InventoryListener());
|
2012-04-26 23:36:43 +02:00
|
|
|
listeners.add(new MovingListener());
|
2012-08-03 16:48:06 +02:00
|
|
|
listeners.add(new Workarounds());
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Set up a task to monitor server lag.
|
|
|
|
LagMeasureTask.start(this);
|
2012-04-05 18:24:39 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Register all listeners.
|
2012-04-26 23:36:43 +02:00
|
|
|
for (final Listener listener : listeners)
|
|
|
|
Bukkit.getPluginManager().registerEvents(listener, this);
|
2012-04-05 18:24:39 +02:00
|
|
|
Bukkit.getPluginManager().registerEvents(this, this);
|
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Register the commands handler.
|
|
|
|
getCommand("nocheatplus").setExecutor(new CommandHandler(this));
|
2012-04-26 23:36:43 +02:00
|
|
|
|
2012-08-11 16:43:27 +02:00
|
|
|
// Set the NetServerHandler of every player.
|
|
|
|
for (final Player player : Bukkit.getOnlinePlayers())
|
|
|
|
setCustomNetServerHandler(player);
|
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
// Tell the server administrator that we finished loading NoCheatPlus now.
|
|
|
|
System.out.println("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
|
2012-04-05 18:24:39 +02:00
|
|
|
}
|
|
|
|
|
2012-08-11 02:36:46 +02:00
|
|
|
/**
|
|
|
|
* This event handler is used to execute the actions when a violation is detected.
|
|
|
|
*
|
|
|
|
* @param event
|
|
|
|
* the event handled
|
|
|
|
*/
|
|
|
|
@EventHandler(
|
|
|
|
priority = EventPriority.LOWEST)
|
|
|
|
final void onExecuteActions(final ExecuteActionsEvent event) {
|
|
|
|
event.executeActions();
|
|
|
|
}
|
2012-08-12 15:28:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting the net server handler at the earliest possible point.
|
|
|
|
* @param event
|
|
|
|
*/
|
|
|
|
@EventHandler(
|
|
|
|
priority = EventPriority.LOWEST)
|
|
|
|
public void onPlayerLogin(final PlayerLoginEvent event) {
|
|
|
|
// Set the NetServerHandler of the player.
|
|
|
|
setCustomNetServerHandler(event.getPlayer());
|
|
|
|
}
|
2012-08-11 02:36:46 +02:00
|
|
|
|
2012-08-03 16:48:06 +02:00
|
|
|
/**
|
|
|
|
* This event handler is used to send all the disabling messages to the client.
|
|
|
|
*
|
|
|
|
* @param event
|
|
|
|
* the event handled
|
|
|
|
*/
|
2012-04-05 18:24:39 +02:00
|
|
|
@EventHandler(
|
2012-08-11 02:36:46 +02:00
|
|
|
priority = EventPriority.MONITOR)
|
2012-04-05 18:24:39 +02:00
|
|
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
|
|
|
final Player player = event.getPlayer();
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Check if we allow all the client mods.
|
|
|
|
final boolean allowAll = ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS);
|
2012-04-05 18:24:39 +02:00
|
|
|
String message = "";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Allow Rei's Minimap's cave mode.
|
|
|
|
if (allowAll || player.hasPermission(Permissions.REI_CAVE))
|
|
|
|
message = message + "§0§0§1§e§f";
|
|
|
|
|
|
|
|
// Allow Rei's Minimap's radar.
|
|
|
|
if (allowAll || player.hasPermission(Permissions.REI_RADAR))
|
|
|
|
message = message + "§0§0§2§3§4§5§6§7§e§f";
|
|
|
|
|
|
|
|
// If all the client mods are allowed, no need to go any further.
|
|
|
|
if (allowAll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Disable Zombe's fly mod.
|
|
|
|
if (!player.hasPermission(Permissions.ZOMBE_FLY))
|
2012-04-05 18:24:39 +02:00
|
|
|
message = message + "§f §f §1 §0 §2 §4";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Zombe's noclip.
|
|
|
|
if (!player.hasPermission(Permissions.ZOMBE_NOCLIP))
|
2012-04-05 22:17:41 +02:00
|
|
|
message = message + "§f §f §4 §0 §9 §6";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Zombe's cheat.
|
|
|
|
if (!player.hasPermission(Permissions.ZOMBE_CHEAT))
|
2012-04-05 18:24:39 +02:00
|
|
|
message = message + "§f §f §2 §0 §4 §8";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable CJB's fly mod.
|
|
|
|
if (!player.hasPermission(Permissions.CJB_FLY))
|
2012-04-05 18:24:39 +02:00
|
|
|
message = message + "§3 §9 §2 §0 §0 §1";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable CJB's xray.
|
|
|
|
if (!player.hasPermission(Permissions.CJB_XRAY))
|
2012-04-05 18:24:39 +02:00
|
|
|
message = message + "§3 §9 §2 §0 §0 §2";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable CJB's radar.
|
|
|
|
if (!player.hasPermission(Permissions.CJB_RADAR))
|
2012-04-05 18:24:39 +02:00
|
|
|
message = message + "§3 §9 §2 §0 §0 §3";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Minecraft AutoMap's ores.
|
|
|
|
if (!player.hasPermission(Permissions.MINECRAFTAUTOMAP_ORES))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§0§1§f§e";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Minecraft AutoMap's cave mode.
|
|
|
|
if (!player.hasPermission(Permissions.MINECRAFTAUTOMAP_CAVE))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§0§2§f§e";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Minecraft AutoMap's radar.
|
|
|
|
if (!player.hasPermission(Permissions.MINECRAFTAUTOMAP_RADAR))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§0§3§4§5§6§7§8§f§e";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_CLIMBING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§0§1§2§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_SWIMMING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§3§4§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_CRAWLING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§5§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_SLIDING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§6§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_JUMPING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§8§9§a§b§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
|
|
|
// Disable Smart Moving's climbing.
|
|
|
|
if (!player.hasPermission(Permissions.SMARTMOVING_FLYING))
|
2012-04-11 23:17:14 +02:00
|
|
|
message = message + "§0§1§7§f§f";
|
2012-08-03 16:48:06 +02:00
|
|
|
|
2012-04-05 18:24:39 +02:00
|
|
|
player.sendMessage(message);
|
|
|
|
}
|
2012-08-11 02:36:46 +02:00
|
|
|
|
2012-08-11 16:43:27 +02:00
|
|
|
private boolean setCustomNetServerHandler(final Player player) {
|
|
|
|
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
|
|
|
|
final NetServerHandler oldNSH = entityPlayer.netServerHandler;
|
|
|
|
if (oldNSH instanceof CustomNetServerHandler)
|
|
|
|
return false;
|
|
|
|
final DedicatedServer server = ((CraftServer) Bukkit.getServer()).getHandle().getServer();
|
|
|
|
final NetServerHandler newNSH = new CustomNetServerHandler(server, oldNSH.networkManager, entityPlayer);
|
|
|
|
newNSH.a(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player
|
|
|
|
.getLocation().getYaw(), player.getLocation().getPitch());
|
|
|
|
entityPlayer.netServerHandler = newNSH;
|
|
|
|
try {
|
|
|
|
final Field field = NetworkManager.class.getDeclaredField("packetListener");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(oldNSH.networkManager, newNSH);
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
2012-08-11 02:36:46 +02:00
|
|
|
}
|
2012-08-11 16:43:27 +02:00
|
|
|
oldNSH.disconnected = true;
|
|
|
|
server.ac().a(newNSH);
|
|
|
|
return true;
|
2012-08-08 20:07:13 +02:00
|
|
|
}
|
2012-04-05 18:24:39 +02:00
|
|
|
}
|