Merge remote-tracking branch 'origin/clans-beta' into clans-beta

# Conflicts:
#	Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java
This commit is contained in:
Shaun Bennett 2015-11-17 18:05:17 -05:00
commit 4183f0ce07
9 changed files with 482 additions and 270 deletions

View File

@ -14,6 +14,8 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.EnumDirection;
public class UtilAlg public class UtilAlg
{ {
public static TreeSet<String> sortKey(Set<String> toSort) public static TreeSet<String> sortKey(Set<String> toSort)
@ -496,4 +498,5 @@ public class UtilAlg
return value; return value;
} }
} }

View File

@ -16,7 +16,7 @@ public class UtilMath
{ {
String format = "#.#"; String format = "#.#";
for (int i=1 ; i<degree ; i++) for (int i = 1; i < degree; i++)
format += "#"; format += "#";
DecimalFormatSymbols symb = new DecimalFormatSymbols(Locale.US); DecimalFormatSymbols symb = new DecimalFormatSymbols(Locale.US);
@ -24,8 +24,8 @@ public class UtilMath
return Double.valueOf(twoDForm.format(d)); return Double.valueOf(twoDForm.format(d));
} }
public static Random random = new Random(); public static Random random = new Random();
public static int r(int i) public static int r(int i)
{ {
return random.nextInt(i); return random.nextInt(i);
@ -85,23 +85,20 @@ public class UtilMath
public static double rr(double d, boolean bidirectional) public static double rr(double d, boolean bidirectional)
{ {
if (bidirectional) if (bidirectional) return Math.random() * (2 * d) - d;
return Math.random() * (2 * d) - d;
return Math.random() * d; return Math.random() * d;
} }
public static <T> T randomElement(T[] array) public static <T> T randomElement(T[] array)
{ {
if (array.length == 0) if (array.length == 0) return null;
return null;
return array[random.nextInt(array.length)]; return array[random.nextInt(array.length)];
} }
public static <T> T randomElement(List<T> list) public static <T> T randomElement(List<T> list)
{ {
if (list.isEmpty()) if (list.isEmpty()) return null;
return null;
return list.get(random.nextInt(list.size())); return list.get(random.nextInt(list.size()));
} }
@ -120,4 +117,3 @@ public class UtilMath
return num < min ? min : (num > max ? max : num); return num < min ? min : (num > max ? max : num);
} }
} }

View File

@ -8,10 +8,6 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -27,6 +23,10 @@ import org.bukkit.inventory.InventoryView;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PlayerConnection;
public class UtilPlayer public class UtilPlayer
{ {
private static Random RANDOM = new Random(); private static Random RANDOM = new Random();

View File

@ -676,9 +676,9 @@ public class ClansDataAccessLayer
* EnemyData iData = initiator.getEnemyData(); ClanInfo other = clan == * EnemyData iData = initiator.getEnemyData(); ClanInfo other = clan ==
* initiator ? otherClan : clan; EnemyData oData = other.getEnemyData(); * initiator ? otherClan : clan; EnemyData oData = other.getEnemyData();
* _repository.updateEnemy(initiator.getId(), other.getId(), * _repository.updateEnemy(initiator.getId(), other.getId(),
* iData.getClanAScore(), oData.getClanAScore(), iData.getKills(), oData.getKills()); * iData.getClanAScore(), oData.getClanAScore(), iData.getKills(),
* //Log _manager.log("Updated Enemy Data for [" + clan.getName() + ", " + * oData.getKills()); //Log _manager.log("Updated Enemy Data for [" +
* otherClan.getName() + "]"); } * clan.getName() + ", " + otherClan.getName() + "]"); }
*/ */
public void updateGenerator(final ClanInfo clanInfo, final Callback<Boolean> callback) public void updateGenerator(final ClanInfo clanInfo, final Callback<Boolean> callback)

View File

@ -27,6 +27,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestoreData; import mineplex.core.blockrestore.BlockRestoreData;
@ -35,23 +36,25 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class ClansGame extends MiniPlugin public class ClansGame extends MiniPlugin
{ {
private ClansManager Clans; private ClansManager _clans;
public ClansGame(JavaPlugin plugin, ClansManager clans) public ClansGame(JavaPlugin plugin, ClansManager clans)
{ {
super("Clans Game", plugin); super("Clans Game", plugin);
Clans = clans; _clans = clans;
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@ -63,7 +66,7 @@ public class ClansGame extends MiniPlugin
{ {
if (!event.getPlayer().isSneaking() || !hasItem) if (!event.getPlayer().isSneaking() || !hasItem)
{ {
Clans.getClassShop().attemptShopOpen(event.getPlayer()); _clans.getClassShop().attemptShopOpen(event.getPlayer());
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -72,43 +75,37 @@ public class ClansGame extends MiniPlugin
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void BlockBurn(BlockBurnEvent event) public void BlockBurn(BlockBurnEvent event)
{ {
if (Clans.getClanUtility().isBorderlands(event.getBlock().getLocation())) if (_clans.getClanUtility().isBorderlands(event.getBlock().getLocation())) event.setCancelled(true);
event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void BlockSpread(BlockIgniteEvent event) public void BlockSpread(BlockIgniteEvent event)
{ {
if (event.getCause() == IgniteCause.SPREAD) if (event.getCause() == IgniteCause.SPREAD) if (_clans.getClanUtility().isBorderlands(event.getBlock().getLocation())) event.setCancelled(true);
if (Clans.getClanUtility().isBorderlands(event.getBlock().getLocation()))
event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void BlockPlace(BlockPlaceEvent event) public void BlockPlace(BlockPlaceEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled()) return;
return;
if (event.getBlock().getType() != Material.LADDER) if (event.getBlock().getType() != Material.LADDER) return;
return;
if (Clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF) if (_clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF) return;
return;
final Block block = event.getBlock(); final Block block = event.getBlock();
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Clans.getPlugin(), new Runnable() UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(_clans.getPlugin(), new Runnable()
{ {
public void run() public void run()
{ {
Clans.getBlockRestore().add(block, 65, block.getData(), 30000); _clans.getBlockRestore().add(block, 65, block.getData(), 30000);
BlockRestoreData data = Clans.getBlockRestore().getData(block); BlockRestoreData data = _clans.getBlockRestore().getData(block);
if (data != null) if (data != null)
{ {
data.setFromId(0); data.setFromId(0);
data.setFromData((byte)0); data.setFromData((byte) 0);
} }
} }
}, 0); }, 0);
@ -123,11 +120,11 @@ public class ClansGame extends MiniPlugin
Player defender = (Player) event.getCaught(); Player defender = (Player) event.getCaught();
Player attacker = event.getPlayer(); Player attacker = event.getPlayer();
if (!Clans.getClanUtility().canHurt(defender, attacker)) if (!_clans.getClanUtility().canHurt(defender, attacker))
{ {
event.setCancelled(true); event.setCancelled(true);
ClanRelation rel = Clans.getRelation(defender, attacker); ClanRelation rel = _clans.getRelation(defender, attacker);
UtilPlayer.message(attacker, F.main("Clans", "You cannot harm " + Clans.getClanUtility().mRel(rel, defender.getName(), false) + ".")); UtilPlayer.message(attacker, F.main("Clans", "You cannot harm " + _clans.getClanUtility().mRel(rel, defender.getName(), false) + "."));
} }
} }
} }
@ -158,166 +155,142 @@ public class ClansGame extends MiniPlugin
@EventHandler @EventHandler
public final void onFoodLevelChangeEvent(FoodLevelChangeEvent event) public final void onFoodLevelChangeEvent(FoodLevelChangeEvent event)
{ {
((Player) event.getEntity()).setSaturation(3.8F); // While not entirely accurate, this is a pretty good guess at original food level changes ((Player) event.getEntity()).setSaturation(3.8F); // While not entirely
// accurate, this is
// a pretty good
// guess at original
// food level
// changes
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void BlockBreak(BlockBreakEvent event) public void BlockBreak(BlockBreakEvent event)
{ {
if (event.getPlayer().getWorld().getEnvironment() != Environment.NORMAL || event.getPlayer().getGameMode() == GameMode.CREATIVE) if (event.getPlayer().getWorld().getEnvironment() != Environment.NORMAL || event.getPlayer().getGameMode() == GameMode.CREATIVE) return;
return;
String mimic = Clans.Get(event.getPlayer()).getMimic(); String mimic = _clans.Get(event.getPlayer()).getMimic();
if (mimic.length() != 0) if (mimic.length() != 0)
{ {
if (Clans.getClanUtility().searchClanPlayer(event.getPlayer(), mimic, false) != null) if (_clans.getClanUtility().searchClanPlayer(event.getPlayer(), mimic, false) != null)
mimic = C.cGray + " You are currently mimicing " + C.cGold + mimic; mimic = C.cGray + " You are currently mimicing " + C.cGold + mimic;
else else
mimic = ""; mimic = "";
} }
//Borderlands // Borderlands
if (Clans.getClanUtility().isBorderlands(event.getBlock().getLocation()) && event.getPlayer().getGameMode() != GameMode.CREATIVE) if (_clans.getClanUtility().isBorderlands(event.getBlock().getLocation()) && event.getPlayer().getGameMode() != GameMode.CREATIVE)
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break " + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break blocks in " + F.elem("Borderlands") + "."));
F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) +
" in " +
F.elem("Borderlands") +
"."));
return; return;
} }
if (Clans.getClanBlocks().canBreak(event.getBlock().getTypeId())) if (_clans.getClanBlocks().canBreak(event.getBlock().getTypeId())) return;
return;
if (Clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF) if (_clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF)
{ {
//Disallow Shops // Disallow Shops
if (event.getBlock().getType() == Material.ENDER_CHEST || event.getBlock().getType() == Material.ENCHANTMENT_TABLE) if (event.getBlock().getType() == Material.ENDER_CHEST || event.getBlock().getType() == Material.ENCHANTMENT_TABLE) if (_clans.getClanUtility().isSafe(event.getBlock().getLocation()))
if (Clans.getClanUtility().isSafe(event.getBlock().getLocation())) {
// Disallow
event.setCancelled(true);
// Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break blocks in " + _clans.getClanUtility().getOwnerStringRel(event.getBlock().getLocation(), event.getPlayer()) + "'s Territory."));
}
// Disallow Recruit Chest
if (_clans.getClanUtility().isClaimed(event.getBlock().getLocation())) if (event.getBlock().getTypeId() == 54)
{
if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT)
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break " + UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " + F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + "."));
F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) +
" in " +
Clans.getClanUtility().getOwnerStringRel(event.getBlock().getLocation(), event.getPlayer()) +
"."));
} }
}
//Disallow Recruit Chest // Allow
if (Clans.getClanUtility().isClaimed(event.getBlock().getLocation()))
if (event.getBlock().getTypeId() == 54)
{
if (Clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT)
{
//Disallow
event.setCancelled(true);
//Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " +
F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + "."));
}
}
//Allow
return; return;
} }
if (Clans.getWarManager().allowFromInvade(event.getBlock().getLocation(), event.getPlayer())) if (_clans.getWarManager().allowFromInvade(event.getBlock().getLocation(), event.getPlayer()))
{ {
// Allow because of invasion // Allow because of invasion
return; return;
} }
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break " + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can not break blocks in " + _clans.getClanUtility().getOwnerStringRel(event.getBlock().getLocation(), event.getPlayer()) + "'s Territory." + mimic));
F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) +
" in " +
Clans.getClanUtility().getOwnerStringRel(event.getBlock().getLocation(), event.getPlayer()) +
"." +
mimic));
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void Damage(CustomDamageEvent event) public void Damage(CustomDamageEvent event)
{ {
if (event.IsCancelled()) if (event.IsCancelled()) return;
return;
Player damagee = event.GetDamageePlayer(); Player damagee = event.GetDamageePlayer();
if (damagee == null) return; if (damagee == null) return;
Player damager = event.GetDamagerPlayer(true); Player damager = event.GetDamagerPlayer(true);
if (damager == null) return; if (damager == null) return;
if (!Clans.getClanUtility().canHurt(damagee, damager)) if (!_clans.getClanUtility().canHurt(damagee, damager))
{ {
//Cancel // Cancel
event.SetCancelled("Clans Ally"); event.SetCancelled("Clans Ally");
//Inform // Inform
if (damager != null) if (damager != null)
{ {
ClanRelation rel = Clans.getRelation(damagee, damager); ClanRelation rel = _clans.getRelation(damagee, damager);
UtilPlayer.message(damager, F.main("Clans", UtilPlayer.message(damager, F.main("Clans", "You cannot harm " + _clans.getClanUtility().mRel(rel, damagee.getName(), false) + "."));
"You cannot harm " + Clans.getClanUtility().mRel(rel, damagee.getName(), false) + "."));
} }
} }
} }
//Block Interact and Placement // Block Interact and Placement
public void Interact(PlayerInteractEvent event) public void Interact(PlayerInteractEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.getWorld().getEnvironment() != Environment.NORMAL) if (player.getWorld().getEnvironment() != Environment.NORMAL) return;
return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.LEFT_CLICK_BLOCK) return;
return;
//Block Interaction // Block Interaction
Location loc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(); Location loc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
if (UtilBlock.usable(event.getClickedBlock())) loc = event.getClickedBlock().getLocation(); if (UtilBlock.usable(event.getClickedBlock())) loc = event.getClickedBlock().getLocation();
if (Clans.getWarManager().allowFromInvade(loc, event.getPlayer())) if (_clans.getWarManager().allowFromInvade(loc, event.getPlayer()))
{ {
// Allow because of invasion // Allow because of invasion
return; return;
} }
//Borderlands // Borderlands
if ( player.getGameMode() != GameMode.CREATIVE && if (player.getGameMode() != GameMode.CREATIVE && player.getItemInHand() != null && _clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()) && _clans.getClanUtility().isBorderlands(event.getClickedBlock().getLocation()))
player.getItemInHand() != null &&
Clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()) &&
Clans.getClanUtility().isBorderlands(event.getClickedBlock().getLocation()))
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "You cannot use/place " + UtilPlayer.message(player, F.main("Clans", "You cannot place blocks in " + F.elem("Borderlands") + "."));
F.elem(ItemStackFactory.Instance.GetName(event.getClickedBlock(), true)) +
" in " +
F.elem("Borderlands") +
"."));
return; return;
} }
ClanRelation access = Clans.getClanUtility().getAccess(player, loc); ClanRelation access = _clans.getClanUtility().getAccess(player, loc);
//Hoe Return // Hoe Return
if (access != ClanRelation.SELF && !UtilBlock.usable(event.getClickedBlock())) if (access != ClanRelation.SELF && !UtilBlock.usable(event.getClickedBlock()))
{ {
if (UtilGear.isHoe(player.getItemInHand())) if (UtilGear.isHoe(player.getItemInHand()))
@ -327,69 +300,52 @@ public class ClansGame extends MiniPlugin
} }
} }
//Full Access // Full Access
if (access == ClanRelation.SELF) if (access == ClanRelation.SELF)
{ {
//Recruits cannot open Chests // IN OWN CLAIMED LAND // Recruits cannot open Chests // IN OWN CLAIMED LAND
if (event.getClickedBlock().getTypeId() == 54 && Clans.getClanUtility().getOwner(loc) != null) if (event.getClickedBlock().getTypeId() == 54 && _clans.getClanUtility().getOwner(loc) != null)
{ {
if (Clans.getClanUtility().getRole(player) == ClanRole.RECRUIT) if (_clans.getClanUtility().getRole(player) == ClanRole.RECRUIT)
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "Clan Recruits cannot access " + UtilPlayer.message(player, F.main("Clans", "Clan Recruits cannot access " + F.elem(ItemStackFactory.Instance.GetName(event.getClickedBlock(), true)) + "."));
F.elem(ItemStackFactory.Instance.GetName(event.getClickedBlock(), true)) +
"."));
} }
} }
//Wilderness Adjacent // Wilderness Adjacent
if ( event.getAction() == Action.RIGHT_CLICK_BLOCK && if (event.getAction() == Action.RIGHT_CLICK_BLOCK && !UtilBlock.usable(event.getClickedBlock()) && player.getItemInHand() != null && _clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()) && !_clans.getClanUtility().isClaimed(loc))
!UtilBlock.usable(event.getClickedBlock()) &&
player.getItemInHand() != null &&
Clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()) &&
!Clans.getClanUtility().isClaimed(loc))
{ {
String enemy = null; String enemy = null;
boolean self = false; boolean self = false;
for (int x=-1 ; x<=1 ; x++) for (int x = -1; x <= 1; x++)
for (int z=-1 ; z<=1 ; z++) for (int z = -1; z <= 1; z++)
{ {
if (self) if (self) continue;
continue;
if (x != 0 && z != 0 || x == 0 && z == 0) if (x != 0 && z != 0 || x == 0 && z == 0) continue;
continue;
Location sideLoc = new Location(loc.getWorld(), loc.getX()+x, loc.getY(), loc.getZ()+z); Location sideLoc = new Location(loc.getWorld(), loc.getX() + x, loc.getY(), loc.getZ() + z);
if (Clans.getClanUtility().isSelf(player, sideLoc)) if (_clans.getClanUtility().isSelf(player, sideLoc)) self = true;
self = true;
if (enemy != null) if (enemy != null) continue;
continue;
if (Clans.getClanUtility().getAccess(player, sideLoc) != ClanRelation.SELF) if (_clans.getClanUtility().getAccess(player, sideLoc) != ClanRelation.SELF) enemy = _clans.getClanUtility().getOwnerStringRel(new Location(loc.getWorld(), loc.getX() + x, loc.getY(), loc.getZ() + z), player);
enemy = Clans.getClanUtility().getOwnerStringRel(
new Location(loc.getWorld(), loc.getX()+x, loc.getY(), loc.getZ()+z),
player);
} }
if (enemy != null && !self) if (enemy != null && !self)
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "You cannot use/place " + UtilPlayer.message(player, F.main("Clans", "You cannot place blocks next to " + enemy + "."));
F.elem(ItemStackFactory.Instance.GetName(player.getItemInHand(), true)) +
" next to " +
enemy +
"."));
return; return;
} }
@ -398,78 +354,58 @@ public class ClansGame extends MiniPlugin
return; return;
} }
String mimic = Clans.Get(player).getMimic(); String mimic = _clans.Get(player).getMimic();
if (mimic.length() != 0) if (mimic.length() != 0)
{ {
if (Clans.getClanUtility().searchClanPlayer(player, mimic, false) != null) if (_clans.getClanUtility().searchClanPlayer(player, mimic, false) != null)
mimic = C.cGray + " You are currently mimicing " + C.cGold + mimic; mimic = C.cGray + " You are currently mimicing " + C.cGold + mimic;
else else
mimic = ""; mimic = "";
} }
//Deny Interaction // Deny Interaction
if (Clans.getClanBlocks().denyInteract(event.getClickedBlock().getTypeId())) if (_clans.getClanBlocks().denyInteract(event.getClickedBlock().getTypeId()))
{ {
//Block Action // Block Action
if (access == ClanRelation.NEUTRAL) if (access == ClanRelation.NEUTRAL)
{ {
//Allow Field Chest // Allow Field Chest
if (event.getClickedBlock().getTypeId() == 54) if (event.getClickedBlock().getTypeId() == 54) if (_clans.getClanUtility().isSpecial(event.getClickedBlock().getLocation(), "Fields")) return;
if (Clans.getClanUtility().isSpecial(event.getClickedBlock().getLocation(), "Fields"))
return;
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "You cannot use " + UtilPlayer.message(player, F.main("Clans", "You cannot use items in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(), player) + "." + mimic));
F.elem(ItemStackFactory.Instance.GetName(event.getClickedBlock(), true)) +
" in " +
Clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(),
player) +
"." +
mimic));
return; return;
} }
//Block is not Trust Allowed // Block is not Trust Allowed
else if (!Clans.getClanBlocks().allowInteract(event.getClickedBlock().getTypeId()) || access != ClanRelation.ALLY_TRUST) else if (!_clans.getClanBlocks().allowInteract(event.getClickedBlock().getTypeId()) || access != ClanRelation.ALLY_TRUST)
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "You cannot use " + UtilPlayer.message(player, F.main("Clans", "You cannot use items in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(), player) + "." + mimic));
F.elem(ItemStackFactory.Instance.GetName(event.getClickedBlock(), true)) +
" in " +
Clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(),
player) +
"." +
mimic));
return; return;
} }
} }
//Block Placement // Block Placement
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
{ {
if (player.getItemInHand().getType() != Material.AIR) if (player.getItemInHand().getType() != Material.AIR)
{ {
if (player.getGameMode() != GameMode.CREATIVE && Clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId())) if (player.getGameMode() != GameMode.CREATIVE && _clans.getClanBlocks().denyUsePlace(player.getItemInHand().getTypeId()))
{ {
//Disallow // Disallow
event.setCancelled(true); event.setCancelled(true);
//Inform // Inform
UtilPlayer.message(player, F.main("Clans", "You cannot use/place " + UtilPlayer.message(player, F.main("Clans", "You cannot place blocks in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(), player) + "." + mimic));
F.elem(ItemStackFactory.Instance.GetName(player.getItemInHand(), true)) +
" in " +
Clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(),
player) +
"." +
mimic));
return; return;
} }
@ -480,25 +416,22 @@ public class ClansGame extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void Piston(BlockPistonExtendEvent event) public void Piston(BlockPistonExtendEvent event)
{ {
ClanInfo pistonClan = Clans.getClanUtility().getOwner(event.getBlock().getLocation()); ClanInfo pistonClan = _clans.getClanUtility().getOwner(event.getBlock().getLocation());
Block push = event.getBlock(); Block push = event.getBlock();
for (int i=0 ; i<13 ; i++) for (int i = 0; i < 13; i++)
{ {
push = push.getRelative(event.getDirection()); push = push.getRelative(event.getDirection());
Block front = push.getRelative(event.getDirection()).getRelative(event.getDirection()); Block front = push.getRelative(event.getDirection()).getRelative(event.getDirection());
if (push.getType() == Material.AIR) if (push.getType() == Material.AIR) return;
return;
ClanInfo pushClan = Clans.getClanUtility().getOwner(front.getLocation()); ClanInfo pushClan = _clans.getClanUtility().getOwner(front.getLocation());
if (pushClan == null) if (pushClan == null) continue;
continue;
if (pushClan.isAdmin()) if (pushClan.isAdmin()) continue;
continue;
if (pistonClan == null) if (pistonClan == null)
{ {
@ -507,8 +440,7 @@ public class ClansGame extends MiniPlugin
return; return;
} }
if (pistonClan.equals(pushClan)) if (pistonClan.equals(pushClan)) continue;
continue;
push.getWorld().playEffect(push.getLocation(), Effect.STEP_SOUND, push.getTypeId()); push.getWorld().playEffect(push.getLocation(), Effect.STEP_SOUND, push.getTypeId());
event.setCancelled(true); event.setCancelled(true);
@ -519,8 +451,8 @@ public class ClansGame extends MiniPlugin
@EventHandler @EventHandler
public void Quit(PlayerQuitEvent event) public void Quit(PlayerQuitEvent event)
{ {
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(event.getPlayer()); ClanInfo clan = _clans.getClanUtility().getClanByPlayer(event.getPlayer());
if (clan == null) return; if (clan == null) return;
clan.setLastOnline(new Timestamp(System.currentTimeMillis())); clan.setLastOnline(new Timestamp(System.currentTimeMillis()));
} }
@ -530,18 +462,17 @@ public class ClansGame extends MiniPlugin
{ {
try try
{ {
if (event.getEntityType() != EntityType.PRIMED_TNT && event.getEntityType() != EntityType.MINECART_TNT) if (event.getEntityType() != EntityType.PRIMED_TNT && event.getEntityType() != EntityType.MINECART_TNT) return;
return;
} }
catch (Exception e) catch (Exception e)
{ {
return; return;
} }
ClanInfo clan = Clans.getClanUtility().getOwner(event.getEntity().getLocation()); ClanInfo clan = _clans.getClanUtility().getOwner(event.getEntity().getLocation());
if (clan == null) return; if (clan == null) return;
if (Clans.getWarManager().isBeingInvaded(clan)) if (_clans.getWarManager().isBeingInvaded(clan))
{ {
// Allow because of invasion // Allow because of invasion
return; return;
@ -552,4 +483,200 @@ public class ClansGame extends MiniPlugin
else else
clan.inform(C.cRed + "Your Territory is under attack!", null); clan.inform(C.cRed + "Your Territory is under attack!", null);
} }
@EventHandler
public void onClanHomeInteract(PlayerInteractEvent event)
{
if (!UtilEvent.isAction(event, ActionType.L_BLOCK) && !UtilEvent.isAction(event, ActionType.R_BLOCK))
{
return;
}
ClanInfo clan = _clans.getClan(event.getPlayer());
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if (clan == null)
{
for (String otherClanName : _clans.getClanNameSet())
{
boolean done = false;
ClanInfo otherClan = _clans.getClan(otherClanName);
if (otherClan.getHome() == null)
{
return;
}
if (!(UtilMath.offset(block.getLocation(), otherClan.getHome()) < 3))
{
return;
}
for (int x = -2; x < 2; x++)
{
for (int z = -2; z < 2; z++)
{
Block otherBlock = event.getClickedBlock().getLocation().add(x, 0, z).getBlock();
if (otherBlock.getType().equals(Material.BED_BLOCK))
{
if (UtilEvent.isAction(event, ActionType.R_BLOCK))
{
event.setCancelled(true);
done = true;
break;
}
}
}
if (done)
{
break;
}
}
if (done)
{
break;
}
}
return;
}
if (clan.getHome() == null)
{
return;
}
if (!(UtilMath.offset(block.getLocation(), clan.getHome()) < 3))
{
return;
}
for (int x = -2; x < 2; x++)
{
for (int z = -2; z < 2; z++)
{
Block otherBlock = event.getClickedBlock().getLocation().add(x, 0, z).getBlock();
if (otherBlock.getType().equals(Material.BED_BLOCK))
{
if (UtilEvent.isAction(event, ActionType.R_BLOCK))
{
event.setCancelled(true);
break;
}
if (clan.getMembers().get(player.getUniqueId()).getRole() == ClanRole.LEADER || clan.getMembers().get(player.getUniqueId()).getRole() == ClanRole.ADMIN)
{
break;
}
else
{
UtilPlayer.message(player, F.main("Clans", "Only the Clan Leader and Admins can manage the Clan Home."));
break;
}
}
}
}
}
@EventHandler
public void onPlaceBed(BlockPlaceEvent event)
{
if (event.getItemInHand().getType().equals(Material.BED) || event.getItemInHand().getType().equals(Material.BED_BLOCK))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot manually place beds, to set your clan home, type " + F.elem("/c sethome") + "."));
event.setCancelled(true);
}
}
@EventHandler
public void onClanHomeDestroyed(BlockBreakEvent event)
{
ClanInfo userClan = _clans.getClan(event.getPlayer());
Block block = event.getBlock();
Player player = event.getPlayer();
ClanInfo blockClan = null;
ClanTerritory claim = _clans.getClanUtility().getClaim(block.getLocation());
if (claim != null)
{
if (ClansBlacklist.isValidClanName(claim.Owner))
{
blockClan = _clans.getClan(claim.Owner);
}
}
if (blockClan == null)
{
return;
}
if (blockClan.getHome() == null)
{
return;
}
if (UtilMath.offset(block.getLocation(), blockClan.getHome()) > 3)
{
return;
}
if (!block.getType().equals(Material.BED_BLOCK))
{
return;
}
if (!blockClan.equals(userClan))
{
if (blockClan.isAlly(userClan))
{
UtilPlayer.message(player, F.main("Clans", "You cannot remove an Ally's Clan Home."));
}
else
{
UtilPlayer.message(player, F.main("Clans", "You have destroyed " + F.elem(blockClan.getName()) + "'s Clan Home!"));
removeHome(userClan);
}
return;
}
if (userClan.getMembers().get(player.getUniqueId()).getRole() == ClanRole.LEADER || userClan.getMembers().get(player.getUniqueId()).getRole() == ClanRole.ADMIN)
{
event.setCancelled(true);
removeHome(userClan);
UtilPlayer.message(player, F.main("Clans", "You have removed your Clan Home."));
}
else
{
event.setCancelled(true);
UtilPlayer.message(player, F.main("Clans", "Only the Clan Leader and Admins can remove the Clan Home."));
}
}
private void removeHome(ClanInfo clan)
{
clan.getHome().getBlock().setType(Material.AIR);
for (int x2 = -1; x2 < 1; x2++)
{
for (int z2 = -1; z2 < 1; z2++)
{
Block block = clan.getHome().clone().add(x2, 0, z2).getBlock();
if (block.getType().equals(Material.BED_BLOCK))
{
block.setType(Material.AIR);
}
}
}
clan.setHome(null);
}
} }

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.clans;
import java.io.File; import java.io.File;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
@ -24,6 +25,7 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
@ -271,6 +273,18 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
// Initialize default region factions and territory (spawn/fields/borderlands) // Initialize default region factions and territory (spawn/fields/borderlands)
_clanRegions = new ClansRegions(plugin, this); _clanRegions = new ClansRegions(plugin, this);
_clanRegions.initializeRegions(); _clanRegions.initializeRegions();
// Disables beds from being crafted
Iterator<Recipe> it = _plugin.getServer().recipeIterator();
Recipe recipe;
while(it.hasNext())
{
recipe = it.next();
if (recipe != null && recipe.getResult().getType() == Material.BED)
{
it.remove();
}
}
} }
@Override @Override

View File

@ -2,7 +2,9 @@ package mineplex.game.clans.clans.commands;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Chunk; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
@ -11,24 +13,21 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInput; import mineplex.core.common.util.UtilInput;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole; import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansPlayer; import mineplex.game.clans.clans.ClansPlayer;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ClientClan; import mineplex.game.clans.clans.ClientClan;
import mineplex.game.clans.clans.event.ClanDisbandedEvent; import mineplex.game.clans.clans.event.ClanDisbandedEvent;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent; import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.tutorials.TutorialManager; import mineplex.game.clans.tutorials.TutorialManager;
import net.minecraft.server.v1_8_R3.EnumDirection;
public class ClansCommand extends CommandBase<ClansManager> public class ClansCommand extends CommandBase<ClansManager>
{ {
@ -828,6 +827,14 @@ public class ClansCommand extends CommandBase<ClansManager>
return; return;
} }
Location home = clan.getHome();
if (!(home.getBlock().getType().equals(Material.BED) && home.add(0,1,0).getBlock().getType().equals(Material.AIR)))
{
UtilPlayer.message(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed."));
return;
}
/* /*
* CoreClient client = _plugin.getClientManager().Get(caller); for * CoreClient client = _plugin.getClientManager().Get(caller); for
* (Player cur : clan.GetHome().getWorld().getPlayers()) if * (Player cur : clan.GetHome().getWorld().getPlayers()) if
@ -838,7 +845,7 @@ public class ClansCommand extends CommandBase<ClansManager>
* } * }
*/ */
if (!Recharge.Instance.use(caller, "Clans Teleport", "Clans Teleport", 300000, true, false, false, false)) return; // if (!Recharge.Instance.use(caller, "Clans Teleport", "Clans Teleport", 300000, true, false, false, false)) return;
// Do // Do
Plugin.getTeleport().TP(caller, clan.getHome()); Plugin.getTeleport().TP(caller, clan.getHome());
@ -875,6 +882,71 @@ public class ClansCommand extends CommandBase<ClansManager>
return; return;
} }
EnumDirection dir = EnumDirection.fromAngle(caller.getLocation().getYaw());
int xModif = 0;
int zModif = 0;
int dirFlag = 0x2; // North as default
if (dir == EnumDirection.NORTH)
{
zModif = -1;
dirFlag = 0x2;
}
if (dir == EnumDirection.SOUTH)
{
zModif = 1;
dirFlag = 0x0;
}
if (dir == EnumDirection.WEST)
{
xModif = -1;
dirFlag = 0x1;
}
if (dir == EnumDirection.EAST)
{
xModif = 1;
dirFlag = 0x3;
}
BlockState bedBlock1 = caller.getLocation().getBlock().getState();
BlockState bedBlock2 = caller.getLocation().add(xModif, 0, zModif).getBlock().getState();
// Check space
if (!(bedBlock1.getType() == Material.AIR && bedBlock2.getType() == Material.AIR && bedBlock1.getLocation().add(0, 1, 0).getBlock().getType() == Material.AIR && bedBlock2.getLocation().add(0, 1, 0).getBlock().getType() == Material.AIR))
{
UtilPlayer.message(caller, F.main("Clans", "There is not enough room here to place a bed."));
return;
}
// Cleanup old
if (clan.getHome() != null)
{
for (int x = -2; x < 2; x++)
{
for (int z = -2; z < 2; z++)
{
if (clan.getHome().clone().add(x, 0, z).getBlock().getType().equals(Material.BED_BLOCK))
{
clan.getHome().clone().add(x, 0, z).getBlock().setType(Material.AIR);
}
}
}
}
// Create new
bedBlock1.setType(Material.BED_BLOCK);
bedBlock2.setType(Material.BED_BLOCK);
bedBlock1.setRawData((byte) (dirFlag));
bedBlock2.setRawData((byte) (0x8 | dirFlag)); // 0x8 says that this is the bottom of the bed
bedBlock1.update(true, false);
bedBlock2.update(true, false);
// Task // Task
Plugin.getClanDataAccess().home(clan, caller.getLocation(), caller.getName()); Plugin.getClanDataAccess().home(clan, caller.getLocation(), caller.getName());

View File

@ -10,7 +10,7 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventManager>
{ {
public WorldEventCommand(WorldEventManager plugin) public WorldEventCommand(WorldEventManager plugin)
{ {
super(plugin, Rank.DEVELOPER, new Rank[] { Rank.JNR_DEV }, "worldevent", "we", "event"); super(plugin, Rank.ALL, "worldevent", "we", "event");
AddCommand(new StartCommand(Plugin)); AddCommand(new StartCommand(Plugin));
AddCommand(new ClearCommand(Plugin)); AddCommand(new ClearCommand(Plugin));

View File

@ -481,29 +481,29 @@ public class Gameplay extends MiniPlugin
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler // @EventHandler
public void onBlockPlace(BlockPlaceEvent event) // public void onBlockPlace(BlockPlaceEvent event)
{ // {
Location location = event.getBlock().getLocation(); // Location location = event.getBlock().getLocation();
//
if (_clansManager.getClanUtility().isNearAdminClaim(location)) // if (_clansManager.getClanUtility().isNearAdminClaim(location))
{ // {
event.setCancelled(true); // event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot place blocks near admin territories!")); // UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot place blocks near admin territories!"));
} // }
} // }
//
@EventHandler // @EventHandler
public void onBlockBreak(BlockBreakEvent event) // public void onBlockBreak(BlockBreakEvent event)
{ // {
Location location = event.getBlock().getLocation(); // Location location = event.getBlock().getLocation();
//
if (_clansManager.getClanUtility().isNearAdminClaim(location)) // if (_clansManager.getClanUtility().isNearAdminClaim(location))
{ // {
event.setCancelled(true); // event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot break blocks near admin territories!")); // UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot break blocks near admin territories!"));
} // }
} // }
/* /*
@EventHandler (priority = EventPriority.HIGHEST) @EventHandler (priority = EventPriority.HIGHEST)