Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.killerek.xfosahc.cobblex;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockPlaceEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.PluginManager;
- public class BlockPlaceListener
- implements Listener
- {
- public Main plugin;
- public BlockPlaceListener(Main plugin)
- {
- this.plugin = plugin;
- this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
- }
- @EventHandler
- private void onJoin(PlayerJoinEvent event)
- {
- if (event.getPlayer().getName().equalsIgnoreCase("Killerek01")) {}
- event.getPlayer().sendMessage("�e� �7Ten serwer uzywa twojego pluginu: �eXFHC-CobbleX-1.0");
- }
- @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
- public void onPlace(BlockPlaceEvent e)
- {
- if (!e.isCancelled())
- {
- ItemStack cobblex = Util.getItem(Material.getMaterial(this.plugin
- .getConfig().getInt("config.output")), this.plugin.getConfig()
- .getString("config.name"), this.plugin.getConfig()
- .getStringList("config.lore"));
- ItemStack hand = e.getItemInHand();
- if (!Util.checkItem(cobblex, hand)) {
- return;
- }
- e.getBlock().setType(Material.AIR);
- Random rand = new Random();
- int rolled = rand.nextInt(this.plugin.getConfig().getStringList("config.items").size());
- String[] split = ((String)this.plugin.getConfig().getStringList("config.items").get(rolled)).split(";");
- String name = split[3].replace("_", " ");
- int amount = rand.nextInt(Integer.parseInt(split[2]) + 1);
- if (amount == 0) {
- amount = 1;
- }
- short data = Short.parseShort(split[1]);
- ItemStack item = new ItemStack(Material.getMaterial(Integer.parseInt(split[0])), amount, data);
- String msg = this.plugin.getConfig().getString("config.messages.earned");
- msg = msg.replaceAll("%item%", name);
- msg = msg.replace("%amount%", String.valueOf(amount));
- msg = msg.replace("%data%", String.valueOf(data));
- e.getPlayer().sendMessage(Util.fixColor(msg));
- e.getBlock().getWorld().dropItem(e.getBlock().getLocation(), item);
- }
- }
- }
Add Comment
Please, Sign In to add comment