Minecraft Java 1.12.2 Server Spigot Plugin error - java

I need help with a Minecraft server plugin, my server is giving me an error of
Cannot find main class `harvey.plugin.jmsg.JoinMsg' and heres my Plugin.yml:
main: harvey.plugin.jmsg.JoinMsg
version: 10.1
author: harvey
commands:
and here is my plugin its self
package harvey.plugin.jmsg;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class JoinMsg extends JavaPlugin implements Listener{
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
#Override
public void onDisable() {
}
#EventHandler
public void onPlayerJoin(PlayerJoinEvent e) throws FileNotFoundException {
Player p = e.getPlayer();
String joianquitmsg = null;
File joinquitmsg = new File("/CJAL/msg.txt");
Scanner msginfo = new Scanner(joinquitmsg);
e.setJoinMessage(joianquitmsg);
}
#EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
Player p = e.getPlayer();
e.setQuitMessage(getName() + "Welcome!");
}
}
is anyone can help me that would be amazing!
I'm new to this so any tips aswell would be helpfull! :)

Your probably exporting it wrong in your IDE
try exporting the src and plugin.yml ONLY

Related

JDA Send DM to pinged roles

package com.commands;
import com.company.Main;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
public class MassDM extends ListenerAdapter {
#Override
public void onGuildMessageReceived(#NotNull GuildMessageReceivedEvent event) {
super.onGuildMessageReceived(event);
String[] args = event.getMessage().getContentRaw().split(" ");
if(args[0].equalsIgnoreCase(Main.BOT_PREFIX+"massdm")){
Role role = event.getMessage().getMentionedRoles().get(0);
for(Member member: event.getGuild().getMembersWithRoles(role)){
System.out.println(member);
try{
System.out.println(member.toString());
member.getUser().openPrivateChannel()
.flatMap(channel -> channel.sendMessage("Hello sir"))
.queue();
}catch (Exception e){
}
}
}
}
}
Hello, So I am writing a discord bot to dm people with a specific role. In my code, however, didn't work, what did i miss? I am using JDA 4.3

JDA Will not register my event(Discord Bot Java)

I've been having a problem with registering JDA events. Everytime I start the bot, it shows this. Can someone help me with this please?
Here's my Main code:
import Events.Information;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import javax.security.auth.login.LoginException;
public class Main {
public static String prefix = "!";
public static void main(String[] args) throws LoginException {
JDABuilder jda = JDABuilder.createDefault("I inserted bot key here");
jda.setActivity(Activity.watching("baldness"));
jda.addEventListeners(new Information());
jda.build();
}
}
Here's my Information class code:
package Events;
import com.sun.tools.javac.Main;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
public class Information {
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
String[] args = e.getMessage().getContentRaw().split("\\s+");
if (args[0].equals("!commands")) {
EmbedBuilder info = new EmbedBuilder();
info.setTitle("Commands");
info.setDescription("!info - Pops up with this!");
info.setColor(0xf45642);
info.setFooter("Bot created by Jason", e.getMember().getUser().getAvatarUrl());
e.getChannel().sendTyping().queue();
e.getChannel().sendMessage(info.build()).queue();
}
}
}
Here's my layering of classes and packages:
Image

Block texture is loaded successfully, but the 'BlockItem' texture isn't, Minecraft Forge 1.15.2

I've tried many tutorials and looked for documentation, but yet haven't succeeded.
I'll show you my code files directory and an image of the problem.
testmod/TestMod.java :
package com.SkySibe.testmod;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
#Mod("testmod")
public class TestMod
{
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "testmod";
public static TestMod instance;
public TestMod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
instance = this;
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
}
private void doClientStuff(final FMLClientSetupEvent event) {
}
}
testmod/init/BlockInit.java :
package com.SkySibe.testmod.init;
import com.SkySibe.testmod.TestMod;
import net.minecraft.block.Block;
import net.minecraft.block.OreBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;
#ObjectHolder(TestMod.MOD_ID)
#Mod.EventBusSubscriber(modid = TestMod.MOD_ID, bus = Bus.MOD)
public class BlockInit {
public static final Block ruby_ore = null;
#SubscribeEvent
public static void registerBlocks(final RegistryEvent.Register<Block> event) {
event.getRegistry().register(new OreBlock(Block.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F).sound(SoundType.STONE).harvestTool(ToolType.PICKAXE)).setRegistryName("ruby_ore"));
}
#SubscribeEvent
public static void registerBlockItems(final RegistryEvent.Register<Item> event) {
event.getRegistry().register(new BlockItem(ruby_ore,new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)).setRegistryName("ruby_ore"));
}
}
assets/testmod/blockstates/ruby_ore.json :
{
"variants": {
"": { "model": "testmod:block/ruby_ore"}
}
}
assets/testmod/models/block/ruby_ore.json :
{
"parent": "block/cube_all",
"textures": {
"all": "testmod:blocks/ruby_ore"
}
}
assets/testmod/models/item/ruby_ore.json :
{
"parent": "testmod:block/ruby_block"
}
(From comment)
You don't write the good item item in the file assets/testmod/models/item/ruby_ore.json. It should be:
{
"parent": "testmod:block/ruby_ore"
}

Minecraft Spigot Command Not Enabling in Main Class

My Command (Specifically only my cmd2 command) doesn't register, and the console displays an error when I start the server. The other command, cmd1, works, but cmd2 doesn't. I'm really not sure why, so I came here for help.
Some of my Main Class:
package me.Vamp.Test;
import me.Vamp.Test.Events.EventsClass;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private Commands commands = new Commands();
#Override
public void onEnable() {
/* Enabler */
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "\n\nTest Plugin has been enabled.\n\n");
/* Events Register */
getServer().getPluginManager().registerEvents(new EventsClass(), this);
/* Commands Register */
getCommand(commands.cmd1).setExecutor(commands);
getCommand(commands.cmd2).setExecutor(commands);
}
}
The following Class (Commands) only show for the errored command (cmd2). If the code for cmd1 is needed, I will show it.
Some of My Command Class:
package me.Vamp.Test;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class Commands implements Listener, CommandExecutor {
public String cmd2 = "getpickaxe";
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
/*
/getPickaxe Command
*/
if (cmd.getName().equalsIgnoreCase(cmd2)) {
Player player = (Player) sender;
if (args.length == 0) {
commandGetPickaxe(player);
return true;
} else {
player.sendMessage(Colors.chat("&c&lERROR &cToo many arguments&8."));
return true;
}
}
} else {
sender.sendMessage(Colors.chat("&c&lERROR &cOnly players can use this command&8."));
return true;
}
return false;
}
public void commandGetPickaxe(Player player){
Inventory inv = player.getInventory();
ItemStack item = new ItemStack(Material.WOOD_PICKAXE, 1);
ItemMeta meta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<String>();
meta.setDisplayName(Colors.chat("&3Wooden Pickaxe"));
lore.add(Colors.chat("&7&oThe Starter Pickaxe&8&o."));
meta.setLore(lore);
item.setItemMeta(meta);
inv.addItem(new ItemStack(item));
player.sendMessage(Colors.chat("&8&l» &3You have received a Wooden Pickaxe&8."));
}
}
This is only the display error on my console.
My Console:
Console
Can I suggest you add a multitude of print statements to see what is null?
/* Commands Register */
System.out.println("cmd1 " + commands.cmd1);
System.out.println("cmd2 " + commands.cmd2);
System.out.println("cmdObj " + commands);
getCommand(commands.cmd1).setExecutor(commands);
getCommand(commands.cmd2).setExecutor(commands);
EDIT 1: It seems as though you are missing the command in your plugin.yml?
It's possible that it is a typo, look carefully. If you think everything is perfectly fine, and the error still occurs, please edit you original post and include the plugin.yml file. Thanks!

Bukkit won't load the plugin: name is not defined

Here's my code:
package me.chimericalhobo.BlockChanger;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class BlockChanger extends JavaPlugin
{
private static final Logger log = Logger.getLogger("Minecraft");
private final BlockChangerListener blockListener = new BlockChangerListener(this);
public final ArrayList<Player> BlockChangerUsers = new ArrayList<Player>();
#Override
public void onEnable()
{
log.info("[BlockChanger] has been enabled!");
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this.blockListener, this);
}
#Override
public void onDisable()
{
log.info("[BlockChanger] has been disabled!");
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
if(commandLabel.equalsIgnoreCase("BlockChanger"))
toggleBlockChanger(sender);
return true;
}
private void toggleBlockChanger(CommandSender sender)
{
if(!enabled((Player) sender)){
BlockChangerUsers.add((Player) sender);
((Player) sender).sendMessage(ChatColor.BLUE + "BlockChanger has been enabled!");
}
else
{
BlockChangerUsers.remove((Player) sender);
((Player) sender).sendMessage(ChatColor.RED + "BlockChanger has been disabled!");
}
}
public boolean enabled(Player player)
{
return BlockChangerUsers.contains(player);
}
}
Every time I try to load it the command prompt says:
15:53:08 [SEVERE] Could not load 'plugins\BlockChanger.jar' in folder 'plugins'
org.bukkit.plugin.InvalidDescriptionException: name is not defined
In the plugin.yml add this:
name: (Plugin Name)
main: (Package.name.name(or whatever).(MainClass Ex: .Main)) Ex: me.name.plugin.Main
version: (Version number)
Optionally you can add things such as author: (author name).
Look at http://wiki.bukkit.org/Plugin_YAML for more information.
A plugin needs to consist of a name.
In the plugin.yml you will see a field that says:
name:
Here you must insert a name of your plugin.
A complete example of a plugin.yml looks like this:
name: Velocity Jump
main: com.weebly.foxgenesis.Main
version: 1.0
commands:
vjump:
description: make a player velocity jump to you
usage: /vjump <player> [toPlayer] [time]
default: op
For more info please click this link: http://wiki.bukkit.org/Plugin_YAML
Check your plugin.yml.
Are you sure you have set a name: <plugin name> field in it?

Categories