use of org.bukkit.command.BlockCommandSender in project MyMaid2 by jaoafa.
the class Event_Antijaoium method ByCommandBlock.
@EventHandler(priority = EventPriority.MONITOR)
public void ByCommandBlock(ServerCommandEvent event) {
if (!(event.getSender() instanceof BlockCommandSender))
return;
BlockCommandSender sender = (BlockCommandSender) event.getSender();
if (sender.getBlock() == null || !(sender.getBlock().getState() instanceof CommandBlock))
return;
CommandBlock cmdb = (CommandBlock) sender.getBlock().getState();
String command = cmdb.getCommand();
if (!command.startsWith("/give") && !command.startsWith("give")) {
return;
}
if (command.equalsIgnoreCase("/give") || command.equalsIgnoreCase("give")) {
return;
}
String[] commands = command.split(" ", 0);
if (commands.length < 3) {
return;
}
String item = commands[2];
if (!item.equalsIgnoreCase("splash_potion") && !item.equalsIgnoreCase("minecraft:splash_potion")) {
return;
}
String selector = commands[1];
boolean ALLPlayer = false;
String ToPlayer = null;
if (selector.equalsIgnoreCase("@p")) {
// 一番近い
Player p = getNearestPlayer(cmdb.getLocation());
if (p == null) {
return;
}
ToPlayer = p.getName();
} else if (selector.equalsIgnoreCase("@a")) {
// プレイヤーすべて
ALLPlayer = true;
} else if (selector.equalsIgnoreCase("@e")) {
// エンティティすべて
ALLPlayer = true;
} else {
Player p = Bukkit.getPlayer(selector);
if (p != null) {
ToPlayer = selector;
}
}
for (Player p : Bukkit.getOnlinePlayers()) {
if (ToPlayer.equalsIgnoreCase(p.getName())) {
Reason.put(p.getName(), "コマンドブロック(" + cmdb.getLocation().getWorld().getName() + " " + cmdb.getLocation().getBlockX() + " " + cmdb.getLocation().getBlockY() + " " + cmdb.getLocation().getBlockZ() + ")の実行したコマンド : " + command);
continue;
}
if (ALLPlayer) {
Reason.put(p.getName(), "コマンドブロック(" + cmdb.getLocation().getWorld().getName() + " " + cmdb.getLocation().getBlockX() + " " + cmdb.getLocation().getBlockY() + " " + cmdb.getLocation().getBlockZ() + ")の実行したコマンド : " + command);
continue;
}
}
}
use of org.bukkit.command.BlockCommandSender in project EliteMobs by MagmaGuy.
the class SpawnMobCommandHandler method spawnMob.
public void spawnMob(CommandSender commandSender, String[] args) {
World world = null;
Location location = null;
String entityInput = null;
int mobLevel = 0;
List<String> mobPower = new ArrayList<>();
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
if (args.length == 1) {
player.sendMessage("Valid command syntax:");
player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
}
world = player.getWorld();
location = player.getTargetBlock((HashSet<Byte>) null, 30).getLocation().add(0, 1, 0);
entityInput = args[1].toLowerCase();
if (args.length > 2) {
try {
mobLevel = Integer.valueOf(args[2]);
} catch (NumberFormatException ex) {
player.sendMessage("Not a valid level.");
player.sendMessage("Valid command syntax:");
player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
}
}
if (args.length > 3) {
int index = 0;
for (String arg : args) {
//mob powers start after arg 2
if (index > 2) {
mobPower.add(arg);
}
index++;
}
}
} else if (commandSender instanceof ConsoleCommandSender || commandSender instanceof BlockCommandSender) {
for (World worldIterator : worldList) {
//find world
if (worldIterator.getName().equals(args[1])) {
world = worldIterator;
//find x coord
try {
double xCoord = Double.parseDouble(args[2]);
double yCoord = Double.parseDouble(args[3]);
double zCoord = Double.parseDouble(args[4]);
location = new Location(worldIterator, xCoord, yCoord, zCoord);
entityInput = args[5].toLowerCase();
break;
} catch (NumberFormatException ex) {
getConsoleSender().sendMessage("At least one of the coordinates (x:" + args[2] + ", y:" + args[3] + ", z:" + args[4] + ") is not valid");
getConsoleSender().sendMessage("Valid command syntax: /elitemobs SpawnMob worldName xCoord yCoord " + "zCoord mobType mobLevel mobPower mobPower(you can keep adding these mobPowers as many as you'd like)");
}
if (args.length > 6) {
int index = 0;
for (String arg : args) {
//mob powers start after arg 2
if (index > 2) {
mobPower.add(arg);
}
index++;
}
}
}
}
if (world == null) {
getConsoleSender().sendMessage("World " + args[1] + "not found. Valid command syntax: /elitemobs SpawnMob" + " [worldName] [xCoord] [yCoord] [zCoord] [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these " + "mobPowers as many as you'd like)]");
}
}
EntityType entityType = null;
switch(entityInput) {
case "blaze":
entityType = EntityType.BLAZE;
break;
case "cavespider":
entityType = EntityType.CAVE_SPIDER;
break;
case "creeper":
entityType = EntityType.CREEPER;
break;
case "enderman":
entityType = EntityType.ENDERMAN;
break;
case "endermite":
entityType = EntityType.ENDERMITE;
break;
case "husk":
entityType = EntityType.HUSK;
break;
case "irongolem":
entityType = EntityType.IRON_GOLEM;
break;
case "pigzombie":
entityType = EntityType.PIG_ZOMBIE;
break;
case "polarbear":
entityType = EntityType.POLAR_BEAR;
break;
case "silverfish":
entityType = EntityType.SILVERFISH;
break;
case "skeleton":
entityType = EntityType.SKELETON;
break;
case "spider":
entityType = EntityType.SPIDER;
break;
case "stray":
entityType = EntityType.STRAY;
break;
case "witch":
entityType = EntityType.WITCH;
break;
case "witherskeleton":
entityType = EntityType.WITHER_SKELETON;
break;
case "zombie":
entityType = EntityType.ZOMBIE;
break;
case "chicken":
entityType = EntityType.CHICKEN;
break;
case "cow":
entityType = EntityType.COW;
break;
case "mushroomcow":
entityType = EntityType.MUSHROOM_COW;
break;
case "pig":
entityType = EntityType.PIG;
break;
case "sheep":
entityType = EntityType.SHEEP;
break;
default:
if (commandSender instanceof Player) {
((Player) commandSender).getPlayer().sendTitle("Could not spawn mob type " + entityInput, "If this is incorrect, please contact the dev.");
} else if (commandSender instanceof ConsoleCommandSender) {
getConsoleSender().sendMessage("Could not spawn mob type " + entityInput + ". If this is incorrect, " + "please contact the dev.");
}
break;
}
Entity entity = null;
if (entityType != null) {
entity = world.spawnEntity(location, entityType);
}
if (entityType == EntityType.CHICKEN || entityType == EntityType.COW || entityType == EntityType.MUSHROOM_COW || entityType == EntityType.PIG || entityType == EntityType.SHEEP) {
HealthHandler.passiveHealthHandler(entity, ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount"));
NameHandler.customPassiveName(entity, plugin);
return;
}
if (mobLevel > 0) {
entity.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, mobLevel));
}
if (mobPower.size() > 0) {
boolean inputError = false;
int powerCount = 0;
MetadataHandler metadataHandler = new MetadataHandler();
for (String string : mobPower) {
switch(string) {
//major powers
case MetadataHandler.ZOMBIE_FRIENDS_H:
if (entity instanceof Zombie) {
entity.setMetadata(MetadataHandler.ZOMBIE_FRIENDS_MD, new FixedMetadataValue(plugin, true));
powerCount++;
}
break;
case MetadataHandler.ZOMBIE_NECRONOMICON_H:
if (entity instanceof Zombie) {
entity.setMetadata(MetadataHandler.ZOMBIE_NECRONOMICON_MD, new FixedMetadataValue(plugin, true));
powerCount++;
}
break;
case MetadataHandler.ZOMBIE_TEAM_ROCKET_H:
if (entity instanceof Zombie) {
entity.setMetadata(MetadataHandler.ZOMBIE_TEAM_ROCKET_MD, new FixedMetadataValue(plugin, true));
powerCount++;
}
break;
case MetadataHandler.ZOMBIE_PARENTS_H:
if (entity instanceof Zombie) {
entity.setMetadata(MetadataHandler.ZOMBIE_PARENTS_MD, new FixedMetadataValue(plugin, true));
powerCount++;
}
break;
//minor powers
case MetadataHandler.ATTACK_ARROW_H:
entity.setMetadata(MetadataHandler.ATTACK_ARROW_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_BLINDING_H:
entity.setMetadata(MetadataHandler.ATTACK_BLINDING_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_CONFUSING_H:
entity.setMetadata(MetadataHandler.ATTACK_CONFUSING_MD, new FixedMetadataValue(plugin, true));
// minorPowerPowerStance.attackConfusing(entity);
powerCount++;
break;
case MetadataHandler.ATTACK_FIRE_H:
entity.setMetadata(MetadataHandler.ATTACK_FIRE_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_FIREBALL_H:
entity.setMetadata(MetadataHandler.ATTACK_FIREBALL_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_FREEZE_H:
entity.setMetadata(MetadataHandler.ATTACK_FREEZE_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_GRAVITY_H:
entity.setMetadata(MetadataHandler.ATTACK_GRAVITY_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_POISON_H:
entity.setMetadata(MetadataHandler.ATTACK_POISON_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_PUSH_H:
entity.setMetadata(MetadataHandler.ATTACK_PUSH_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_WEAKNESS_H:
entity.setMetadata(MetadataHandler.ATTACK_WEAKNESS_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_WEB_H:
entity.setMetadata(MetadataHandler.ATTACK_WEB_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.ATTACK_WITHER_H:
entity.setMetadata(MetadataHandler.ATTACK_WITHER_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.BONUS_LOOT_H:
entity.setMetadata(MetadataHandler.BONUS_LOOT_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.DOUBLE_DAMAGE_H:
if (!(entity instanceof IronGolem)) {
entity.setMetadata(MetadataHandler.DOUBLE_DAMAGE_MD, new FixedMetadataValue(plugin, true));
}
powerCount++;
break;
case MetadataHandler.DOUBLE_HEALTH_H:
if (!(entity instanceof IronGolem)) {
entity.setMetadata(MetadataHandler.DOUBLE_HEALTH_MD, new FixedMetadataValue(plugin, true));
}
powerCount++;
break;
case MetadataHandler.INVISIBILITY_H:
entity.setMetadata(MetadataHandler.INVISIBILITY_MD, new FixedMetadataValue(plugin, true));
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
powerCount++;
break;
case MetadataHandler.INVULNERABILITY_ARROW_H:
entity.setMetadata(MetadataHandler.INVULNERABILITY_ARROW_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.INVULNERABILITY_FALL_DAMAGE_H:
entity.setMetadata(MetadataHandler.INVULNERABILITY_FALL_DAMAGE_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.INVULNERABILITY_FIRE_H:
entity.setMetadata(MetadataHandler.INVULNERABILITY_FIRE_MD, new FixedMetadataValue(plugin, true));
// minorPowerPowerStance.invulnerabilityFireEffect(entity);
powerCount++;
break;
case MetadataHandler.INVULNERABILITY_KNOCKBACK_H:
entity.setMetadata(MetadataHandler.INVULNERABILITY_KNOCKBACK_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case MetadataHandler.MOVEMENT_SPEED_H:
entity.setMetadata(MetadataHandler.MOVEMENT_SPEED_MD, new FixedMetadataValue(plugin, true));
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
powerCount++;
break;
case MetadataHandler.TAUNT_H:
entity.setMetadata(MetadataHandler.TAUNT_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
case "custom":
entity.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
powerCount++;
break;
default:
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
player.sendMessage(string + " is not a valid power.");
} else if (commandSender instanceof ConsoleCommandSender) {
getConsoleSender().sendMessage(string + " is not a valid power.");
}
inputError = true;
}
}
entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, powerCount));
minorPowerPowerStance.itemEffect(entity);
majorPowerPowerStance.itemEffect(entity);
if (inputError) {
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
player.sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + " custom");
} else if (commandSender instanceof ConsoleCommandSender) {
getConsoleSender().sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + MetadataHandler.majorPowerList() + " custom");
}
}
}
}
use of org.bukkit.command.BlockCommandSender in project Glowstone by GlowstoneMC.
the class SummonCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender))
return true;
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("This command can only be executed by a player or via command blocks.");
return true;
}
Location location = null;
if (sender instanceof Player) {
location = ((Player) sender).getLocation().clone();
} else if (sender instanceof BlockCommandSender) {
location = ((BlockCommandSender) sender).getBlock().getLocation().clone();
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (args.length >= 4) {
location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
}
if (location == null) {
return false;
}
location.setYaw(0.0f);
location.setPitch(0.0f);
CompoundTag tag = null;
if (args.length >= 5) {
String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage());
}
}
String entityName = args[0];
if (!checkSummon(sender, entityName)) {
return true;
}
GlowEntity entity;
if (EntityType.fromName(entityName) != null) {
entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
} else {
Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
if (tag != null) {
EntityStorage.load(entity, tag);
}
sender.sendMessage("Object successfully summoned.");
return true;
}
use of org.bukkit.command.BlockCommandSender in project CommandHelper by EngineHub.
the class CommandHelperPlugin method onCommand.
/**
* Called when a command registered by this plugin is received.
*
* @param sender
* @param cmd
* @param commandLabel
* @param args
* @return
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
String cmdName = cmd.getName().toLowerCase();
if ((sender.isOp() || (sender instanceof Player && (sender.hasPermission("commandhelper.reloadaliases") || sender.hasPermission("ch.reloadaliases")))) && (cmdName.equals("reloadaliases") || cmdName.equals("reloadalias") || cmdName.equals("recompile"))) {
MCPlayer player = null;
if (sender instanceof Player) {
player = new BukkitMCPlayer((Player) sender);
}
ac.reload(player, args, false);
return true;
} else if (cmdName.equalsIgnoreCase("commandhelper")) {
return args.length >= 1 && args[0].equalsIgnoreCase("null");
} else if (cmdName.equals("runalias")) {
// Hardcoded alias rebroadcast
if (args.length == 0) {
return false;
}
String command = StringUtils.Join(args, " ");
if (sender instanceof Player) {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent((Player) sender, command);
playerListener.onPlayerCommandPreprocess(pcpe);
} else if (sender instanceof ConsoleCommandSender || sender instanceof BlockCommandSender || sender instanceof CommandMinecart) {
// event handler that would get them if they would not have started with "/runalias".
if (command.startsWith("/")) {
command = command.substring(1);
}
ServerCommandEvent sce = new ServerCommandEvent(sender, command);
serverListener.onServerCommand(sce);
}
return true;
} else if (cmdName.equalsIgnoreCase("interpreter-on")) {
if (sender instanceof ConsoleCommandSender) {
int interpreterTimeout = Prefs.InterpreterTimeout();
if (interpreterTimeout != 0) {
interpreterUnlockedUntil = (interpreterTimeout * 60 * 1000) + System.currentTimeMillis();
sender.sendMessage("Interpreter mode unlocked for " + interpreterTimeout + " minute" + (interpreterTimeout == 1 ? "" : "s"));
}
} else {
sender.sendMessage("This command can only be run from console.");
}
return true;
} else if (sender instanceof Player && cmdName.equalsIgnoreCase("interpreter")) {
if (!sender.hasPermission("commandhelper.interpreter")) {
sender.sendMessage(MCChatColor.RED + "You do not have permission to run that command");
} else if (!Prefs.EnableInterpreter()) {
sender.sendMessage(MCChatColor.RED + "The interpreter is currently disabled." + " Check your preferences file.");
} else if (Prefs.InterpreterTimeout() != 0 && interpreterUnlockedUntil < System.currentTimeMillis()) {
sender.sendMessage(MCChatColor.RED + "Interpreter mode is currently locked. Run \"interpreter-on\"" + " console to unlock it. If you want to turn this off entirely, set the interpreter-timeout" + " option to 0 in " + CommandHelperFileLocations.getDefault().getPreferencesFile().getName());
} else {
interpreterListener.startInterpret(sender.getName());
sender.sendMessage(MCChatColor.YELLOW + "You are now in interpreter mode. Type a dash (-) on a" + " line by itself to exit, and >>> to enter multiline mode.");
}
return true;
} else {
MCCommandSender mcsender = BukkitConvertor.BukkitGetCorrectSender(sender);
MCCommand mccmd = new BukkitMCCommand(cmd);
return mccmd.handleCustomCommand(mcsender, commandLabel, args);
}
}
use of org.bukkit.command.BlockCommandSender in project CommandHelper by EngineHub.
the class CommandHelperServerListener method onServerCommand.
@EventHandler(priority = EventPriority.LOWEST)
public void onServerCommand(ServerCommandEvent event) {
// Select the proper CommandSender wrapper.
MCCommandSender sender;
if (event.getSender() instanceof ConsoleCommandSender) {
// Console.
sender = new BukkitMCConsoleCommandSender((ConsoleCommandSender) event.getSender());
} else if (event.getSender() instanceof BlockCommandSender) {
// Commandblock blocks.
sender = new BukkitMCBlockCommandSender((BlockCommandSender) event.getSender());
} else if (event.getSender() instanceof CommandMinecart) {
// Commandblock minecarts.
sender = new BukkitMCCommandMinecart((CommandMinecart) event.getSender());
} else {
// other CommandSenders.
sender = new BukkitMCCommandSender(event.getSender());
}
BukkitMiscEvents.BukkitMCServerCommandEvent cce = new BukkitMiscEvents.BukkitMCServerCommandEvent(event, sender);
EventUtils.TriggerListener(Driver.SERVER_COMMAND, "server_command", cce);
try {
if (event.isCancelled()) {
return;
}
} catch (NoSuchMethodError ex) {
// not cancellable before 1.8.8
}
boolean match = false;
try {
match = Static.getAliasCore().alias("/" + event.getCommand(), sender);
} catch (InternalException e) {
Static.getLogger().log(Level.SEVERE, e.getMessage());
} catch (ConfigRuntimeException e) {
Static.getLogger().log(Level.WARNING, e.getMessage());
} catch (Throwable e) {
sender.sendMessage(MCChatColor.RED + "Command failed with following reason: " + e.getMessage());
// Obviously the command is registered, but it somehow failed. Cancel the event.
e.printStackTrace();
return;
}
// commandhelper null, which just returns true.
if (match) {
event.setCommand("commandhelper null");
}
}
Aggregations