Only players can use these commands

This commit is contained in:
Cola
2021-09-01 01:01:01 +01:00
parent d5de9fc7c1
commit 106c696258
4 changed files with 16 additions and 28 deletions

View File

@@ -15,7 +15,6 @@ import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -24,8 +23,7 @@ public class CheatOutput extends BaseCommand {
@CommandAlias("fmco")
@CommandPermission("fm.op")
@Description("Gives you the output of the selected recipe in the factory you are looking at")
public void execute(CommandSender sender) {
Player player = (Player) sender;
public void execute(Player sender) {
Set<Material> transparent = null;
List<Block> view = ((Player) sender).getLineOfSight(transparent, 10);
FactoryModManager manager = FactoryMod.getInstance().getManager();
@@ -33,21 +31,21 @@ public class CheatOutput extends BaseCommand {
if (exis != null && exis instanceof FurnCraftChestFactory) {
FurnCraftChestFactory fcc = (FurnCraftChestFactory) exis;
if (fcc.getCurrentRecipe() == null) {
player.sendMessage(ChatColor.RED + "This factory has no recipe selected");
sender.sendMessage(ChatColor.RED + "This factory has no recipe selected");
return;
}
IRecipe rec = fcc.getCurrentRecipe();
if (!(rec instanceof ProductionRecipe)) {
player.sendMessage(ChatColor.RED + "The selected recipe is not a production recipe");
sender.sendMessage(ChatColor.RED + "The selected recipe is not a production recipe");
return;
}
ProductionRecipe prod = (ProductionRecipe) rec;
for (ItemStack is : prod.getOutput().getItemStackRepresentation()) {
player.getInventory().addItem(is);
sender.getInventory().addItem(is);
}
player.sendMessage(ChatColor.GREEN + "Gave you all items for recipe " + ChatColor.GREEN + prod.getName());
sender.sendMessage(ChatColor.GREEN + "Gave you all items for recipe " + ChatColor.GREEN + prod.getName());
} else {
player.sendMessage(ChatColor.RED + "You are not looking at a valid factory");
sender.sendMessage(ChatColor.RED + "You are not looking at a valid factory");
}
}
}

View File

@@ -24,7 +24,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Furnace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Create extends BaseCommand {
@@ -34,7 +33,7 @@ public class Create extends BaseCommand {
@Syntax("<factory>")
@Description("Creates a factory at the blocks you are looking at")
@CommandCompletion("@FM_Factories")
public void execute(CommandSender sender, String factoryName) {
public void execute(Player sender, String factoryName) {
FactoryModManager manager = FactoryMod.getInstance().getManager();
IFactoryEgg egg = manager.getEgg(factoryName);
if (egg == null) {
@@ -42,7 +41,7 @@ public class Create extends BaseCommand {
return;
}
Set<Material> transparent = null;
List<Block> view = ((Player) sender).getLineOfSight(transparent, 10);
List<Block> view = sender.getLineOfSight(transparent, 10);
Factory exis = manager.getFactoryAt(view.get(view.size() - 1));
if (exis != null) {
manager.removeFactory(exis);

View File

@@ -11,7 +11,6 @@ import com.github.igotyou.FactoryMod.eggs.FurnCraftChestEgg;
import com.github.igotyou.FactoryMod.eggs.IFactoryEgg;
import com.github.igotyou.FactoryMod.utility.FactoryModGUI;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class FactoryMenu extends BaseCommand {
@@ -20,18 +19,17 @@ public class FactoryMenu extends BaseCommand {
@Syntax("[factory]")
@Description("Opens a GUI allowing you to browse through all factories")
@CommandCompletion("@FM_Factories")
public void execute(CommandSender sender, @Optional String factoryName) {
Player p = (Player) sender;
public void execute(Player sender, @Optional String factoryName) {
if (factoryName == null) {
FactoryModGUI gui = new FactoryModGUI((Player) sender);
FactoryModGUI gui = new FactoryModGUI(sender);
gui.showFactoryOverview(true);
} else {
IFactoryEgg egg = FactoryMod.getInstance().getManager().getEgg(factoryName);
if (egg == null) {
p.sendMessage(ChatColor.RED + "The factory " + factoryName + " does not exist");
sender.sendMessage(ChatColor.RED + "The factory " + factoryName + " does not exist");
return;
}
FactoryModGUI gui = new FactoryModGUI((Player) sender);
FactoryModGUI gui = new FactoryModGUI(sender);
gui.showForFactory((FurnCraftChestEgg) egg);
}
}

View File

@@ -13,7 +13,6 @@ import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RunAmountSetterCommand extends BaseCommand {
@@ -22,28 +21,22 @@ public class RunAmountSetterCommand extends BaseCommand {
@Syntax("<amount>")
@Description("Sets the amount of runs for the currently selected recipe in the factory you are looking at")
@CommandPermission("fm.op")
public void execute(CommandSender sender, String runCount) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.MAGIC
+ "How the hell is this supposed to work");
return;
}
Player p = (Player) sender;
public void execute(Player sender, String runCount) {
int newAmount;
try {
newAmount = Integer.parseInt(runCount);
}
catch(NumberFormatException e) {
p.sendMessage(ChatColor.RED + runCount + " is not a number");
sender.sendMessage(ChatColor.RED + runCount + " is not a number");
return;
}
FactoryModManager manager = FactoryMod.getInstance().getManager();
for(Block b : p.getLineOfSight((Set <Material>)null, 15)) {
for(Block b : sender.getLineOfSight((Set <Material>)null, 15)) {
Factory f = manager.getFactoryAt(b);
if (f instanceof FurnCraftChestFactory) {
FurnCraftChestFactory fccf = (FurnCraftChestFactory) f;
fccf.setRunCount(fccf.getCurrentRecipe(), newAmount);
p.sendMessage(ChatColor.GREEN + "Set runcount for recipe " + fccf.getCurrentRecipe().getName() + " in " + fccf.getName() + " to "+ newAmount);
sender.sendMessage(ChatColor.GREEN + "Set runcount for recipe " + fccf.getCurrentRecipe().getName() + " in " + fccf.getName() + " to "+ newAmount);
}
}
}