1
Plugin help!
I'm trying to make a plugin where you can punish the person who just killed you. But when I added the code, my plugin didn't work anymore. It compiled fine, without errors, but when I loaded up my server, the plugin didn't show up. Please help!
package me.Pixelizedgaming;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class ParkourPlugin extends JavaPlugin{
public Permission playerPermission = new Permission("RedFactionsPvpHelper.revenge");
@Override
public void onEnable(){
new PlayerListener(this);
PluginManager pm = getServer().getPluginManager();
pm.addPermission(playerPermission);
}
@Override
public void onDisable(){
}
public boolean onCommand(CommandSender sender,Command cmd,String label, String[] args){
if (cmd.getName().equalsIgnoreCase("revenge")&& sender instanceof Player){
Player player = (Player) sender;
if (!player.hasPermission("RedFactionsPvpHelper.revenge")){
player.sendMessage(ChatColor.DARK_RED/* ChatColor.BOLD*/ + "Sorry, You don't have permissions to do this command. ");
}
else{
Player p = player.getKiller();
player.sendMessage(ChatColor.GOLD +"Successfully punished" + ChatColor.GRAY + p.getDisplayName());
p.setMaxHealth(10);
p.setPlayerListName(ChatColor.DARK_RED +"DUMBASS");
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 20, 1));
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20, 1));
p.sendMessage(ChatColor.DARK_PURPLE+ "Thou have been punished!");
}
return true;
}
return false;
}
}
3
There's a few things wrong with the code provided - nothing to panic about though, I have made similar mistakes beforehand:
1. Your plugin.yml isn't formatted properly. It should look like this:
2. You may want to include a != null check for player.getKiller() in case it returns null, so just add this snippet of code and your plugin should have fewer exceptions thrown:
1. Your plugin.yml isn't formatted properly. It should look like this:
name: RFPvpHelper
main: me.Pixelizedgaming.ParkourPlugin
version: 1.0.5
commands:
revenge:
description: Let your killer feel your wrath!
permission: RedFactionsPvpHelper.revenge
usage: /<command>2. You may want to include a != null check for player.getKiller() in case it returns null, so just add this snippet of code and your plugin should have fewer exceptions thrown:
if (player.getKiller() != null) {
Player p = player.getKiller();
player.sendMessage(ChatColor.GOLD +"Successfully punished" + ChatColor.GRAY + p.getDisplayName());
// All of your other code here
p.sendMessage(ChatColor.DARK_PURPLE+ "Thou have been punished!");
} else {
player.sendMessage(ChatColor.DARK_RED + "You don't have anyone to punish!");
}I mean that when i look in the server plugin list, the plugin isn't there. I have a plugin.yml,
here.
and here is the PlayerListener class mentioned in the code above.
package me.Pixelizedgaming;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class PlayerListener implements Listener{
public PlayerListener(ParkourPlugin plugin){
plugin.getServer().getPluginManager().registerEvents(this,plugin);
}
@EventHandler
public void Teleport(PlayerRespawnEvent event){
Player player = event.getPlayer();
player.chat("I died! Yay!");
player.performCommand("spawn");
Player h = player.getKiller();
h.getInventory().addItem(new ItemStack(Material.SPONGE, 1));
h.sendMessage(ChatColor.DARK_AQUA + "Congrats on that Kill! Here's a piece of Sponge! Exchange it for blaze rods in " + ChatColor.RED +"/warp shop.");
}
@EventHandler
public void Teleport1(PlayerItemConsumeEvent event){
Player player = event.getPlayer();
Random random = new Random();
double e = random.nextInt(11);
double g = player.getHealth();
player.setHealth(g + e);
player.sendMessage(ChatColor.GRAY + "Yum! You Gained " + ChatColor.AQUA + e + ChatColor.GRAY+ " Health!");
}
@EventHandler
public void GG(PlayerJoinEvent event){
Player player = event.getPlayer();
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20, 3));
}
}
here.
Click to reveal
name: RFPvpHelper
main: me.Pixelizedgaming.ParkourPlugin
version: 1.0.5
commands:
-revenge
description: Let your killer feel your wrath!
usage = /<command>
main: me.Pixelizedgaming.ParkourPlugin
version: 1.0.5
commands:
-revenge
description: Let your killer feel your wrath!
usage = /<command>
and here is the PlayerListener class mentioned in the code above.
package me.Pixelizedgaming;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class PlayerListener implements Listener{
public PlayerListener(ParkourPlugin plugin){
plugin.getServer().getPluginManager().registerEvents(this,plugin);
}
@EventHandler
public void Teleport(PlayerRespawnEvent event){
Player player = event.getPlayer();
player.chat("I died! Yay!");
player.performCommand("spawn");
Player h = player.getKiller();
h.getInventory().addItem(new ItemStack(Material.SPONGE, 1));
h.sendMessage(ChatColor.DARK_AQUA + "Congrats on that Kill! Here's a piece of Sponge! Exchange it for blaze rods in " + ChatColor.RED +"/warp shop.");
}
@EventHandler
public void Teleport1(PlayerItemConsumeEvent event){
Player player = event.getPlayer();
Random random = new Random();
double e = random.nextInt(11);
double g = player.getHealth();
player.setHealth(g + e);
player.sendMessage(ChatColor.GRAY + "Yum! You Gained " + ChatColor.AQUA + e + ChatColor.GRAY+ " Health!");
}
@EventHandler
public void GG(PlayerJoinEvent event){
Player player = event.getPlayer();
player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20, 3));
}
}
There could be a bunch of issues.
- Did you include a plugin.yml?
- Is the main variable set in the plugin.yml?
- Are you checking for runtime errors from stdout/console?
Describe what you mean by "didn't show up".
- Did you include a plugin.yml?
- Is the main variable set in the plugin.yml?
- Are you checking for runtime errors from stdout/console?
Describe what you mean by "didn't show up".
