Skip to content

Commit

Permalink
Protection event handlers set up and base code for land management ad…
Browse files Browse the repository at this point in the history
…ded.
  • Loading branch information
jcdesimp committed Mar 4, 2014
1 parent a2e3474 commit 0893b3c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 14 deletions.
108 changes: 108 additions & 0 deletions src/com/jcdesimp/landlord/LandListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.jcdesimp.landlord;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import javax.persistence.Entity;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
* File created by jcdesimp on 3/4/14.
*/
public class LandListener implements Listener {

JavaPlugin plugin;

public LandListener(JavaPlugin p) {
plugin = p;
}


@EventHandler(priority = EventPriority.HIGH)
public void animalKill(EntityDamageByEntityEvent event){
org.bukkit.entity.Entity victim = event.getEntity();
org.bukkit.entity.Entity attacker = event.getDamager();

System.out.println("Victim: "+victim.getType().toString());
System.out.println("Attacker: " + attacker.getType().toString());
if(attacker.getType().toString().equals("PLAYER")){
Player p = (Player)attacker;
System.out.println("Attacker Name:" + p.getName());

if(p.getName().equalsIgnoreCase("jcdesimp")){

event.setCancelled(true);
return;
}

} else if(attacker.getType().toString().equalsIgnoreCase("Arrow")){
Arrow a = (Arrow)attacker;
Player p;
if(a.getShooter() instanceof Player){
p = (Player)a.getShooter();
System.out.println("Shooter: " + p.getName());
if(p.getName().equalsIgnoreCase("jcdesimp")){
event.setCancelled(true);
return;
}
}


}
}

@EventHandler(priority = EventPriority.HIGH)
public void blockPlace(BlockPlaceEvent event){
Player p = event.getPlayer();
if(p.getName().equalsIgnoreCase("jcdesimp")){
//p.sendMessage(ChatColor.RED + "You are not allowed to build on this land.");
//event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH)
public void blockBreak(BlockBreakEvent event){
Player p = event.getPlayer();
if(p.getName().equalsIgnoreCase("jcdesimp")){
//p.sendMessage(ChatColor.RED + "You are not allowed to break on this land.");
//event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.HIGH)
public void storageOpen(PlayerInteractEvent event){
String[] blockAccess = {"CHEST","TRAPPED_CHEST","BURNING_FURNACE","FURNACE","ANVIL","DROPPER","DISPENSER","HOPPER"};
if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) &&
Arrays.asList(blockAccess).contains(event.getClickedBlock().getType().toString())){

System.out.println("Block Clicked: " + event.getClickedBlock().getType().toString());
event.setCancelled(true);


}
}


}
9 changes: 0 additions & 9 deletions src/com/jcdesimp/landlord/LandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,6 @@ public static String[] buildMap(Player p) {


String[][] mapBoard = getMapDir(getPlayerDirection(p));
/*String[][] mapBoard = new String[][]{
{"▒", "▒", "▓", "▓", "▓", "▒", "▒"},
{"▒", "▒", "▒", "▓", "▒", "▒", "▒"},
{"▒", "▒", "▒", "▒", "▓", "▒", "▒"},
{"▒", "▒", "▒", "█", "▒", "▒", "▒"},
{"▒", "▒", "▒", "▓", "▓", "▒", "▒"},
{"▒", "▒", "▓", "▒", "▓", "▒", "▒"},
{"▒", "▒", "▒", "▒", "▒", "▒", "▒"}
};*/

String[] mapRows = new String[mapBoard.length];

Expand Down
5 changes: 5 additions & 0 deletions src/com/jcdesimp/landlord/Landlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.lennardf1989.bukkitex.MyDatabase;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import javax.persistence.PersistenceException;
Expand All @@ -19,10 +20,14 @@ public final class Landlord extends JavaPlugin {

private MyDatabase database;
private static Landlord plugin;
//private LandListener listner;


@Override
public void onEnable() {
plugin = this;
//listner = new LandListener();
getServer().getPluginManager().registerEvents(new LandListener(this), this);
setupDatabase();
getLogger().info(getDescription().getName() + " has been enabled!");

Expand Down
36 changes: 31 additions & 5 deletions src/com/jcdesimp/landlord/LandlordCommandExecutor.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package com.jcdesimp.landlord;

import com.avaje.ebean.Ebean;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Effect;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import com.DarkBladee12.ParticleAPI.ParticleEffect;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;

import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -68,6 +70,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else if(args[0].equalsIgnoreCase("map")) {

return landlord_map(sender, args);
} else if(args[0].equalsIgnoreCase("manage")) {
return landlord_manage(sender, args);
}

} //If this has happened the function will return true.
Expand Down Expand Up @@ -261,7 +265,7 @@ private boolean landlord_remfriend(CommandSender sender, String[] args) {
* @param args
* @return
*/
public boolean landlord_map(CommandSender sender, String[] args) {
private boolean landlord_map(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.DARK_RED + "This command can only be run by a player.");
} else {
Expand Down Expand Up @@ -292,4 +296,26 @@ public void run() {

}

private boolean landlord_manage(CommandSender sender, String[] args){
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.DARK_RED + "This command can only be run by a player.");
} else {
Player player = (Player) sender;

Inventory inv = Bukkit.createInventory(null,27,"Land Manager");
ItemStack is = new ItemStack(Material.SIGN);
ItemMeta im = is.getItemMeta();
im.setDisplayName("Test Button");
ArrayList<String> lore = new ArrayList<String>();
lore.add("Test1");
lore.add("Test2");
im.setLore(lore);
is.setItemMeta(im);
inv.setItem(1,is);
player.openInventory(inv);
}
return true;

}

}

0 comments on commit 0893b3c

Please sign in to comment.