add world rollback and other stuff

This commit is contained in:
Tyler Murphy 2021-08-27 17:20:07 -04:00
parent 4995dc3544
commit 0154a34f1d
14 changed files with 353 additions and 222 deletions

View file

@ -31,6 +31,7 @@ public class CommandHandler {
registerCommand(new SetSpawnLocation());
registerCommand(new SetBorder());
registerCommand(new Reload());
registerCommand(new SaveMap());
}
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {

View file

@ -19,7 +19,7 @@ public class CommandTabCompleter{
if(args.length - 2 < usage.length) {
String parameter = usage[args.length-2];
if(parameter.equals("<player>")) {
return null;//playerList.values().stream().map(p -> p.getName()).collect(Collectors.toList());
return null;
} else {
List<String> temp = new ArrayList<String>();
temp.add(parameter.replace("<", "").replace(">", ""));

View file

@ -2,6 +2,7 @@ package net.tylermurphy.hideAndSeek;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.io.File;
import java.util.List;
import org.bukkit.Bukkit;
@ -18,6 +19,7 @@ import net.tylermurphy.hideAndSeek.events.EventTick;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
public static File root;
public void onEnable() {
@ -35,6 +37,9 @@ public class Main extends JavaPlugin implements Listener {
// Register Commands
CommandHandler.registerCommands();
// Get Data Folder
root = this.getServer().getWorldContainer();
// Start Tick Timer
Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){
public void run(){

View file

@ -33,8 +33,9 @@ public class Store {
worldborderPrefix,
abortPrefix,
gameoverPrefix,
warningPrefix,
spawnWorld,
status = "Setup",
status = "Standby",
tauntPlayer = "";
public static Vector
@ -88,13 +89,14 @@ public class Store {
getConfig().addDefault("worldBorder.delay", 10);
getConfig().addDefault("worldBorder.size", 500);
getConfig().addDefault("worldBorder.enabled", false);
getConfig().addDefault("blockedCommands", Arrays.asList("tp","kill","gamemode","effect","clear"));
getConfig().addDefault("blockedCommands", Arrays.asList("whisper","msg"));
getConfig().addDefault("prefix.default", "&9Hide and Seek > &f");
getConfig().addDefault("prefix.error", "&cError > &f");
getConfig().addDefault("prefix.taunt", "&eTaunt > &f");
getConfig().addDefault("prefix.border", "&cWorld Border > &f");
getConfig().addDefault("prefix.abort", "&cAbort > &f");
getConfig().addDefault("prefix.gameover", "&aGame Over > &f");
getConfig().addDefault("prefix.warning", "&cWarning > &f");
getConfig().addDefault("nametagsVisible", false);
getConfig().addDefault("permissionsRequired", true);
getConfig().addDefault("blockSettings.unbreakable.painting", false);
@ -136,6 +138,7 @@ public class Store {
worldborderPrefix = getConfig().getString("prefix.border").replace("&", SYMBOLE_STRING);
abortPrefix = getConfig().getString("prefix.abort").replace("&", SYMBOLE_STRING);
gameoverPrefix = getConfig().getString("prefix.gameover").replace("&", SYMBOLE_STRING);
warningPrefix = getConfig().getString("prefix.warning").replace("&", SYMBOLE_STRING);
//Other
nametagsVisible = getConfig().getBoolean("nametagsVisible");
@ -153,12 +156,6 @@ public class Store {
getConfig().options().copyDefaults(true);
saveConfig();
if(spawnPosition.getBlockX() != 0 || spawnPosition.getBlockY() != 0 || spawnPosition.getBlockZ() != 0) {
if(status.equals("Setup")) {
status = "Standby";
}
}
}
public static void addToSection(String sectionName, Map<String,Object> values) {

View file

@ -0,0 +1,59 @@
package net.tylermurphy.hideAndSeek.commands;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
public class SaveMap implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
sender.sendMessage(errorPrefix + "Please set spawn location first");
return;
}
sender.sendMessage(warningPrefix + "This command may lag the server");
Bukkit.getServer().getWorld(spawnWorld).save();
File current = new File(Main.root+File.separator+spawnWorld);
if(current.exists()) {
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(destenation.exists()) {
deleteDirectory(destenation);
destenation.mkdir();
}
Functions.copyFileStructure(current, destenation);
sender.sendMessage(messagePrefix + "Map save complete");
} else {
sender.sendMessage(errorPrefix + "Coudnt find current map");
}
}
boolean deleteDirectory(File directoryToBeDeleted) {
File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) {
for (File file : allContents) {
deleteDirectory(file);
}
}
return directoryToBeDeleted.delete();
}
public String getLabel() {
return "saveMap";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Saves current map for the game. May lag server.";
}
}

View file

@ -15,7 +15,7 @@ import net.tylermurphy.hideAndSeek.util.ICommand;
public class SetBorder implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(!status.equals("Standby") && !status.equals("Setup")) {
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}

View file

@ -19,12 +19,15 @@ public class SetSpawnLocation implements ICommand {
newSpawnPosition.setX(player.getLocation().getBlockX());
newSpawnPosition.setY(player.getLocation().getBlockY());
newSpawnPosition.setZ(player.getLocation().getBlockZ());
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is currently in session");
return;
}
if(worldborderEnabled && spawnPosition.distance(worldborderPosition) > 100) {
sender.sendMessage(errorPrefix + "Spawn position must be 100 from worldborder center");
return;
}
spawnPosition = newSpawnPosition;
status = "Standby";
sender.sendMessage(messagePrefix + "Set spawn position to current location");
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", spawnPosition.getX());

View file

@ -1,7 +1,7 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
@ -15,24 +15,35 @@ import net.tylermurphy.hideAndSeek.util.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.io.File;
import java.util.Random;
public class Start implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(status.equals("Setup")) {
sender.sendMessage(errorPrefix + "Please set spawn location first");
return;
}
if(!status.equals("Standby")) {
sender.sendMessage(errorPrefix + "Game is already in session");
return;
}
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
sender.sendMessage(errorPrefix + "Please set spawn location first");
return;
}
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(!destenation.exists()) {
sender.sendMessage(errorPrefix + "Please set map save first");
return;
} else {
if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) {
Functions.rollback("hideandseek_"+spawnWorld);
} else {
Functions.loadMap("hideandseek_"+spawnWorld);
}
}
if(playerList.size() < minPlayers) {
sender.sendMessage(errorPrefix + "You must have at least "+minPlayers+" players to start");
return;
}
String seekerName;
if(args.length < 1) {
seekerName = playerList.values().stream().skip(new Random().nextInt(playerList.values().size())).findFirst().get().getName();
@ -52,7 +63,7 @@ public class Start implements ICommand {
for(Player player : playerList.values()) {
player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
@ -130,9 +141,69 @@ public class Start implements ICommand {
}, 20 * 30);
if(worldborderEnabled) {
Functions.scheduleWorldborder();
scheduleWorldborder();
}
Functions.scheduleTaunt();
scheduleTaunt();
}
private static void scheduleTaunt() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
if(tauntPlayer != null && !tauntPlayer.equals("")) {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
if(gameId != temp) break;
continue;
}
try { Thread.sleep(1000*60); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(Math.random() > .8) {
Player taunted = null;
int rand = (int) (Math.random()*Hider.getEntries().size());
for(Player player : playerList.values()) {
if(Hider.hasEntry(player.getName())) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Bukkit.getServer().broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
try { Thread.sleep(1000*30); } catch (InterruptedException e) {}
if(gameId != temp) break;
tauntPlayer = taunted.getName();
}
}
}
}
});
}
private static void scheduleWorldborder() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(currentWorldborderSize-100 > 100) {
Bukkit.getServer().broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
decreaseBorder = true;
} else {
break;
}
}
}
});
}
public String getLabel() {

View file

@ -12,6 +12,7 @@ import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.ICommand;
import net.tylermurphy.hideAndSeek.util.Packet;
public class Stop implements ICommand {
@ -31,7 +32,7 @@ public class Stop implements ICommand {
}
public static void onStop() {
if(status.equals("Standby") || status.equals("Setup")) return;
if(status.equals("Standby")) return;
status = "Standby";
gameId++;
for(Player player : playerList.values()) {
@ -44,7 +45,7 @@ public class Stop implements ICommand {
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(Player temp : playerList.values()) {
Functions.setGlow(player, temp, false);
Packet.setGlow(player, temp, false);
}
}
Functions.resetWorldborder();

View file

@ -32,6 +32,7 @@ import org.bukkit.potion.PotionEffect;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Packet;
public class EventListener implements Listener {
@ -45,9 +46,10 @@ public class EventListener implements Listener {
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
event.getPlayer().teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
} else if(status.equals("Setup") || status.equals("Standby")) {
Hider.addEntry(event.getPlayer().getName());
event.getPlayer().teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
playerList.put(event.getPlayer().getName(), event.getPlayer());
}
@ -72,8 +74,8 @@ public class EventListener implements Listener {
if(spawnPosition == null) return;
event.setCancelled(true);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Functions.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
if(Hider.hasEntry(event.getEntity().getName())) {
Bukkit.broadcastMessage(String.format(messagePrefix + "%s%s%s has died and became a seeker", ChatColor.GOLD, event.getEntity().getName(), ChatColor.WHITE));
}
@ -82,6 +84,9 @@ public class EventListener implements Listener {
}
Seeker.addEntry(player.getName());
Functions.resetPlayer(player);
for(Player temp : playerList.values()) {
Packet.setGlow(player, temp, false);
}
}
}

View file

@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
@ -13,11 +14,13 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import net.tylermurphy.hideAndSeek.commands.Stop;
import net.tylermurphy.hideAndSeek.util.Functions;
import net.tylermurphy.hideAndSeek.util.Packet;
public class EventTick {
@ -26,10 +29,53 @@ public class EventTick {
public static void onTick() {
if(board == null) {
Functions.loadScoreboard();
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard mainBoard = manager.getMainScoreboard();
try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {}
Seeker = mainBoard.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
if(nametagsVisible)
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS);
else
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {}
Hider = mainBoard.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
if(nametagsVisible)
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
else
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {}
Spectator = mainBoard.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
board = mainBoard;
}
Functions.emptyOfflinePlayers();
for(String entry : Hider.getEntries()) {
if(!playerList.containsKey(entry)) {
Hider.removeEntry(entry);
}
}
for(String entry : Seeker.getEntries()) {
if(!playerList.containsKey(entry)) {
Seeker.removeEntry(entry);
}
}
for(String entry : Spectator.getEntries()) {
if(!playerList.containsKey(entry)) {
Spectator.removeEntry(entry);
}
}
if(status.equals("Starting")) {
onStarting();
@ -53,7 +99,7 @@ public class EventTick {
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.teleport(new Location(Bukkit.getWorld(spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
}
}
@ -86,26 +132,8 @@ public class EventTick {
}
tauntPlayer = "";
}
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
}
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false));
}
for(Player temp : playerList.values()) {
Functions.setGlow(player, temp, false);
}
}
for(String playerName : Hider.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
int distance = 100;
for(String seekerName : Seeker.getEntries()) {
Player seeker = playerList.get(seekerName);
@ -114,25 +142,25 @@ public class EventTick {
distance = temp;
}
if(glowTime > 0) {
Functions.setGlow(player, seeker, true);
Packet.setGlow(player, seeker, true);
} else {
Functions.setGlow(player, seeker, false);
Packet.setGlow(player, seeker, false);
}
}
switch(tick%10) {
case 0:
if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 3:
if(distance < 30) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 30) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 6:
if(distance < 10) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 10) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 9:
if(distance < 20) Functions.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
if(distance < 20) Packet.playSound(player, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
}
}

View file

@ -2,16 +2,21 @@ package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.lang.reflect.InvocationTargetException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -19,32 +24,19 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import net.tylermurphy.hideAndSeek.Main;
public class Functions {
private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
public static void resetPlayer(Player player) {
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
if(Seeker.getEntries().contains(player.getName())){
ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1);
diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
@ -60,6 +52,11 @@ public class Functions {
wackyStickMeta.setDisplayName("Wacky Stick");
wackyStick.setItemMeta(wackyStickMeta);
player.getInventory().addItem(wackyStick);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1000000, 2, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 1000000, 1, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 10, false, false));
}
else if(Hider.getEntries().contains(player.getName())){
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1);
@ -92,156 +89,11 @@ public class Functions {
snowballMeta.setLore(snowballLore);
snowball.setItemMeta(snowballMeta);
player.getInventory().addItem(snowball);
}
}
public static void emptyOfflinePlayers() {
for(String entry : Hider.getEntries()) {
if(!playerList.containsKey(entry)) {
Hider.removeEntry(entry);
player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 1, false, false));
}
}
for(String entry : Seeker.getEntries()) {
if(!playerList.containsKey(entry)) {
Seeker.removeEntry(entry);
}
}
for(String entry : Spectator.getEntries()) {
if(!playerList.containsKey(entry)) {
Spectator.removeEntry(entry);
}
}
}
public static void loadScoreboard() {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard mainBoard = manager.getMainScoreboard();
try { mainBoard.registerNewTeam("Seeker");} catch(Exception e) {}
Seeker = mainBoard.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
if(nametagsVisible)
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS);
else
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Hider");} catch(Exception e) {}
Hider = mainBoard.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
if(nametagsVisible)
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
else
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
try { mainBoard.registerNewTeam("Spectator");} catch(Exception e) {}
Spectator = mainBoard.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
board = mainBoard;
}
public static void playSound(Player player, Sound sound, float volume, float pitch) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT);
packet.getSoundCategories().write(0, SoundCategory.MASTER);
packet.getSoundEffects().write(0, sound);
packet.getIntegers().write(0, (int)(player.getLocation().getX() * 8.0));
packet.getIntegers().write(1, (int)(player.getLocation().getY() * 8.0));
packet.getIntegers().write(2, (int)(player.getLocation().getZ() * 8.0));
packet.getFloat().write(0, volume);
packet.getFloat().write(1, pitch);
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void setGlow(Player player, Player target, boolean glowing) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, target.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher();
Serializer serializer = Registry.get(Byte.class);
watcher.setEntity(target);
if(glowing) {
watcher.setObject(0, serializer, (byte) (0x40));
} else {
watcher.setObject(0, serializer, (byte) (0x0));
}
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void scheduleTaunt() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
if(tauntPlayer != null && !tauntPlayer.equals("")) {
try { Thread.sleep(1000); } catch (InterruptedException e) {}
if(gameId != temp) break;
continue;
}
try { Thread.sleep(1000*60); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(Math.random() > .8) {
Player taunted = null;
int rand = (int) (Math.random()*Hider.getEntries().size());
for(Player player : playerList.values()) {
if(Hider.hasEntry(player.getName())) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
taunted.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Oh no! You have been chosed to be taunted.");
Bukkit.getServer().broadcastMessage(tauntPrefix + " A random hider will be taunted in the next 30s");
try { Thread.sleep(1000*30); } catch (InterruptedException e) {}
if(gameId != temp) break;
tauntPlayer = taunted.getName();
}
}
}
}
});
}
public static void scheduleWorldborder() {
Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
while(true) {
try { Thread.sleep(1000*60*worldborderDelay); } catch (InterruptedException e) {}
if(gameId != temp) break;
if(currentWorldborderSize-100 > 100) {
Bukkit.getServer().broadcastMessage(worldborderPrefix + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
decreaseBorder = true;
} else {
break;
}
}
}
});
}
public static void resetWorldborder() {
if(worldborderEnabled) {
World world = Bukkit.getWorld("world");
@ -257,4 +109,52 @@ public class Functions {
}
}
public static void copyFileStructure(File source, File target){
try {
ArrayList<String> ignore = new ArrayList<>(Arrays.asList("uid.dat", "session.lock"));
if(!ignore.contains(source.getName())) {
if(source.isDirectory()) {
if(!target.exists())
if (!target.mkdirs())
throw new IOException("Couldn't create world directory!");
String files[] = source.list();
for (String file : files) {
File srcFile = new File(source, file);
File destFile = new File(target, file);
copyFileStructure(srcFile, destFile);
}
} else {
InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(target);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0)
out.write(buffer, 0, length);
in.close();
out.close();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void unloadMap(String mapname){
if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){
Main.plugin.getLogger().info("Successfully unloaded " + mapname);
}else{
Main.plugin.getLogger().severe("COULD NOT UNLOAD " + mapname);
}
}
public static void loadMap(String mapname){
Bukkit.getServer().createWorld(new WorldCreator(mapname));
Bukkit.getServer().getWorld("hideandseek_"+spawnWorld).setAutoSave(false);
}
public static void rollback(String mapname){
unloadMap(mapname);
loadMap(mapname);
}
}

View file

@ -0,0 +1,56 @@
package net.tylermurphy.hideAndSeek.util;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.EnumWrappers.SoundCategory;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
public class Packet {
private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
public static void playSound(Player player, Sound sound, float volume, float pitch) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT);
packet.getSoundCategories().write(0, SoundCategory.MASTER);
packet.getSoundEffects().write(0, sound);
packet.getIntegers().write(0, (int)(player.getLocation().getX() * 8.0));
packet.getIntegers().write(1, (int)(player.getLocation().getY() * 8.0));
packet.getIntegers().write(2, (int)(player.getLocation().getZ() * 8.0));
packet.getFloat().write(0, volume);
packet.getFloat().write(1, pitch);
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public static void setGlow(Player player, Player target, boolean glowing) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, target.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher();
Serializer serializer = Registry.get(Byte.class);
watcher.setEntity(target);
if(glowing) {
watcher.setObject(0, serializer, (byte) (0x40));
} else {
watcher.setObject(0, serializer, (byte) (0x0));
}
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

View file

@ -21,6 +21,8 @@ permissions:
hideandseek.setspawn: true
hideandseek.start: true
hideandseek.stop: true
hideandseek.savemap: true
hideandseek.blockbypass: true
hideandseek.about:
description: Allows you to run the about command
default: true
@ -42,6 +44,9 @@ permissions:
hideandseek.stop:
description: Allows you to stop the game
default: op
hideandseek.savemap:
description: Allows you to set the current game map
default: op
hideandseek.blockbypass:
description: Allows you to bypass the block break prevention
default: op