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
+115 -40

No files matched your search

@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@@ -67,9 +68,14 @@ public class SpeedCheck {
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
reason = "while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
}
if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().name().endsWith("ICE")) {
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();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
@@ -65,7 +65,11 @@ public class CommandBase {
if (permission.get(cs)) {
execute(cs, args);
} 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.CommandReport;
import com.rammelkast.anticheatreloaded.command.executors.CommandReset;
import com.rammelkast.anticheatreloaded.command.executors.CommandVersion;
public class CommandHandler implements CommandExecutor {
@@ -46,6 +47,7 @@ public class CommandHandler implements CommandExecutor {
commands.add(new CommandReload());
commands.add(new CommandReport());
commands.add(new CommandReset());
commands.add(new CommandVersion());
}
@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,
/* 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;
private static final String PERMISSION_ALL = "anticheat.*";
@@ -35,11 +35,13 @@ public class UpdateManager {
private final String latestVersion;
private final boolean isLatest;
private final boolean isAhead;
public UpdateManager() {
this.latestVersion = this.getOnlineData(SPIGOT_VERSION_URL);
if (this.latestVersion == null) {
this.isLatest = true;
this.isAhead = false;
return;
}
@@ -50,6 +52,7 @@ public class UpdateManager {
splitCompare = currentSplit.compareTo(newSplit);
} catch (Exception e) {}
this.isLatest = splitCompare >= 0;
this.isAhead = splitCompare > 0;
}
private String getOnlineData(String url) {
@@ -64,9 +67,8 @@ public class UpdateManager {
builder.append((char) readChar);
}
data = builder.toString();
} catch (IOException exception) {
// TODO possibly handle this neatly?
} finally {
} catch (IOException exception) {}
finally {
if (stream != null) {
try {
stream.close();
@@ -80,35 +82,43 @@ public class UpdateManager {
public boolean isLatest() {
return this.isLatest;
}
public boolean isAhead() {
return this.isAhead;
}
public String getCurrentVersion() {
return AntiCheatReloaded.getVersion();
}
public String getLatestVersion() {
return this.latestVersion;
}
public class VersionSplit implements Comparable<VersionSplit> {
private final int major, sub, minor;
private final int major, minor, build;
public VersionSplit(String version) throws Exception {
if (version.endsWith("-ALPHA")) {
version = version.substring(0, version.length() - 6);
}
String[] versionSplit = version.split(".");
String[] versionSplit = version.split("\\.");
if (versionSplit.length != 3) {
// Illegal version
throw new Exception("Illegal version!");
throw new Exception("Version " + version + " is illegal!");
}
try {
int major = Integer.parseInt(versionSplit[0]);
int sub = Integer.parseInt(versionSplit[1]);
int minor = Integer.parseInt(versionSplit[2]);
int minor = Integer.parseInt(versionSplit[1]);
int build = Integer.parseInt(versionSplit[2]);
if (major <= 0) {
throw new Exception("Illegal version!");
}
this.major = major;
this.sub = sub;
this.minor = minor;
this.build = build;
} catch (Exception e) {
throw new Exception("Illegal version!");
}
@@ -116,43 +126,38 @@ public class UpdateManager {
@Override
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) {
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;
return 1;
}
public int getMajor() {
return major;
}
public int getSub() {
return sub;
}
public int getMinor() {
return minor;
}
public int getBuild() {
return build;
}
}
}