Fixed some issues in clans

This commit is contained in:
Sam 2018-07-24 13:47:42 +01:00 committed by Alexander Meech
parent 558682f07d
commit 55e01b3259
8 changed files with 137 additions and 97 deletions

View File

@ -37,6 +37,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapedRecipe;
@ -46,7 +48,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.Permission;
import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.blockrestore.BlockRestoreData;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
@ -57,7 +58,6 @@ import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath; 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.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
@ -180,10 +180,10 @@ public class ClansGame extends MiniPlugin
if (event.getCause() == IgniteCause.SPREAD) if (_clans.getClanUtility().isBorderlands(event.getBlock().getLocation())) event.setCancelled(true); if (event.getCause() == IgniteCause.SPREAD) if (_clans.getClanUtility().isBorderlands(event.getBlock().getLocation())) event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void BlockPlace(BlockPlaceEvent event) public void BlockPlace(BlockPlaceEvent event)
{ {
if (event.isCancelled()) return; Player player = event.getPlayer();
if (isDupedFromClassShop(event.getItemInHand())) if (isDupedFromClassShop(event.getItemInHand()))
{ {
@ -192,26 +192,26 @@ public class ClansGame extends MiniPlugin
{ {
if (ClansManager.getInstance().getClientManager().Get(p).hasPermission(Perm.DUPE_ALERT)) if (ClansManager.getInstance().getClientManager().Get(p).hasPermission(Perm.DUPE_ALERT))
{ {
UtilPlayer.message(p, F.elem("[" + C.cRedB + "!" + C.cGray + "] ") + event.getPlayer().getName() + " just tried to use a duped item/block!"); UtilPlayer.message(p, F.elem("[" + C.cRedB + "!" + C.cGray + "] ") + player.getName() + " just tried to use a duped item/block!");
} }
} }
final int slot = event.getPlayer().getInventory().getHeldItemSlot(); final int slot = player.getInventory().getHeldItemSlot();
ClansManager.getInstance().runSyncLater(() -> ClansManager.getInstance().runSyncLater(() ->
{ {
event.getPlayer().getInventory().setItem(slot, new ItemStack(Material.AIR)); player.getInventory().setItem(slot, new ItemStack(Material.AIR));
event.getPlayer().updateInventory(); player.updateInventory();
}, 1L); }, 1L);
return; return;
} }
if (_clans.getClanUtility().getAccess(event.getPlayer(), event.getBlock().getLocation()) == ClanRelation.SELF) if (_clans.getClanUtility().getAccess(player, event.getBlock().getLocation()) == ClanRelation.SELF)
{ {
if (_clans.getClanUtility().getOwner(event.getBlock().getLocation()) != null) if (_clans.getClanUtility().getOwner(event.getBlock().getLocation()) != null)
{ {
if (event.getBlock().getType() == Material.HOPPER && (event.getBlock().getRelative(BlockFace.UP).getType() == Material.CHEST || event.getBlock().getRelative(BlockFace.UP).getType() == Material.TRAPPED_CHEST)) if (event.getBlock().getType() == Material.HOPPER && (event.getBlock().getRelative(BlockFace.UP).getType() == Material.CHEST || event.getBlock().getRelative(BlockFace.UP).getType() == Material.TRAPPED_CHEST))
{ {
if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT) if (_clans.getClanUtility().getRole(player) == ClanRole.RECRUIT)
{ {
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Recruits cannot siphon items out of chests with a hopper!")); UtilPlayer.message(event.getPlayer(), F.main("Clans", "Recruits cannot siphon items out of chests with a hopper!"));
event.setCancelled(true); event.setCancelled(true);
@ -222,25 +222,33 @@ public class ClansGame extends MiniPlugin
return; return;
} }
if (event.getBlock().getType() != Material.LADDER) return;
final Block block = event.getBlock(); final Block block = event.getBlock();
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(_clans.getPlugin(), new Runnable() if (block.getType() != Material.LADDER)
{ {
public void run() return;
{ }
_clans.getBlockRestore().add(block, 65, block.getData(), 30000);
BlockRestoreData data = _clans.getBlockRestore().getData(block); if (_clans.getWorldEvent().isInEvent(block.getLocation().add(0.5, 0.5, 0.5), false) || block.equals(player.getLocation().getBlock()))
if (data != null)
{ {
data.setFromId(0); player.sendMessage("Cancelled dodgy ladder placement");
data.setFromData((byte) 0); event.setCancelled(true);
}
else
{
_clans.runSyncLater(() -> _clans.getBlockRestore().add(block, 65, block.getData(), 0, (byte) 0, 30000), 0);
} }
} }
}, 0);
@EventHandler(priority = EventPriority.MONITOR)
public void teleport(PlayerTeleportEvent event)
{
Bukkit.broadcastMessage(event.getPlayer().getName() + " : " + event.getCause() + " : " + event.isCancelled());
if (event.getCause() == TeleportCause.UNKNOWN)
{
UtilPlayer.closeInventoryIfOpen(event.getPlayer());
}
} }
@EventHandler @EventHandler

View File

@ -363,7 +363,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
new Weapon(plugin, energy); new Weapon(plugin, energy);
new Gameplay(plugin, this, blockRestore, _damageManager); new Gameplay(plugin, this, blockRestore, _damageManager);
new HiddenChestManager(this, packetHandler); new HiddenChestManager(this);
_projectileManager = new ProjectileManager(plugin); _projectileManager = new ProjectileManager(plugin);
Fire fire = new Fire(plugin, _condition, _damageManager); Fire fire = new Fire(plugin, _condition, _damageManager);

View File

@ -25,6 +25,8 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.observer.command.ObserverCommand; import mineplex.game.clans.clans.observer.command.ObserverCommand;
import mineplex.minecraft.game.core.condition.Condition;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.condition.ConditionManager;
public class ObserverManager extends MiniPlugin public class ObserverManager extends MiniPlugin
@ -35,16 +37,14 @@ public class ObserverManager extends MiniPlugin
} }
// Used to Cloak Players // Used to Cloak Players
private ConditionManager _conditionManager; private final ConditionManager _conditionManager;
private ClansManager _clansManager; private final Map<Player, ObserverData> _observerMap;
private Map<Player, ObserverData> _observerMap;
public ObserverManager(JavaPlugin plugin, ConditionManager conditionManager, ClansManager clansManager) public ObserverManager(JavaPlugin plugin, ConditionManager conditionManager, ClansManager clansManager)
{ {
super("Observer", plugin); super("Observer", plugin);
_conditionManager = conditionManager; _conditionManager = conditionManager;
_clansManager = clansManager;
_observerMap = new HashMap<>(); _observerMap = new HashMap<>();
generatePermissions(); generatePermissions();
@ -60,7 +60,7 @@ public class ObserverManager extends MiniPlugin
ObserverData data = new ObserverData(player); ObserverData data = new ObserverData(player);
((CraftPlayer) player).getHandle().spectating = true; ((CraftPlayer) player).getHandle().spectating = true;
_conditionManager.Clean(player); _conditionManager.Clean(player);
_conditionManager.Factory().Cloak("Observer", player, null, 999999999, true, true); _conditionManager.Factory().Cloak("Observer", player, null, Integer.MAX_VALUE, true, true);
UtilPlayer.clearInventory(player); UtilPlayer.clearInventory(player);
UtilPlayer.clearPotionEffects(player); UtilPlayer.clearPotionEffects(player);
player.setGameMode(GameMode.CREATIVE); player.setGameMode(GameMode.CREATIVE);
@ -82,8 +82,14 @@ public class ObserverManager extends MiniPlugin
private void restore(Player player, ObserverData data) private void restore(Player player, ObserverData data)
{ {
Condition condition = _conditionManager.GetActiveCondition(player, ConditionType.CLOAK);
if (condition != null)
{
condition.Remove();
}
data.getSnapshot().applySnapshot(player); data.getSnapshot().applySnapshot(player);
_conditionManager.Clean(player);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
((CraftPlayer) player).getHandle().spectating = false; ((CraftPlayer) player).getHandle().spectating = false;
} }

View File

@ -6,6 +6,7 @@ import mineplex.game.clans.clans.worldevent.api.WorldEvent;
import mineplex.game.clans.clans.worldevent.boss.ironwizard.GolemBoss; import mineplex.game.clans.clans.worldevent.boss.ironwizard.GolemBoss;
import mineplex.game.clans.clans.worldevent.boss.skeletonking.SkeletonBoss; import mineplex.game.clans.clans.worldevent.boss.skeletonking.SkeletonBoss;
import mineplex.game.clans.clans.worldevent.capturepoint.CapturePointEvent; import mineplex.game.clans.clans.worldevent.capturepoint.CapturePointEvent;
import mineplex.game.clans.clans.worldevent.undead.UndeadCity;
public enum WorldEventType public enum WorldEventType
{ {
@ -15,22 +16,10 @@ public enum WorldEventType
//IRON_WIZARD("Iron Wizard", GolemBoss.class, 30), //IRON_WIZARD("Iron Wizard", GolemBoss.class, 30),
//BROOD_MOTHER("Brood Mother", SpiderBoss.class, 30), //BROOD_MOTHER("Brood Mother", SpiderBoss.class, 30),
//SKELETON_KING("Skeleton King", SkeletonBoss.class, 30) //SKELETON_KING("Skeleton King", SkeletonBoss.class, 30)
IRON_WIZARD("Iron Wizard", (man) -> IRON_WIZARD("Iron Wizard", GolemBoss::new),
{ SKELETON_KING("Skeleton King", SkeletonBoss::new),
return new GolemBoss(man); CAPTURE_POINT("Capture Point", CapturePointEvent::new),
}), UNDEAD_CITY("Undead City", UndeadCity::new)
SKELETON_KING("Skeleton King", (man) ->
{
return new SkeletonBoss(man);
}),
CAPTURE_POINT("Capture Point", (man) ->
{
return new CapturePointEvent(man);
}),
/*UNDEAD_CITY("Undead City", (man) ->
{
return new UndeadCity(man);
})*/
; ;
private String _name; private String _name;

View File

@ -13,8 +13,6 @@ import org.bukkit.Sound;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_8_R3.CraftChunk;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -31,7 +29,6 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerFishEvent.State; import org.bukkit.event.player.PlayerFishEvent.State;
@ -827,20 +824,6 @@ public class Gameplay extends MiniPlugin
event.SetCancelled("Spawn Fall"); event.SetCancelled("Spawn Fall");
} }
/**
* Cancel the spawning of all Witches.
*
* @param event
*/
@EventHandler
public void cancelWitchSpawns(EntitySpawnEvent event)
{
if (event.getEntityType() == EntityType.WITCH)
{
event.setCancelled(true);
}
}
public DamageManager getDamageManager() public DamageManager getDamageManager()
{ {
return _damageManager; return _damageManager;

View File

@ -1,55 +1,103 @@
package mineplex.game.clans.gameplay; package mineplex.game.clans.gameplay;
import mineplex.core.common.util.UtilServer; import java.util.HashMap;
import mineplex.core.packethandler.PacketHandler; import java.util.Map;
import mineplex.game.clans.clans.ClansManager;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.PacketPlayOutBlockAction;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Chest; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; import org.bukkit.entity.Player;
import org.bukkit.craftbukkit.v1_8_R3.inventory.InventoryWrapper;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.ClansManager;
public class HiddenChestManager implements Listener public class HiddenChestManager implements Listener
{ {
private final ClansManager _clansManager; private final ClansManager _clansManager;
public HiddenChestManager(ClansManager clansManager, PacketHandler packetHandler) private final Map<Player, BlockPosition> _openChest;
private PacketPlayOutBlockAction _lastPacket;
public HiddenChestManager(ClansManager clansManager)
{ {
this._clansManager = clansManager; _clansManager = clansManager;
_openChest = new HashMap<>();
clansManager.getPacketHandler().addPacketHandler(packetInfo ->
{
PacketPlayOutBlockAction packet = (PacketPlayOutBlockAction) packetInfo.getPacket();
if (packet.equals(_lastPacket))
{
packetInfo.getPlayer().sendMessage("Already modified");
return;
}
packetInfo.getPlayer().sendMessage("b= " + packet.b + " c=" + packet.c);
// b - Action Id
// c - Action Param - How many people have the chest open
// a - Block Position
if (packet.b == 1 && packet.c > 0 && _openChest.containsValue(packet.a))
{
packetInfo.getPlayer().sendMessage("Removed viewer");
packet.c--;
_lastPacket = packet;
}
}, PacketPlayOutBlockAction.class);
UtilServer.RegisterEvents(this); UtilServer.RegisterEvents(this);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) public void onInteract(PlayerInteractEvent event)
{ {
if (!_clansManager.getIncognitoManager().Get(event.getPlayer()).Status) Player player = event.getPlayer();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !_clansManager.getIncognitoManager().Get(player).Status)
{ {
return; return;
} }
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) Block block = event.getClickedBlock();
{ Material type = block.getType();
return;
}
if (event.getClickedBlock() == null)
{
return;
}
Material type = event.getClickedBlock().getType();
if (type != Material.CHEST && type != Material.TRAPPED_CHEST) if (type != Material.CHEST && type != Material.TRAPPED_CHEST)
{ {
return; return;
} }
Chest chest = (Chest) event.getClickedBlock().getState(); Location location = event.getClickedBlock().getLocation();
event.getPlayer().openInventory(new CraftInventory(new InventoryWrapper(chest.getInventory()))); player.sendMessage("Opening silently...");
event.setCancelled(true); _openChest.put(player, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
//fixme opened chest has name "container.chest" and that looks bad }
@EventHandler
public void handleClose(InventoryCloseEvent event)
{
if (_openChest.remove(event.getPlayer()) != null)
{
event.getPlayer().sendMessage("Removed");
}
}
@EventHandler
public void handleClose(PlayerQuitEvent event)
{
if (_openChest.remove(event.getPlayer()) != null)
{
event.getPlayer().sendMessage("Removed");
}
} }
} }

View File

@ -73,6 +73,8 @@ public class Spawn extends MiniPlugin
_spawns = new WeightSet<Location>(getNorthSpawn(), getSouthSpawn()); _spawns = new WeightSet<Location>(getNorthSpawn(), getSouthSpawn());
_shops = new WeightSet<Location>(getEastTown(), getWestTown()); _shops = new WeightSet<Location>(getEastTown(), getWestTown());
_clansManager = clansManager; _clansManager = clansManager;
getSpawnWorld().setGameRuleValue("doDaylightCycle", "true");
} }
/** /**

View File

@ -91,8 +91,12 @@ public class BarbedArrows extends Skill
if (damageePlayer != null) if (damageePlayer != null)
{ {
int food = damageePlayer.getFoodLevel();
damageePlayer.setFoodLevel(2); damageePlayer.setFoodLevel(2);
damageePlayer.setSprinting(false); damageePlayer.setSprinting(false);
Factory.runSyncLater(() -> damageePlayer.setFoodLevel(food), duration * 20);
} }
} }