Skip to content

Commit

Permalink
Fix for missing commands and commands being hijacked by EssentialsX.
Browse files Browse the repository at this point in the history
Removes ability to disable commands in the config.
  • Loading branch information
ShakeforProtein committed Jun 7, 2021
1 parent 5384c45 commit 6041b3a
Show file tree
Hide file tree
Showing 47 changed files with 1,748 additions and 286 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>TreeboTeleport</artifactId>
<version>2.0.0</version>
<version>2.0.2</version>
<packaging>jar</packaging>

<name>TreeboTeleport</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
Expand All @@ -11,7 +13,7 @@
import java.lang.reflect.Field;


public class AddMaxHomes {
public class AddMaxHomes implements CommandExecutor {

private TreeboTeleport pl;

Expand Down Expand Up @@ -79,4 +81,23 @@ private void registerNewCommand(String fallback, BukkitCommand command) {
e.printStackTrace();
}
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 2) {
sender.sendMessage(pl.err + "Incorrect usage. Correct usage is /addmaxhomes <player name> <amount>");
} else {
if (pl.isInteger(args[1])) {
Player p = Bukkit.getOfflinePlayer(args[0]).getPlayer();
int currentMaxHomes = getHomes(p);
int newHomes = currentMaxHomes + Integer.parseInt(args[1]);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + p.getName() + " add tbteleport.maxhomes." + newHomes);
sender.sendMessage(pl.badge + "Successfully set " + p.getName() + "'s maximum homes to " + getHomes(p));
} else {
sender.sendMessage(pl.err + "Second argument must be a number");
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.lang.reflect.Field;


public class Back {
public class Back implements CommandExecutor {

private TreeboTeleport pl;

Expand Down Expand Up @@ -67,4 +67,22 @@ private void registerNewCommand(String fallback, BukkitCommand command) {
e.printStackTrace();
}
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (sender instanceof Player) {
Player p = (Player) sender;

if (pl.lastLocConf.containsKey(p.getUniqueId())) {
p.sendMessage(pl.badge + "Sending you to your previous location");
p.teleport(pl.lastLocConf.get(p.getUniqueId()));
} else {
p.sendMessage(pl.err + "Could not find previous location");
}
} else {
sender.sendMessage(pl.badge + "This command can only be run by a player");
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import me.shakeforprotein.treeboteleport.TreeboTeleport;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;

public class Bed {
public class Bed implements CommandExecutor {

private TreeboTeleport pl;

Expand Down Expand Up @@ -48,4 +50,19 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}
return true;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player p = (Player) sender;

if (p.getBedSpawnLocation() != null) {
p.sendMessage(pl.badge + "Sending you to your bed");
p.teleport(p.getBedSpawnLocation());
} else {
p.sendMessage(pl.err + "Bed Missing");
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;

public class ClearMyChat {
public class ClearMyChat implements CommandExecutor {

private TreeboTeleport pl;

Expand Down Expand Up @@ -42,4 +41,13 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}
return true;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
int i;
for (i = 0; i < 30; i++) {
sender.sendMessage("");
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;

public class ConfigureHomes {
public class ConfigureHomes implements CommandExecutor {

private TreeboTeleport pl;
private File homeFile;
Expand Down Expand Up @@ -124,4 +126,55 @@ public void doHelp(CommandSender s) {
s.sendMessage("/configurehome set <current name> <icon | colour> <New Value>");
s.sendMessage("/configurehome set default <CurrentName>");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
homeFile = new File(pl.getPlayerDataFolder() + File.separator + ((Player) sender).getUniqueId(), File.separator + "homes"+ ".yml");
homeYaml = YamlConfiguration.loadConfiguration(homeFile);
boolean found = false;

if (args.length > 2) {
if (args[0].equalsIgnoreCase("set")) {
if (args[2].equalsIgnoreCase("colour") || args[2].equalsIgnoreCase("color") || args[2].equalsIgnoreCase("icon")) {
if (args[2].equalsIgnoreCase("colour") || args[2].equalsIgnoreCase("color")) {
for (String item : homeYaml.getConfigurationSection("homes").getKeys(false)) {
if (item.equalsIgnoreCase(args[1])) {
found = true;
try {
ChatColor newColour = ChatColor.valueOf(args[3].toUpperCase());
setYml(item, "colour", args[3].toUpperCase(), sender);
} catch (IllegalArgumentException e) {
sender.sendMessage("Unknown colour: '" + args[3].toUpperCase() + "'");
}
}
}
} else if (args[2].equalsIgnoreCase("icon")) {
for (String item : homeYaml.getConfigurationSection("homes").getKeys(false)) {
if (item.equalsIgnoreCase(args[1])) {
found = true;
if (Material.getMaterial(args[3].toUpperCase()) != null) {
setYml(item, "icon", args[3].toUpperCase(), sender);
} else {
sender.sendMessage(pl.err + "Unknown Item: '" + args[3].toUpperCase() + "'");
}
}
}
}
if (!found) {
sender.sendMessage(pl.err + "");
}
} else {
sender.sendMessage(pl.err + "Unknown argument '" + args[2] + "'");
}
} else {
sender.sendMessage(pl.err + "Unknown argument '" + args[0] + "'");
}
} else {
sender.sendMessage(pl.err + "Insufficient arguments");
doHelp(sender);
}
pl.saveFileConfigurationToFile(homeFile, homeYaml, sender);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;


public class ConfigureHubMenu {
public class ConfigureHubMenu implements CommandExecutor {

private TreeboTeleport pl;
private File hubFile;
Expand Down Expand Up @@ -134,4 +136,58 @@ public void doHelp(CommandSender s) {
s.sendMessage("Usage: /configureHub set <icon | label | command | colour> <existing table position> <New Value>");
s.sendMessage(" /configurehub set rows <amount> (1 - 6)");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (args.length == 0) {
sender.sendMessage(pl.err + "This command requires multiple inputs");
doHelp(sender);
} else if (args[0].equalsIgnoreCase("set")) {
if (args[2] != null) {
if (pl.isInteger(args[2])) {
if (args[1].equalsIgnoreCase("icon")) {
if (Material.getMaterial(args[3].toUpperCase()) != null) {
setYml(args[2], "icon", args[3].toUpperCase(), sender);
} else {
sender.sendMessage(pl.err + "Unknown Material -->" + args[3] + "<--");
}
} else if (args[1].equalsIgnoreCase("label")) {
int i;
StringBuilder labelText = new StringBuilder();
for (i = 3; i < args.length; i++) {
labelText.append(args[i] + " ");
}
setYml(args[2], "label", labelText.toString(), sender);
} else if (args[1].equalsIgnoreCase("position")) {

setYml(args[2], "position", args[3], sender);
} else if (args[1].equalsIgnoreCase("command")) {
int i;
StringBuilder commandText = new StringBuilder();
for (i = 3; i < args.length; i++) {
commandText.append(args[i] + " ");
}
setYml(args[2], "command", commandText.toString(), sender);
} else if (args[1].equalsIgnoreCase("colour") || args[1].equalsIgnoreCase("color")) {
if (args[1].equalsIgnoreCase("color")) {
sender.sendMessage("You seem to have dropped your U. Don't worry, I've made sure to include it with your other letters.");
}
setYml(args[2], "color", args[3], sender);
} else if (args[1].equalsIgnoreCase("rows")) {
setRows(args[2], sender);
}


} else {
sender.sendMessage(pl.err + "Expected integer at -->" + args[2] + "<--");
}
} else {
sender.sendMessage(pl.err + "Insufficient arguments");
doHelp(sender);
}
}
pl.saveFileConfigurationToFile(hubFile, hubYaml, sender);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import me.shakeforprotein.treeboteleport.TreeboTeleport;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;

public class ConfigureWarps {
public class ConfigureWarps implements CommandExecutor {

private TreeboTeleport pl;

Expand Down Expand Up @@ -96,4 +98,61 @@ private void doHelp(CommandSender s) {
s.sendMessage(pl.badge + "Correct usage is as follows");
s.sendMessage("/configurewarps set <icon | title> <warp id> <new value>");
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
File warpsFile = new File(pl.getDataFolder(), "warps.yml");
YamlConfiguration warpsYaml = YamlConfiguration.loadConfiguration(warpsFile);
boolean found = false;


if (args.length < 4) {
sender.sendMessage(pl.err + "Insufficient Arguments");
doHelp(sender);
} else if (args[0].equalsIgnoreCase("set")) {
for (String item : warpsYaml.getConfigurationSection("warps").getKeys(false)) {
if (args[2].equalsIgnoreCase(item)) {
found = true;
if (args[1].equalsIgnoreCase("icon")) {
if (Material.getMaterial(args[3].toUpperCase()) != null) {
warpsYaml.set("warps." + item + ".icon", args[3].toUpperCase());
try {
warpsYaml.save(warpsFile);
sender.sendMessage("Warps file saved");
} catch (IOException ex) {
pl.roots.errorLogger.logError(pl, ex);
sender.sendMessage(pl.err + "Failed to save warps file");
}
} else {
sender.sendMessage(pl.err + "Unknown Item: '" + args[3].toUpperCase() + "'");
}

} else if (args[1].equalsIgnoreCase("title")) {
StringBuilder fullText = new StringBuilder();
int i;
for (i = 3; i < args.length; i++) {
fullText.append(args[i] + " ");
}
warpsYaml.set("warps." + item + ".title", fullText.toString().trim());
try {
warpsYaml.save(warpsFile);
sender.sendMessage("Warps file saved");
} catch (IOException ex) {
pl.roots.errorLogger.logError(pl, ex);
sender.sendMessage(pl.err + "Failed to save warps file");
}
} else {
sender.sendMessage(pl.err + "Unknown setting '" + args[1] + "'");
}
}
}
if (!found) {
sender.sendMessage(pl.err + "Could not find warp with that id");
}
} else {
sender.sendMessage(pl.err + "Incorrect usage");
doHelp(sender);
}
return true;
}
}
Loading

0 comments on commit 6041b3a

Please sign in to comment.