Introduced version command, fixed #58

This commit is contained in:
Rammelkast committed 2020-04-01 12:53:25 +02:00
1 parent d41d08ccc6
commit 7e37e8558b
7 files changed
+114 -39

No files matched your search

@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@@ -67,8 +68,13 @@ public class SpeedCheck {
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION(); max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
} }
} else if (player.isSprinting()) { } else if (player.isSprinting()) {
reason = "while sprinting "; if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().name().endsWith("ICE")) {
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT(); reason = "while sprinting on ice ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT() + 0.165D;
} else {
reason = "while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
}
} }
float speed = player.getWalkSpeed(); float speed = player.getWalkSpeed();
@@ -65,7 +65,11 @@ public class CommandBase {
if (permission.get(cs)) { if (permission.get(cs)) {
execute(cs, args); execute(cs, args);
} else { } else {
cs.sendMessage(PERMISSIONS_ERROR + " (" + WHITE + permission.toString() + RED + ")"); if (args == null) {
cs.sendMessage(GOLD + "" + ChatColor.BOLD + "AntiCheatReloaded " + GRAY + "version " + AntiCheatReloaded.getVersion());
} else {
cs.sendMessage(PERMISSIONS_ERROR + " (" + WHITE + permission.toString() + RED + ")");
}
} }
} }
@@ -33,6 +33,7 @@ import com.rammelkast.anticheatreloaded.command.executors.CommandLog;
import com.rammelkast.anticheatreloaded.command.executors.CommandReload; import com.rammelkast.anticheatreloaded.command.executors.CommandReload;
import com.rammelkast.anticheatreloaded.command.executors.CommandReport; import com.rammelkast.anticheatreloaded.command.executors.CommandReport;
import com.rammelkast.anticheatreloaded.command.executors.CommandReset; import com.rammelkast.anticheatreloaded.command.executors.CommandReset;
import com.rammelkast.anticheatreloaded.command.executors.CommandVersion;
public class CommandHandler implements CommandExecutor { public class CommandHandler implements CommandExecutor {
@@ -46,6 +47,7 @@ public class CommandHandler implements CommandExecutor {
commands.add(new CommandReload()); commands.add(new CommandReload());
commands.add(new CommandReport()); commands.add(new CommandReport());
commands.add(new CommandReset()); commands.add(new CommandReset());
commands.add(new CommandVersion());
} }
@Override @Override
@@ -0,0 +1,58 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 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.command.executors;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
import com.rammelkast.anticheatreloaded.util.UpdateManager;
public class CommandVersion extends CommandBase {
private static final String NAME = "AntiCheatReloaded Version";
private static final String COMMAND = "version";
private static final String USAGE = "anticheat version";
private static final Permission PERMISSION = Permission.SYSTEM_NOTICE;
private static final String[] HELP = {
GRAY + "Use: " + AQUA + "/anticheat version" + GRAY + " to get update information", };
public CommandVersion() {
super(NAME, COMMAND, USAGE, HELP, PERMISSION);
}
@Override
protected void execute(CommandSender cs, String[] args) {
UpdateManager updateManager = AntiCheatReloaded.getUpdateManager();
String status = RED + "behind";
if (updateManager.isLatest()) {
if (updateManager.isAhead()) {
status = GREEN + "ahead";
} else {
status = GOLD + "up-to-date";
}
}
cs.sendMessage(GOLD + "" + ChatColor.BOLD + "ACR " + GRAY + "You are running version " + GOLD
+ updateManager.getCurrentVersion() + GRAY + ". The latest version is " + GOLD
+ updateManager.getLatestVersion() + GRAY + ". This means you are " + status + GRAY + ".");
}
}
@@ -29,7 +29,7 @@ public enum Permission {
CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_BLINK, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGAL_INTERACT, CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_BLINK, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGAL_INTERACT,
/* System Nodes */ /* System Nodes */
SYSTEM_LOG, SYSTEM_RESET, SYSTEM_SPY, SYSTEM_HELP, SYSTEM_UPDATE, SYSTEM_REPORT, SYSTEM_ALERT, SYSTEM_NOTICE, SYSTEM_LOG, SYSTEM_RESET, SYSTEM_SPY, SYSTEM_HELP, SYSTEM_VERSION, SYSTEM_REPORT, SYSTEM_ALERT, SYSTEM_NOTICE,
SYSTEM_CALIBRATE, SYSTEM_CHECK, SYSTEM_DEBUG, SYSTEM_RELOAD; SYSTEM_CALIBRATE, SYSTEM_CHECK, SYSTEM_DEBUG, SYSTEM_RELOAD;
private static final String PERMISSION_ALL = "anticheat.*"; private static final String PERMISSION_ALL = "anticheat.*";
@@ -35,11 +35,13 @@ public class UpdateManager {
private final String latestVersion; private final String latestVersion;
private final boolean isLatest; private final boolean isLatest;
private final boolean isAhead;
public UpdateManager() { public UpdateManager() {
this.latestVersion = this.getOnlineData(SPIGOT_VERSION_URL); this.latestVersion = this.getOnlineData(SPIGOT_VERSION_URL);
if (this.latestVersion == null) { if (this.latestVersion == null) {
this.isLatest = true; this.isLatest = true;
this.isAhead = false;
return; return;
} }
@@ -50,6 +52,7 @@ public class UpdateManager {
splitCompare = currentSplit.compareTo(newSplit); splitCompare = currentSplit.compareTo(newSplit);
} catch (Exception e) {} } catch (Exception e) {}
this.isLatest = splitCompare >= 0; this.isLatest = splitCompare >= 0;
this.isAhead = splitCompare > 0;
} }
private String getOnlineData(String url) { private String getOnlineData(String url) {
@@ -64,9 +67,8 @@ public class UpdateManager {
builder.append((char) readChar); builder.append((char) readChar);
} }
data = builder.toString(); data = builder.toString();
} catch (IOException exception) { } catch (IOException exception) {}
// TODO possibly handle this neatly? finally {
} finally {
if (stream != null) { if (stream != null) {
try { try {
stream.close(); stream.close();
@@ -81,34 +83,42 @@ public class UpdateManager {
return this.isLatest; return this.isLatest;
} }
public boolean isAhead() {
return this.isAhead;
}
public String getCurrentVersion() {
return AntiCheatReloaded.getVersion();
}
public String getLatestVersion() { public String getLatestVersion() {
return this.latestVersion; return this.latestVersion;
} }
public class VersionSplit implements Comparable<VersionSplit> { public class VersionSplit implements Comparable<VersionSplit> {
private final int major, sub, minor; private final int major, minor, build;
public VersionSplit(String version) throws Exception { public VersionSplit(String version) throws Exception {
if (version.endsWith("-ALPHA")) { if (version.endsWith("-ALPHA")) {
version = version.substring(0, version.length() - 6); version = version.substring(0, version.length() - 6);
} }
String[] versionSplit = version.split("."); String[] versionSplit = version.split("\\.");
if (versionSplit.length != 3) { if (versionSplit.length != 3) {
// Illegal version // Illegal version
throw new Exception("Illegal version!"); throw new Exception("Version " + version + " is illegal!");
} }
try { try {
int major = Integer.parseInt(versionSplit[0]); int major = Integer.parseInt(versionSplit[0]);
int sub = Integer.parseInt(versionSplit[1]); int minor = Integer.parseInt(versionSplit[1]);
int minor = Integer.parseInt(versionSplit[2]); int build = Integer.parseInt(versionSplit[2]);
if (major <= 0) { if (major <= 0) {
throw new Exception("Illegal version!"); throw new Exception("Illegal version!");
} }
this.major = major; this.major = major;
this.sub = sub;
this.minor = minor; this.minor = minor;
this.build = build;
} catch (Exception e) { } catch (Exception e) {
throw new Exception("Illegal version!"); throw new Exception("Illegal version!");
} }
@@ -116,43 +126,38 @@ public class UpdateManager {
@Override @Override
public int compareTo(VersionSplit other) { public int compareTo(VersionSplit other) {
if (other.major == this.major) {
if (other.minor == this.minor) {
if (other.build == this.build) {
return 0;
}
if (other.build > this.build) {
return -1;
}
return 1;
}
if (other.minor > this.minor) {
return -1;
}
return 1;
}
if (other.major > this.major) { if (other.major > this.major) {
return -1; return -1;
} }
return 1;
if (other.major < this.major) {
return 1;
}
if (other.sub > this.sub) {
return -1;
}
if (other.sub < this.sub) {
return 1;
}
if (other.minor > this.minor) {
return -1;
}
if (other.minor < this.minor) {
return 1;
}
return 0;
} }
public int getMajor() { public int getMajor() {
return major; return major;
} }
public int getSub() {
return sub;
}
public int getMinor() { public int getMinor() {
return minor; return minor;
} }
public int getBuild() {
return build;
}
} }
} }
+1 -1
View File
@@ -36,7 +36,7 @@ permissions:
description: Access reloading the system description: Access reloading the system
anticheat.system.reset: anticheat.system.reset:
description: Access resetting a player's cheat level description: Access resetting a player's cheat level
anticheat.system.update: anticheat.system.version:
description: Access information about whether the system is updated description: Access information about whether the system is updated
anticheat.system.calibrate: anticheat.system.calibrate:
description: Access the calibration system description: Access the calibration system