mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 13:57:49 +01:00
Only show version warning if an unsupported CraftBukkit version is
used + real MC 1.0.0 support without losing MC 1.8.1 Beta support.
This commit is contained in:
parent
36b97f246a
commit
48d6c141ca
6
pom.xml
6
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>NoCheat</groupId>
|
<groupId>NoCheat</groupId>
|
||||||
<artifactId>NoCheat</artifactId>
|
<artifactId>NoCheat</artifactId>
|
||||||
<version>2.16d</version>
|
<version>2.17</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>NoCheat</name>
|
<name>NoCheat</name>
|
||||||
<properties>
|
<properties>
|
||||||
@ -19,7 +19,9 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>1.8.1-R5-SNAPSHOT</version>
|
<version>1.8.1-R5-20111119.223146-84</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -20,15 +20,14 @@ import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager;
|
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
|
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.FightEventManager;
|
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager;
|
import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.events.FightEventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.MovingEventManager;
|
import cc.co.evenprime.bukkit.nocheat.events.MovingEventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager;
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.events.TimedEventManager;
|
import cc.co.evenprime.bukkit.nocheat.events.TimedEventManager;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager;
|
||||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||||
import cc.co.evenprime.bukkit.nocheat.log.LogManager;
|
import cc.co.evenprime.bukkit.nocheat.log.LogManager;
|
||||||
|
|
||||||
@ -50,7 +49,13 @@ public class NoCheat extends JavaPlugin {
|
|||||||
|
|
||||||
private LagMeasureTask lagMeasureTask;
|
private LagMeasureTask lagMeasureTask;
|
||||||
|
|
||||||
private int taskId = -1;
|
private int taskId = -1;
|
||||||
|
|
||||||
|
private MCVersion mcVersion = MCVersion.Unknown;
|
||||||
|
|
||||||
|
public enum MCVersion {
|
||||||
|
MC100, MC181, Unknown
|
||||||
|
}
|
||||||
|
|
||||||
public NoCheat() {
|
public NoCheat() {
|
||||||
|
|
||||||
@ -86,7 +91,15 @@ public class NoCheat extends JavaPlugin {
|
|||||||
// First set up logging
|
// First set up logging
|
||||||
this.log = new LogManager();
|
this.log = new LogManager();
|
||||||
|
|
||||||
log.logToConsole(LogLevel.LOW, "[NoCheat] This version is for CB #1337. It may break at any time and for any other version.");
|
// find out Minecraft version
|
||||||
|
if(Bukkit.getVersion().contains("MC: 1.0.0")) {
|
||||||
|
this.mcVersion = MCVersion.MC100;
|
||||||
|
} else if(Bukkit.getVersion().contains("MC: 1.8.1")) {
|
||||||
|
this.mcVersion = MCVersion.MC181;
|
||||||
|
} else {
|
||||||
|
this.mcVersion = MCVersion.Unknown;
|
||||||
|
log.logToConsole(LogLevel.LOW, "[NoCheat] You run an unsupported version of Minecraft. Some parts of NoCheat get disabled for your safety.");
|
||||||
|
}
|
||||||
|
|
||||||
// Then set up in memory per player data storage
|
// Then set up in memory per player data storage
|
||||||
this.players = new PlayerManager(this);
|
this.players = new PlayerManager(this);
|
||||||
@ -106,7 +119,6 @@ public class NoCheat extends JavaPlugin {
|
|||||||
eventManagers.add(new BlockPlaceEventManager(this));
|
eventManagers.add(new BlockPlaceEventManager(this));
|
||||||
eventManagers.add(new FightEventManager(this));
|
eventManagers.add(new FightEventManager(this));
|
||||||
|
|
||||||
System.out.println(Bukkit.getVersion());
|
|
||||||
TimedEventManager m = new TimedEventManager(this);
|
TimedEventManager m = new TimedEventManager(this);
|
||||||
taskId = m.taskId; // There's a bukkit task, remember its id
|
taskId = m.taskId; // There's a bukkit task, remember its id
|
||||||
eventManagers.add(m);
|
eventManagers.add(m);
|
||||||
@ -194,4 +206,7 @@ public class NoCheat extends JavaPlugin {
|
|||||||
return players.getPlayer(player);
|
return players.getPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MCVersion getMCVersion() {
|
||||||
|
return mcVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||||
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.player.PlayerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide secure access to player-specific data objects for various checks or
|
* Provide secure access to player-specific data objects for various checks or
|
||||||
@ -36,9 +37,9 @@ public class PlayerManager {
|
|||||||
NoCheatPlayerImpl p = this.players.get(player.getName());
|
NoCheatPlayerImpl p = this.players.get(player.getName());
|
||||||
|
|
||||||
if(p == null) {
|
if(p == null) {
|
||||||
// TODO: Differentiate which player"type" should be created, e.g.
|
// PlayerFactory may create different players based on the
|
||||||
// based on bukkit version
|
// MCVersion that we are running
|
||||||
p = new NoCheatPlayerImpl(player, plugin, new BaseData());
|
p = PlayerFactory.createPlayer(player, plugin);
|
||||||
this.players.put(player.getName(), p);
|
this.players.put(player.getName(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,21 +33,9 @@ public class TimedEventManager extends EventManagerImpl {
|
|||||||
|
|
||||||
checks = new ArrayList<TimedCheck>(1);
|
checks = new ArrayList<TimedCheck>(1);
|
||||||
|
|
||||||
|
checks.add(new GodmodeCheck(plugin));
|
||||||
this.timedPerformance = plugin.getPerformance(Type.TIMED);
|
this.timedPerformance = plugin.getPerformance(Type.TIMED);
|
||||||
|
|
||||||
try {
|
|
||||||
// Get an error thrown if "entityPlayer.b(boolean)" doesn't exist
|
|
||||||
EntityPlayer.class.getMethod("b", boolean.class);
|
|
||||||
|
|
||||||
checks.add(new GodmodeCheck(plugin));
|
|
||||||
|
|
||||||
} catch(NoSuchMethodException e1) {
|
|
||||||
System.out.println("[NoCheat]: Couldn't find needed method for \"timed.godmode\" check, disabling it. You probably run an incompatible craftbukkit version.");
|
|
||||||
System.out.println("[NoCheat]: This problem may be fixed in a newer version of NoCheat (when available).");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// "register a listener" for passed time
|
// "register a listener" for passed time
|
||||||
this.taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
this.taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.player;
|
package cc.co.evenprime.bukkit.nocheat.player;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import net.minecraft.server.EntityPlayer;
|
import net.minecraft.server.EntityPlayer;
|
||||||
import net.minecraft.server.MobEffectList;
|
import net.minecraft.server.MobEffectList;
|
||||||
|
|
||||||
@ -14,12 +16,17 @@ import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
|||||||
|
|
||||||
public class NoCheatPlayerImpl implements NoCheatPlayer {
|
public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||||
|
|
||||||
private Player player;
|
protected Player player;
|
||||||
private final NoCheat plugin;
|
protected final NoCheat plugin;
|
||||||
private final BaseData data;
|
protected final BaseData data;
|
||||||
private long lastUsedTime;
|
protected long lastUsedTime;
|
||||||
|
|
||||||
|
// The method that's used to artifically "fast-forward" the player
|
||||||
|
protected static Method incAge = null;
|
||||||
|
|
||||||
public NoCheatPlayerImpl(Player player, NoCheat plugin, BaseData data) {
|
public NoCheatPlayerImpl(Player player, NoCheat plugin, BaseData data) {
|
||||||
|
|
||||||
|
System.out.println(incAge != null ? incAge.toString() : null);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@ -60,11 +67,20 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void increaseAge(int ticks) {
|
public void increaseAge(int ticks) {
|
||||||
|
|
||||||
|
if(incAge == null) {
|
||||||
|
player.setTicksLived(player.getTicksLived() + ticks);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||||
|
|
||||||
for(int i = 0; i < ticks; i++) {
|
for(int i = 0; i < ticks; i++) {
|
||||||
// TODO: This is highly fragile and breaks every update!!
|
try {
|
||||||
p.b(true); // Catch up with the server, one tick at a time
|
incAge.invoke(p, true);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package cc.co.evenprime.bukkit.nocheat.player;
|
||||||
|
|
||||||
|
import net.minecraft.server.EntityPlayer;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||||
|
|
||||||
|
public class NoCheatPlayer_100 extends NoCheatPlayerImpl {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
incAge = EntityPlayer.class.getMethod("a", boolean.class);
|
||||||
|
} catch(Exception e) {
|
||||||
|
System.out.println("NoCheat couldn't initialize variable incAge");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoCheatPlayer_100(Player player, NoCheat plugin, BaseData data) {
|
||||||
|
super(player, plugin, data);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cc.co.evenprime.bukkit.nocheat.player;
|
||||||
|
|
||||||
|
import net.minecraft.server.EntityPlayer;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||||
|
|
||||||
|
public class NoCheatPlayer_181 extends NoCheatPlayerImpl {
|
||||||
|
|
||||||
|
public NoCheatPlayer_181(Player player, NoCheat plugin, BaseData data) {
|
||||||
|
super(player, plugin, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
incAge = EntityPlayer.class.getMethod("b", boolean.class);
|
||||||
|
} catch(Exception e) {
|
||||||
|
System.out.println("NoCheat couldn't initialize variable incAge");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
src/cc/co/evenprime/bukkit/nocheat/player/PlayerFactory.java
Normal file
21
src/cc/co/evenprime/bukkit/nocheat/player/PlayerFactory.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package cc.co.evenprime.bukkit.nocheat.player;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||||
|
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||||
|
|
||||||
|
public class PlayerFactory {
|
||||||
|
|
||||||
|
public static NoCheatPlayerImpl createPlayer(Player player, NoCheat plugin) {
|
||||||
|
|
||||||
|
switch (plugin.getMCVersion()) {
|
||||||
|
case MC100:
|
||||||
|
return new NoCheatPlayer_100(player, plugin, new BaseData());
|
||||||
|
case MC181:
|
||||||
|
return new NoCheatPlayer_181(player, plugin, new BaseData());
|
||||||
|
default:
|
||||||
|
return new NoCheatPlayerImpl(player, plugin, new BaseData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user