This commit is contained in:
Tyler Murphy 2021-08-13 16:49:36 -04:00
commit 173d4b0e6a
22 changed files with 1362 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
project
.classpath
.settings/
bin/
target/
.git/

23
.project Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hideandseek-plugin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

201
LICENSE Normal file
View file

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

34
pom.xml Normal file
View file

@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId>
<artifactId>HideAndSeek</artifactId>
<version>1.0.0</version>
<name>Hide and Seek Plugin</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,15 @@
package net.tylermurphy.hideAndSeek;
import org.bukkit.command.CommandSender;
public interface ICommand {
public void execute(CommandSender sender, String[] args);
public String getLabel();
public String getUsage();
public String getDescription();
}

View file

@ -0,0 +1,79 @@
package net.tylermurphy.hideAndSeek;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.manager.BoardManager;
import net.tylermurphy.hideAndSeek.manager.CommandManager;
import net.tylermurphy.hideAndSeek.manager.EventManager;
import net.tylermurphy.hideAndSeek.manager.TickManager;
public class Main extends JavaPlugin implements Listener {
public static Main plugin;
private int tickTaskId;
public void onEnable() {
plugin = this;
// Setup Initial Player Count
getServer().getPluginManager().registerEvents(new EventManager(), this);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
playerList.put(player.getName(), player);
}
// Init Configuration
Vector spawnPositionVector = getConfig().getVector("spawnPosition");
if(spawnPositionVector != null) {
spawnPosition = spawnPositionVector;
status = "Standby";
}
Vector worldborderPositionVector = getConfig().getVector("borderPosition");
if(worldborderPositionVector != null) {
worldborderPosition = worldborderPositionVector;
worldborderSize = getConfig().getInt("borderSize");
worldborderDelay = getConfig().getInt("borderDelay");
}
worldborderEnabled = getConfig().getBoolean("borderEnabled");
// Init Gamerules
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule sendCommandFeedback false");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule doImmediateRespawn true");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "gamerule logAdminCommands false");
// Register Commands
CommandManager.registerCommands();
// Init Scoreboard
if(Bukkit.getScoreboardManager() != null) {
BoardManager.loadScoreboard();
}
// Start Tick Timer
tickTaskId = Bukkit.getServer().getScheduler().runTaskTimer(this, new Runnable(){
public void run(){
TickManager.onTick();
}
},0,1).getTaskId();
}
public void onDisable() {
Bukkit.getServer().getScheduler().cancelTask(tickTaskId);
saveConfig();
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return CommandManager.handleCommand(sender, cmd, label, args);
}
}

View file

@ -0,0 +1,70 @@
package net.tylermurphy.hideAndSeek;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.Vector;
import net.md_5.bungee.api.ChatColor;
public class Store {
public static Map<String,Player> playerList = new HashMap<String,Player>();
public static List<String> loadedPlayers = new ArrayList<String>();
public static Scoreboard board;
public static Team Hider,Seeker,Spectator;
public static String status = "Setup";
public static String messagePrefix = String.format("%sHide and Seek > %s", ChatColor.BLUE, ChatColor.WHITE);
public static String errorPrefix = String.format("%sError > %s", ChatColor.RED, ChatColor.WHITE);
public static Vector spawnPosition,worldborderPosition;
public static int worldborderSize,worldborderDelay,currentWorldborderSize;
public static boolean worldborderEnabled = false, decreaseBorder = false;
public static String tauntPlayer = "";
public static HashMap<String,HashMap<String,Integer>> playerData = new HashMap<String,HashMap<String,Integer>>();
public static int startTaskId;
public static int gameId = 0;
public static FileConfiguration getConfig() {
return Main.plugin.getConfig();
}
public static void saveConfig() {
Main.plugin.saveConfig();
}
public static int getPlayerData(String playerName, String key) {
HashMap<String,Integer> data = playerData.get(playerName);
if(data == null) {
data = new HashMap<String,Integer>();
playerData.put(playerName, data);
return 0;
}
if(data.get(key) == null) {
data.put(key, 0);
return 0;
}
return data.get(key);
}
public static void setPlayerData(String playerName, String key, int value) {
HashMap<String,Integer> data = playerData.get(playerName);
if(data == null) {
data = new HashMap<String,Integer>();
}
data.put(key, value);
playerData.put(playerName, data);
}
public static void resetPlayerData(String playerName, boolean giveItems) {
HashMap<String,Integer> data = new HashMap<String,Integer>();
data.put("Death", 0);
data.put("GiveStatus", (giveItems) ? 1 : 0);
playerData.put(playerName, data);
}
}

View file

@ -0,0 +1,30 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.ICommand;
public class About implements ICommand {
public void execute(CommandSender sender, String[] args) {
sender.sendMessage(
String.format("%s%sHide and Seek %s(1.0.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
);
}
public String getLabel() {
return "about";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Get information about the plugin";
}
}

View file

@ -0,0 +1,45 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager;
import static net.tylermurphy.hideAndSeek.Store.*;
public class EnableBorder implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(worldborderPosition == null) {
sender.sendMessage(errorPrefix + "Please setup worldborder info before enabling");
return;
}
boolean bool;
try { bool = Boolean.parseBoolean(args[0]); } catch (Exception e) {
sender.sendMessage(errorPrefix + "Please enter true or false");
return;
}
if(spawnPosition != null && worldborderPosition != null && spawnPosition.distance(worldborderPosition) > 100) {
sender.sendMessage(errorPrefix + "Cannot enable worldborder, spawn position is outside 100 blocks from worldborder");
return;
}
sender.sendMessage(messagePrefix + "Set worldborder to "+args[0]);
getConfig().set("borderEnabled", bool);
worldborderEnabled = bool;
saveConfig();
WorldborderManager.reset();
}
public String getLabel() {
return "enableBorder";
}
public String getUsage() {
return "<true/false>";
}
public String getDescription() {
return "Enables or disables worldborder";
}
}

View file

@ -0,0 +1,32 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.command.CommandSender;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.manager.CommandManager;
public class Help implements ICommand {
public void execute(CommandSender sender, String[] args) {
String message = "";
for(ICommand command : CommandManager.COMMAND_REGISTER.values()) {
message += String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription()+"\n");
}
message = message.substring(0, message.length()-2);
sender.sendMessage(message);
}
public String getLabel() {
return "help";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Get the commands for the plugin";
}
}

View file

@ -0,0 +1,68 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager;
import static net.tylermurphy.hideAndSeek.Store.*;
public class SetBorder implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(spawnPosition == null) {
sender.sendMessage(errorPrefix + "Please set spawn position first");
return;
}
if(args.length < 2) {
sender.sendMessage(errorPrefix + "Please enter worldborder size and delay");
return;
}
int num,delay;
try { num = Integer.parseInt(args[0]); } catch (Exception e) {
sender.sendMessage(errorPrefix + "Invalid integer: "+args[0]);
return;
}
try { delay = Integer.parseInt(args[1]); } catch (Exception e) {
sender.sendMessage(errorPrefix + "Invalid integer: "+args[1]);
return;
}
if(num < 100) {
sender.sendMessage(errorPrefix + "Worldborder cannot be smaller than 100 blocks.");
return;
}
Vector newWorldborderPosition = new Vector();
Player player = (Player) sender;
newWorldborderPosition.setX(player.getLocation().getBlockX());
newWorldborderPosition.setY(0);
newWorldborderPosition.setZ(player.getLocation().getBlockZ());
if(spawnPosition.distance(newWorldborderPosition) > 100) {
sender.sendMessage(errorPrefix + "Spawn position must be 100 from worldborder center");
return;
}
worldborderPosition = newWorldborderPosition;
worldborderSize = num;
worldborderDelay = delay;
sender.sendMessage(messagePrefix + "Set border center to current location, size to "+num+", and delay to "+delay);
getConfig().set("borderPosition", newWorldborderPosition);
getConfig().set("borderSize", num);
getConfig().set("borderDelay", delay);
saveConfig();
WorldborderManager.reset();
}
public String getLabel() {
return "setBorder";
}
public String getUsage() {
return "<size> <delay>";
}
public String getDescription() {
return "Sets worldboarder's center location, size in blocks, and delay in minutes";
}
}

View file

@ -0,0 +1,43 @@
package net.tylermurphy.hideAndSeek.commands;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.ICommand;
public class SetSeeker implements ICommand {
public void execute(CommandSender sender, String[] args) {
String playerName;
if(args.length < 1) {
playerName = sender.getName();
} else {
playerName = args[0];
}
Player player = playerList.get(playerName);
if(player == null) {
sender.sendMessage(errorPrefix + "Invalid player: " + playerName);
return;
}
for(Player temp : playerList.values()) {
Hider.addEntry(temp.getName());
}
Seeker.addEntry(player.getName());
sender.sendMessage(String.format("%s Set %s as the seaker.", messagePrefix, args[0]));
}
public String getLabel() {
return "setSeeker";
}
public String getUsage() {
return "<player>";
}
public String getDescription() {
return "Sets the current or select player as the seeker";
}
}

View file

@ -0,0 +1,45 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.ICommand;
import static net.tylermurphy.hideAndSeek.Store.*;
public class SetSpawnLocation implements ICommand {
public void execute(CommandSender sender, String[] args) {
Vector newSpawnPosition = new Vector();
Player player = (Player) sender;
newSpawnPosition.setX(player.getLocation().getBlockX());
newSpawnPosition.setY(player.getLocation().getBlockY());
newSpawnPosition.setZ(player.getLocation().getBlockZ());
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");
getConfig().set("spawnPosition", newSpawnPosition);
saveConfig();
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("setworldspawn %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("spawnpoint @a %s %s %s", player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
}
public String getLabel() {
return "setspawn";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Sets hide and seeks spawn location to current position";
}
}

View file

@ -0,0 +1,111 @@
package net.tylermurphy.hideAndSeek.commands;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.manager.TauntManager;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager;
import static net.tylermurphy.hideAndSeek.Store.*;
import java.util.HashMap;
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(Hider.getSize() < 1) {
sender.sendMessage(errorPrefix + "No Hiders were found");
return;
}
if(Seeker.getSize() < 1) {
sender.sendMessage(errorPrefix + "No Seekers were found");
return;
}
playerData = new HashMap<String,HashMap<String,Integer>>();
for(Player player : playerList.values()) {
resetPlayerData(player.getName(),true);
player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
}
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
}
}
for(String playerName : Hider.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
}
}
WorldborderManager.reset();
status = "Starting";
startTaskId = Bukkit.getServer().getScheduler().runTaskAsynchronously(Main.plugin, new Runnable(){
public void run() {
int temp = gameId;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 30 seconds to hide!");
try { Thread.sleep(10*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 20 seconds to hide!");
try { Thread.sleep(10*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 10 seconds to hide!");
try { Thread.sleep(5*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 5 seconds to hide!");
try { Thread.sleep(2*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 3 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 2 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Hiders have 1 seconds to hide!");
try { Thread.sleep(1*1000); } catch (InterruptedException e) {}
if(temp != gameId) return;
Bukkit.getServer().broadcastMessage(messagePrefix + "Attetion SEEKERS, its time to find the hiders!");
status = "Playing";
}
}).getTaskId();
if(worldborderEnabled) {
WorldborderManager.schedule();
}
TauntManager.schedule();
}
public String getLabel() {
return "start";
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Starts the game";
}
}

View file

@ -0,0 +1,63 @@
package net.tylermurphy.hideAndSeek.commands;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.manager.WorldborderManager;
public class Stop implements ICommand {
public void execute(CommandSender sender, String[] args) {
if(status.equals("Starting") || status.equals("Playing")) {
onStop(true);
} else {
sender.sendMessage(errorPrefix + "There is no game in progress");
return;
}
}
public String getLabel() {
return "stop";
}
public static void onStop(boolean forced) {
if(status.equals("Standby")) return;
if(forced) {
Bukkit.broadcastMessage(messagePrefix + "Game has been force stopped.");
} else {
Bukkit.broadcastMessage(messagePrefix + "Game over! All hiders have been found.");
}
status = "Standby";
Bukkit.getServer().getScheduler().cancelTask(startTaskId);
for(Player player : playerList.values()) {
player.setGameMode(GameMode.ADVENTURE);
Hider.addEntry(player.getName());
player.getInventory().clear();
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
}
WorldborderManager.reset();
gameId++;
}
public String getUsage() {
return "";
}
public String getDescription() {
return "Stops the game";
}
}

View file

@ -0,0 +1,40 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
public class BoardManager {
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);
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);
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;
}
}

View file

@ -0,0 +1,60 @@
package net.tylermurphy.hideAndSeek.manager;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.ICommand;
import net.tylermurphy.hideAndSeek.commands.*;
import static net.tylermurphy.hideAndSeek.Store.*;
public class CommandManager implements CommandExecutor {
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>();
private static void registerCommand(ICommand command) {
if(!COMMAND_REGISTER.containsKey(command.getLabel())) {
COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command);
}
}
public static void registerCommands() {
registerCommand(new About());
registerCommand(new Help());
registerCommand(new Start());
registerCommand(new Stop());
registerCommand(new SetSeeker());
registerCommand(new SetSpawnLocation());
registerCommand(new SetBorder());
registerCommand(new EnableBorder());
}
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player == false) {
sender.sendMessage(errorPrefix + "This command can only be run as a player.");
} else if(args.length < 1) {
COMMAND_REGISTER.get("about").execute(sender, new String[0]);
} else if(!COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
COMMAND_REGISTER.get("about").execute(sender, Arrays.copyOfRange(args, 1, args.length));
} else {
try {
COMMAND_REGISTER.get(args[0].toLowerCase()).execute(sender,Arrays.copyOfRange(args, 1, args.length));
} catch (Exception e) {
sender.sendMessage(errorPrefix + "An error has occured.");
e.printStackTrace();
}
}
return true;
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return CommandManager.handleCommand(sender, command, label, args);
}
}

View file

@ -0,0 +1,49 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.potion.PotionEffect;
public class EventManager implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if(status.equals("Playing") || status.equals("Starting")) {
Spectator.addEntry(event.getPlayer().getName());
resetPlayerData(event.getPlayer().getName(), false);
event.getPlayer().sendMessage(messagePrefix + "You have joined mid game, and thus have been placed on the spectator team.");
event.getPlayer().setGameMode(GameMode.SPECTATOR);
event.getPlayer().getInventory().clear();
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
event.getPlayer().teleport(new Location(event.getPlayer().getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
playerList.put(event.getPlayer().getName(), event.getPlayer());
if(board == null) BoardManager.loadScoreboard();
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
playerList.remove(event.getPlayer().getName());
Hider.removeEntry(event.getPlayer().getName());
Seeker.removeEntry(event.getPlayer().getName());
Spectator.removeEntry(event.getPlayer().getName());
}
@EventHandler
public void onDeath(PlayerDeathEvent event) {
if(status.equals("Playing")) {
setPlayerData(event.getEntity().getName(), "Death", 1);
setPlayerData(event.getEntity().getName(), "GiveStatus", 1);
}
}
}

View file

@ -0,0 +1,52 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
public class TauntManager {
public static void schedule() {
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() > .9) {
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(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " 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();
}
}
}
}
});
}
}

View file

@ -0,0 +1,241 @@
package net.tylermurphy.hideAndSeek.manager;
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;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
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.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import net.tylermurphy.hideAndSeek.commands.Stop;
public class TickManager {
static int tick = 0;
public static void onTick() {
if(board == null) return;
checkTeams();
if(status.equals("Standby") || status.equals("Setup")) {
onStandby();
} else if(status.equals("Starting")) {
onStarting();
} else if(status.equals("Playing")) {
onPlaying();
}
tick ++;
tick %= 10;
if(Hider.getSize() < 1) {
Stop.onStop(false);
}
if(Seeker.getSize() < 1) {
Stop.onStop(false);
}
}
private static void checkTeams() {
try { Hider.getSize(); }
catch (Exception e) {
board.registerNewTeam("Hider");
Hider = board.getTeam("Hider");
Hider.setColor(ChatColor.GOLD);
Hider.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Hider.setAllowFriendlyFire(false);
}
try { Seeker.getSize(); }
catch (Exception e) {
board.registerNewTeam("Seeker");
Seeker = board.getTeam("Seeker");
Seeker.setColor(ChatColor.RED);
Seeker.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Seeker.setAllowFriendlyFire(false);
}
try { Spectator.getSize(); }
catch (Exception e) {
board.registerNewTeam("Spectator");
Spectator = board.getTeam("Spectator");
Spectator.setColor(ChatColor.GRAY);
Spectator.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
Spectator.setAllowFriendlyFire(false);
}
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);
}
}
}
private static void onStandby() {
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 1000000, 127, false, false));
}
}
private static void onStarting() {
for(String playerName : Seeker.getEntries()) {
Player player = playerList.get(playerName);
if(player != null) {
player.teleport(new Location(player.getWorld(), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
}
}
private static void onPlaying() {
if(decreaseBorder) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder add -100 30");
decreaseBorder = false;
}
if(!tauntPlayer.equals("")) {
Player taunted = playerList.get(tauntPlayer);
if(taunted != null) {
Firework fw = (Firework) taunted.getLocation().getWorld().spawnEntity(taunted.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.setPower(2);
fwm.addEffect(FireworkEffect.builder()
.withColor(Color.BLUE)
.withColor(Color.RED)
.withColor(Color.YELLOW)
.with(FireworkEffect.Type.STAR)
.with(FireworkEffect.Type.BALL)
.with(FireworkEffect.Type.BALL_LARGE)
.flicker(true)
.withTrail()
.build());
fw.setFireworkMeta(fwm);
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "Taunt >" + ChatColor.WHITE + " Taunt has been activated");
}
tauntPlayer = "";
}
for(Player player : playerList.values()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.DOLPHINS_GRACE, 1000000, 1, false, false));
if(getPlayerData(player.getName(),"GiveStatus") > 0) {
setPlayerData(player.getName(),"GiveStatus",0);
player.getInventory().clear();
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
if(Seeker.getEntries().contains(player.getName())){
ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD,1);
diamondSword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
ItemMeta diamondSwordMeta = diamondSword.getItemMeta();
diamondSwordMeta.setDisplayName("Seeker Sword");
diamondSwordMeta.setUnbreakable(true);
diamondSword.setItemMeta(diamondSwordMeta);
player.getInventory().addItem(diamondSword);
ItemStack wackyStick = new ItemStack(Material.STICK,1);
wackyStick.addUnsafeEnchantment(Enchantment.KNOCKBACK, 3);
ItemMeta wackyStickMeta = wackyStick.getItemMeta();
wackyStickMeta.setDisplayName("Wacky Stick");
wackyStick.setItemMeta(wackyStickMeta);
player.getInventory().addItem(wackyStick);
}
else if(Hider.getEntries().contains(player.getName())){
ItemStack stoneSword = new ItemStack(Material.STONE_SWORD,1);
stoneSword.addEnchantment(Enchantment.DAMAGE_ALL, 2);
ItemMeta stoneSwordMeta = stoneSword.getItemMeta();
stoneSwordMeta.setDisplayName("Hider Sword");
stoneSwordMeta.setUnbreakable(true);
stoneSword.setItemMeta(stoneSwordMeta);
player.getInventory().addItem(stoneSword);
ItemStack splashPotion = new ItemStack(Material.SPLASH_POTION,1);
PotionMeta splashPotionMeta = (PotionMeta) splashPotion.getItemMeta();
splashPotionMeta.setBasePotionData(new PotionData(PotionType.REGEN));
splashPotion.setItemMeta(splashPotionMeta);
player.getInventory().addItem(splashPotion);
ItemStack potion = new ItemStack(Material.POTION,2);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
potionMeta.setBasePotionData(new PotionData(PotionType.INSTANT_HEAL));
potion.setItemMeta(potionMeta);
player.getInventory().addItem(potion);
}
}
if(getPlayerData(player.getName(),"Death") > 0) {
setPlayerData(player.getName(),"Death",0);
Seeker.addEntry(player.getName());
}
}
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(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);
int temp = (int) player.getLocation().distance(seeker.getLocation());
if(distance > temp) {
distance = temp;
}
}
int x = player.getLocation().getBlockX();
int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ();
switch(tick) {
case 0:
if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s .5 1",player.getName(),x,y,z));
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 3:
if(distance < 30) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.basedrum master %s %s %s %s 3.31",player.getName(),x,y,z));
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 6:
if(distance < 10) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
case 9:
if(distance < 20) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("playsound minecraft:block.note_block.bit master %s %s %s %s .3 1",player.getName(),x,y,z));
break;
}
}
}
}

View file

@ -0,0 +1,44 @@
package net.tylermurphy.hideAndSeek.manager;
import static net.tylermurphy.hideAndSeek.Store.*;
import org.bukkit.Bukkit;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
public class WorldborderManager {
public static void schedule() {
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(ChatColor.RED + "World Border> " + ChatColor.WHITE + "Worldborder decreacing by 100 blocks over the next 30s");
currentWorldborderSize -= 100;
decreaseBorder = true;
} else {
break;
}
}
}
});
}
public static void reset() {
if(worldborderEnabled) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set "+worldborderSize);
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("worldborder center %s %s",worldborderPosition.getBlockX(),worldborderPosition.getBlockZ()));
currentWorldborderSize = worldborderSize;
} else {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder set 30000000");
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "worldborder center 0 0");
}
}
}

View file

@ -0,0 +1,11 @@
name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main
version: 1.0
author: KenshinEto
load: STARTUP
commands:
hideandseek:
description: Hide and Seek command
usage: /hideandseek [about|help|start|stop|setspawn|setseeker]
permission: hideAndSeek.admin
aliases: hs