Upload files
This commit is contained in:
Executable
+16
@@ -0,0 +1,16 @@
|
||||
# F Key Command by Akkariin
|
||||
# Support PlaceholderAPI variable, you need to install the PlaceholderAPI plugin.
|
||||
# Support multiple command, Separate each command with ";".
|
||||
# If the command has a ";", you can use %3B to replace it.
|
||||
# Press the F key under normal status.
|
||||
NormalF: ""
|
||||
# Press the F key under sneaking status.
|
||||
SneakingF: ""
|
||||
# Press the F key under look up status.
|
||||
LookUpF: ""
|
||||
# Press the F key under look down status.
|
||||
LookDownF: ""
|
||||
# The command cooldown time(seconds)
|
||||
Delay: 0
|
||||
# If the player press the key too fast
|
||||
TooFast: "&c[&6FKeyCommand&c] &ePlease slow down."
|
||||
Executable
+169
@@ -0,0 +1,169 @@
|
||||
package net.zerodream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class fkey extends JavaPlugin implements Listener {
|
||||
|
||||
public static Boolean usePlaceholder = true;
|
||||
public static FileConfiguration config;
|
||||
public Map<String, Long> cooldown = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
getLogger().info("FKeyCommand Enable!");
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
Bukkit.getPluginCommand("fkey").setExecutor(this);
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
getLogger().info("Plugin config folder not exist");
|
||||
}
|
||||
if (!file.exists()) {
|
||||
this.saveDefaultConfig();
|
||||
getLogger().info("Successful save config!");
|
||||
this.reloadConfig();
|
||||
getLogger().info("New config is loaded to memory");
|
||||
}
|
||||
config = this.load(file);
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
getLogger().info("Found PlaceholderAPI plugin, the variable is available now");
|
||||
usePlaceholder = true;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
float view = player.getLocation().getPitch();
|
||||
if (view <= -80) {
|
||||
this.runCommand(player, "LookUpF", event);
|
||||
return;
|
||||
}
|
||||
if (view >= 80) {
|
||||
this.runCommand(player, "LookDownF", event);
|
||||
return;
|
||||
}
|
||||
if (player.isSneaking()) {
|
||||
this.runCommand(player, "SneakingF", event);
|
||||
return;
|
||||
}
|
||||
this.runCommand(player, "NormalF", event);
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player, String perm) {
|
||||
return (player.hasPermission("fkey." + perm.toLowerCase()) || player.hasPermission("fkey.*") || player.hasPermission("fkey.use") || player.isOp());
|
||||
}
|
||||
|
||||
private void runCommand(Player player, String name, PlayerSwapHandItemsEvent event) {
|
||||
String command = config.getString(name);
|
||||
if (command == null || command.equals("")) {
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
if (!checkPermission(player, name)) {
|
||||
sendMsg(player, "&cYou don't have permission to do this.");
|
||||
return;
|
||||
}
|
||||
int wait = config.getInt("Delay") * 1000;
|
||||
if (!cooldown.containsKey(player.getUniqueId().toString())) {
|
||||
cooldown.put(player.getUniqueId().toString(), new Date().getTime() - wait);
|
||||
} else {
|
||||
long latest = cooldown.get(player.getUniqueId().toString()) + wait;
|
||||
if (new Date().getTime() < latest) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', config.getString("TooFast"));
|
||||
if (usePlaceholder) {
|
||||
message = format(player, message);
|
||||
}
|
||||
player.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (command.contains(";")) {
|
||||
String[] cmds = command.split(";");
|
||||
for (String cmd : cmds) {
|
||||
cmd = cmd.replace("%3B", ";");
|
||||
if (usePlaceholder) {
|
||||
cmd = format(player, cmd);
|
||||
}
|
||||
player.chat("/" + cmd);
|
||||
}
|
||||
} else {
|
||||
if (usePlaceholder) {
|
||||
command = format(player, command);
|
||||
}
|
||||
player.chat("/" + command);
|
||||
}
|
||||
cooldown.replace(player.getUniqueId().toString(), new Date().getTime());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public String format(Player player, String str) {
|
||||
try {
|
||||
str = PlaceholderAPI.setPlaceholders(player, str);
|
||||
} catch (java.lang.NoClassDefFoundError ex) {
|
||||
getLogger().info(ex.getLocalizedMessage());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("fkey")) {
|
||||
if (sender instanceof Player) {
|
||||
if (!Bukkit.getPlayer(sender.getName()).hasPermission("fkey.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "Permission denied");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (args[0].toLowerCase().equals("reload")) {
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
config = this.load(file);
|
||||
sendMsg(sender, "&aConfig reload successful");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
pluginHelp(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void pluginHelp(CommandSender sender) {
|
||||
sendMsg(sender, "&c&l—[ &6F Key &bCommand &c&l]—");
|
||||
sendMsg(sender, "&c/fkey help &6Display this help");
|
||||
sendMsg(sender, "&c/fkey reload &6Reload config");
|
||||
}
|
||||
|
||||
private void sendMsg(CommandSender sender, String msg) {
|
||||
msg = ChatColor.translateAlternateColorCodes('&', msg);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
|
||||
public FileConfiguration load(File file) {
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
name: FKeyCommand
|
||||
main: net.zerodream.fkey
|
||||
version: 1.2.0
|
||||
author: Akkariin
|
||||
softdepend: [PlaceholderAPI]
|
||||
|
||||
commands:
|
||||
fkey:
|
||||
description: "F key command"
|
||||
usage: "§c/fkey §6F key command"
|
||||
permission: "fkey.use"
|
||||
permission-message: "§6You don't have permission §cfkey.use"
|
||||
Reference in New Issue
Block a user