Add /tpslimit Command
Dieser Commit ist enthalten in:
Ursprung
9dd02f6c52
Commit
eeef18d504
@ -98,6 +98,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
getCommand("trace").setExecutor(new CommandTrace());
|
||||
getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
|
||||
getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
|
||||
getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
|
||||
getCommand("nightvision").setExecutor(new CommandNV());
|
||||
getCommand("reset").setExecutor(new CommandReset());
|
||||
getCommand("speed").setExecutor(new CommandSpeed());
|
||||
|
100
BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java
Normale Datei
100
BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java
Normale Datei
@ -0,0 +1,100 @@
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
public class CommandTPSLimiter implements CommandExecutor {
|
||||
|
||||
private static int currentTPSLimit = 20;
|
||||
private static World world = Bukkit.getWorlds().get(0);
|
||||
private long lastTime = System.currentTimeMillis();
|
||||
private long currentTime = System.currentTimeMillis();
|
||||
|
||||
public CommandTPSLimiter() {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
lastTime = currentTime;
|
||||
currentTime = System.currentTimeMillis();
|
||||
|
||||
long timeDelta = currentTime - lastTime;
|
||||
long neededDelta = 1000 / currentTPSLimit;
|
||||
|
||||
if (neededDelta - timeDelta < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(neededDelta - timeDelta);
|
||||
currentTime = System.currentTimeMillis();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}, 0, 1);
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> {
|
||||
if (currentTPSLimit == 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
world.getEntities().stream().filter(entity -> entity instanceof TNTPrimed).forEach(entity -> {
|
||||
Location location = entity.getLocation();
|
||||
world.spawnParticle(Particle.BARRIER, location.getX(), location.getY() + 0.49, location.getZ(), 1);
|
||||
});
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return false;
|
||||
} else if (args.length == 0) {
|
||||
sender.sendMessage(BauSystem.PREFIX + "Jetziges TPS limit: " + currentTPSLimit);
|
||||
sender.sendMessage(BauSystem.PREFIX + "Ändere das TPS limit mit: §8/§etpslimit §8[§7TPS§8|§edefault§8]");
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
String tpsLimit = args[0];
|
||||
if (tpsLimit.equals("default")) {
|
||||
currentTPSLimit = 20;
|
||||
sendNewTPSLimitMessage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
int tpsLimitInt = Integer.parseInt(tpsLimit);
|
||||
if (tpsLimitInt < 1 || tpsLimitInt > 20) {
|
||||
sendInvalidArgumentMessage(player);
|
||||
return false;
|
||||
}
|
||||
currentTPSLimit = tpsLimitInt;
|
||||
sendNewTPSLimitMessage(player);
|
||||
} catch (NumberFormatException e) {
|
||||
sendInvalidArgumentMessage(player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendNewTPSLimitMessage(Player player) {
|
||||
player.sendMessage(BauSystem.PREFIX + "TPS limit auf " + currentTPSLimit + " gesetzt.");
|
||||
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt.")));
|
||||
}
|
||||
|
||||
private void sendInvalidArgumentMessage(Player player) {
|
||||
player.sendMessage(BauSystem.PREFIX + "Nur Zahlen zwischen 1 und 20, und 'default' erlaubt.");
|
||||
}
|
||||
|
||||
public static int getCurrentTPSLimit() {
|
||||
return currentTPSLimit;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandTPSLimiterTabComplete implements TabCompleter {
|
||||
|
||||
private List<String> arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20");
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 1) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> validArguments = new ArrayList<>(arguments.size());
|
||||
for (String s : arguments) {
|
||||
if (s.startsWith(args[0])) {
|
||||
validArguments.add(s);
|
||||
}
|
||||
}
|
||||
return validArguments;
|
||||
}
|
||||
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.bausystem.commands;
|
||||
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.core.Core;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.world;
|
||||
|
||||
import de.steamwar.bausystem.commands.CommandFreeze;
|
||||
import de.steamwar.bausystem.commands.CommandTNT;
|
||||
import de.steamwar.bausystem.commands.CommandTPSLimiter;
|
||||
import de.steamwar.bausystem.tracer.TraceManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.RecordManager;
|
||||
import de.steamwar.bausystem.tracer.recorder.TNTRecorder;
|
||||
@ -72,7 +73,11 @@ public class BauScoreboard implements Listener {
|
||||
}
|
||||
|
||||
strings.add("§4");
|
||||
if (CommandTPSLimiter.getCurrentTPSLimit() == 20) {
|
||||
strings.add("§eTPS§8: §7" + TPSWatcher.getTPS());
|
||||
} else {
|
||||
strings.add("§eTPS§8: §7" + TPSWatcher.getTPS() + " §eLimit§8: §7" + CommandTPSLimiter.getCurrentTPSLimit());
|
||||
}
|
||||
|
||||
int i = strings.size();
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
|
@ -11,6 +11,7 @@ commands:
|
||||
tnt:
|
||||
fire:
|
||||
trace:
|
||||
tpslimit:
|
||||
testblock:
|
||||
aliases: tb
|
||||
reset:
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren