ExpBank

Source Code v2.0

Source Code v2.0

ExpBank.java

package me.mraljabal.expbank;

import java.util.logging.Logger;

import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class ExpBank extends JavaPlugin {
	public final Logger logger = Logger.getLogger("Minecraft");
	public static ExpBank plugin;
	public final MyPlayerListener pl = new MyPlayerListener(this);
    
	@Override
	public void onDisable() {
		PluginDescriptionFile pdffile = this.getDescription();
		this.logger.info(pdffile.getName() + pdffile.getVersion() + " Has been disabled!");
		
		
	}

	@Override
	public void onEnable() {
		PluginDescriptionFile pdffile = this.getDescription();
		this.logger.info(pdffile.getName() + " v" + pdffile.getVersion() + " Has been enabled!");
		PluginManager pm = getServer().getPluginManager();
		pm.registerEvents(this.pl, this);
	}
	
}

MyPlayerListener.java

package me.mraljabal.expbank;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class MyPlayerListener implements Listener {
	public static ExpBank plugin;
	
	public MyPlayerListener(ExpBank instance) {
		plugin = instance;
	}
	
	@EventHandler
	public void playerInteract(PlayerInteractEvent event){
		Player player = event.getPlayer();
		Action action = event.getAction(); 
		if(action.equals(Action.LEFT_CLICK_BLOCK)){
			Block b = event.getClickedBlock();
			if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)){
				Sign sign = (Sign) b.getState();
				if (sign.getLine(1).equals(player.getName()) && sign.getLine(0).equals(ChatColor.DARK_RED + "[ExpBank]")){
					String str = sign.getLine(2);
					if(!str.equalsIgnoreCase("0")){
					int bankamount = Integer.parseInt(str);
					String newbankamount = Integer.toString(bankamount-1);
					player.setLevel(player.getLevel()+1);
					player.sendMessage(ChatColor.GREEN + "[ExpBank] You withdraw 1 Level.");
					sign.setLine(2, newbankamount);
					sign.update();
					}
				}
				
			}
		}else if(action.equals(Action.RIGHT_CLICK_BLOCK)){
			Block b = event.getClickedBlock();
			if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)){
				Sign sign = (Sign) b.getState();
				if (sign.getLine(1).equals(player.getName()) && sign.getLine(0).equals(ChatColor.DARK_RED + "[ExpBank]")){
					if(player.getLevel() >= 1){
						String str = sign.getLine(2);
						int bankamount = Integer.parseInt(str);
						String newbankamount = Integer.toString(bankamount+1);
						sign.setLine(2, newbankamount);
						sign.update();
						player.setLevel(player.getLevel()-1);
						player.sendMessage(ChatColor.GREEN + "[ExpBank] You deposit 1 Level.");
					}
				}
			}
		}
	}
	
	@EventHandler
	public void signChange (SignChangeEvent sign){
		Player player = sign.getPlayer();
		if(sign.getLine(0).equalsIgnoreCase("[ExpBank]")){
			if (player.hasPermission("ExpBank.create")){
				sign.setLine(0, ChatColor.DARK_RED + "[ExpBank]");
				sign.setLine(1, player.getName());
				sign.setLine(2, "0");
				sign.setLine(3, ChatColor.DARK_RED + "By MrAljabal");
			}else{
				player.sendMessage(ChatColor.RED + "You don't have permission to create ExpBank sign.");
			}
		}else if(sign.getLine(0).equalsIgnoreCase("&4[ExpBank]")){
			if (player.hasPermission("ExpBank.create")){
				sign.setLine(0, ChatColor.DARK_RED + "[ExpBank]");
				sign.setLine(1, player.getName());
				sign.setLine(2, "0");
				sign.setLine(3, ChatColor.DARK_RED + "By MrAljabal");
			}else{
				player.sendMessage(ChatColor.RED + "You don't have permission to create ExpBank sign.");
			}
		}
	}
}

Plugin.yml

name: ExpBank
main: me.mraljabal.expbank.ExpBank
version: 1.0
description: >
             Saves EXP By Signs

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Sep 06, 2012
Last updated
Sep 06, 2012

Author