Merge pull request #2 from selfslaughter/dev

Merge Dev Branch
This commit is contained in:
self_slaughter 2020-06-06 15:13:05 +10:00 committed by GitHub
commit 2abb826dd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 71 deletions

View File

@ -110,6 +110,7 @@ public class BlockHunt extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(new OnFoodLevelChangeEvent(), this);
getServer().getPluginManager().registerEvents(new OnInventoryClickEvent(), this);
getServer().getPluginManager().registerEvents(new OnInventoryCloseEvent(), this);
getServer().getPluginManager().registerEvents(new OnPlayerSwapHandItemsEvent(), this);
// Removed - This is handled by WorldGuard now.
// getServer().getPluginManager().registerEvents(

View File

@ -91,71 +91,75 @@ public class OnEntityDamageByEntityEvent implements Listener {
player.setHealth(20);
event.setCancelled(true);
DisguiseAPI.undisguiseToAll(player);
MemoryStorage.pBlock.remove(player);
if (!arena.seekers.contains(player)) {
if (MemoryStorage.shop.getFile().get(damager.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(damager.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int damagerTokens = MemoryStorage.shop.getFile().getInt(damager.getName() + ".tokens");
MemoryStorage.shop.getFile().set(damager.getName() + ".tokens", damagerTokens + arena.killTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(damager, ConfigC.normal_addedToken, "amount-" + arena.killTokens);
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
float addingTokens = ((float) arena.hidersTokenWin - (((float) arena.timer / (float) arena.gameTime) * (float) arena.hidersTokenWin));
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens + (int) addingTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + (int) addingTokens);
arena.seekers.add(player);
player.setWalkSpeed(0.3F);
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHiderDied, "playername-" + player.getDisplayName(), "killer-" + damager.getDisplayName());
int hidercount = (arena.playersInArena.size() - arena.seekers.size());
if ((hidercount <= 3) && (hidercount > 0)) {
List<String> hiders = new ArrayList<>();
for (Player p : arena.playersInArena) {
if (!arena.seekers.contains(p)) {
hiders.add(p.getName());
}
}
Collections.sort(hiders);
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHidersLeft, "left-" + StringUtils.join(hiders.toArray(), ", "));
} else {
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHidersLeft, "left-" + hidercount);
}
}
player.getInventory().clear();
player.updateInventory();
if (arena.seekers.size() >= arena.playersInArena.size()) {
ArenaHandler.seekersWin(arena);
} else {
// try moving everything to the next tick to prevent "Removing entity while ticking" errors
Player finalDamager = damager;
player.getServer().getScheduler().runTask(BlockHunt.plugin, () -> {
DisguiseAPI.undisguiseToAll(player);
MemoryStorage.seekertime.put(player, arena.waitingTimeSeeker);
PlayerHandler.teleport(player, arena.seekersWarp);
player.setGameMode(GameMode.SURVIVAL);
player.setWalkSpeed(0.3F);
MemoryStorage.pBlock.remove(player);
// Fix for client not showing players after they join
for (Player otherplayer : arena.playersInArena) {
if (otherplayer.canSee(player))
otherplayer.showPlayer(BlockHunt.plugin, player); // Make new player visible to others
if (player.canSee(otherplayer))
player.showPlayer(BlockHunt.plugin, otherplayer); // Make other players visible to new player
if (!arena.seekers.contains(player)) {
if (MemoryStorage.shop.getFile().get(finalDamager.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(finalDamager.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int damagerTokens = MemoryStorage.shop.getFile().getInt(finalDamager.getName() + ".tokens");
MemoryStorage.shop.getFile().set(finalDamager.getName() + ".tokens", damagerTokens + arena.killTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(finalDamager, ConfigC.normal_addedToken, "amount-" + arena.killTokens);
if (MemoryStorage.shop.getFile().get(player.getName() + ".tokens") == null) {
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", 0);
MemoryStorage.shop.save();
}
int playerTokens = MemoryStorage.shop.getFile().getInt(player.getName() + ".tokens");
float addingTokens = ((float) arena.hidersTokenWin - (((float) arena.timer / (float) arena.gameTime) * (float) arena.hidersTokenWin));
MemoryStorage.shop.getFile().set(player.getName() + ".tokens", playerTokens + (int) addingTokens);
MemoryStorage.shop.save();
MessageManager.sendFMessage(player, ConfigC.normal_addedToken, "amount-" + (int) addingTokens);
arena.seekers.add(player);
player.setWalkSpeed(0.3F);
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHiderDied, "playername-" + player.getDisplayName(), "killer-" + finalDamager.getDisplayName());
int hidercount = (arena.playersInArena.size() - arena.seekers.size());
if ((hidercount <= 3) && (hidercount > 0)) {
List<String> hiders = new ArrayList<>();
for (Player p : arena.playersInArena) {
if (!arena.seekers.contains(p)) {
hiders.add(p.getName());
}
}
Collections.sort(hiders);
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHidersLeft, "left-" + StringUtils.join(hiders.toArray(), ", "));
} else {
ArenaHandler.sendFMessage(arena, ConfigC.normal_ingameHidersLeft, "left-" + hidercount);
}
}
}
player.getInventory().clear();
player.updateInventory();
if (arena.seekers.size() >= arena.playersInArena.size()) {
ArenaHandler.seekersWin(arena);
} else {
DisguiseAPI.undisguiseToAll(player);
MemoryStorage.seekertime.put(player, arena.waitingTimeSeeker);
PlayerHandler.teleport(player, arena.seekersWarp);
player.setGameMode(GameMode.SURVIVAL);
player.setWalkSpeed(0.3F);
// Fix for client not showing players after they join
for (Player otherplayer : arena.playersInArena) {
if (otherplayer.canSee(player))
otherplayer.showPlayer(BlockHunt.plugin, player); // Make new player visible to others
if (player.canSee(otherplayer))
player.showPlayer(BlockHunt.plugin, otherplayer); // Make other players visible to new player
}
}
});
}
}
}

View File

@ -25,10 +25,8 @@ public class OnInventoryClickEvent implements Listener {
Player player = (Player) event.getWhoClicked();
for (Arena arena : MemoryStorage.arenaList) {
if (arena.playersInArena.contains(player) && !arena.seekers.contains(player)) {
if (event.getSlot() == 8 || event.getSlot() == 39) {
event.setCancelled(true);
}
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
}
}

View File

@ -24,9 +24,9 @@ public class OnPlayerQuitEvent implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player playerJoining = event.getPlayer();
playerJoining.teleport(playerJoining.getWorld().getSpawnLocation());
}
// @EventHandler(priority = EventPriority.HIGHEST)
// public void onPlayerJoinEvent(PlayerJoinEvent event) {
// Player playerJoining = event.getPlayer();
// playerJoining.teleport(playerJoining.getWorld().getSpawnLocation());
// }
}

View File

@ -0,0 +1,25 @@
package nl.Steffion.BlockHunt.Listeners;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.MemoryStorage;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
public class OnPlayerSwapHandItemsEvent implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) {
// Early exit if no one is in any arena
if (ArenaHandler.noPlayersInArenas()) return;
Player player = event.getPlayer();
for (Arena arena : MemoryStorage.arenaList) {
if (arena.playersInArena.contains(player)) {
event.setCancelled(true);
}
}
}
}