Merge branch 'master' into thanos-mineware

This commit is contained in:
Thanos paravantis 2015-12-11 13:32:24 +02:00
commit 3f4980a90f
63 changed files with 4089 additions and 230 deletions

View File

@ -66,10 +66,10 @@
</fileset>
<fileset dir="../Mineplex.Core/bin">
<include name="**/*.class"/>
<include name="**/*.png"/>
</fileset>
<fileset dir="../Mineplex.Core.Common/bin">
<include name="**/*.class"/>
<include name="**/*.png"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Game.ClassCombat/bin">
<include name="**/*.class"/>

View File

@ -8,6 +8,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Cache"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -5,8 +5,8 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.bungee.playerStats.data.IpInfo;
import mineplex.playerCache.PlayerCache;
import mineplex.playerCache.PlayerInfo;
import mineplex.cache.player.PlayerCache;
import mineplex.cache.player.PlayerInfo;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.plugin.Listener;

View File

@ -9,7 +9,7 @@ import java.sql.Statement;
import java.util.UUID;
import mineplex.bungee.playerStats.data.IpInfo;
import mineplex.playerCache.PlayerInfo;
import mineplex.cache.player.PlayerInfo;
public class PlayerStatsRepository
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,18 @@
package mineplex.core.common.util;
public enum LineFormat
{
LORE(200), CHAT(319);
private int _length;
private LineFormat(int length)
{
_length = length;
}
public int getLength()
{
return _length;
}
}

View File

@ -12,6 +12,7 @@ import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.structs.ItemContainer;
@ -1116,4 +1117,12 @@ public class UtilItem
{
return _materials.containsKey(material);
}
public static ItemStack makeUnbreakable(ItemStack i)
{
ItemMeta im = i.getItemMeta();
im.spigot().setUnbreakable(true);
i.setItemMeta(im);
return i;
}
}

View File

@ -1,52 +1,452 @@
package mineplex.core.common.util;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import javax.imageio.ImageIO;
import mineplex.core.common.CurrencyType;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Material;
import org.bukkit.ChatColor;
public class UtilText {
public static <T> String listToString(Collection<T> inputList, boolean comma) {
String out = "";
public class UtilText
{
private static HashMap<Character, Integer> _characters = new HashMap<Character, Integer>();
for (T cur : inputList) {
out += cur.toString() + (comma ? ", " : " ");
static
{
try
{
InputStream inputStream = CurrencyType.class.getResourceAsStream("ascii.png");
BufferedImage image = ImageIO.read(inputStream);
char[] text = new char[]
{
' ',
'!',
'"',
'#',
'$',
'%',
'&',
'\'',
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
';',
'<',
'=',
'>',
'?',
'@',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'[',
'\\',
']',
'^',
'_',
'`',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'{',
'|',
'}',
'~'
};
int x = 0;
int y = 16;
for (char c : text)
{
grab(c, image, x, y);
if (x < 15 * 8)
{
x += 8;
}
else
{
x = 0;
y += 8;
}
}
inputStream.close();
}
if (out.length() > 0) {
out = out.substring(0, out.length() - (comma ? 2 : 1));
catch (IOException e)
{
e.printStackTrace();
}
return out;
}
public static int upperCaseCount(String input) {
int count = 0;
for (int k = 0; k < input.length(); k++) {
char ch = input.charAt(k);
if (Character.isUpperCase(ch))
count++;
public static String center(String string, LineFormat lineFormat)
{
int length = getLength(string);
if (length > lineFormat.getLength())
{
return string;
}
return count;
// Get the number of empty pixels on both sides of the string
int div = (int) Math.floor((lineFormat.getLength() - length) / 2D);
div -= 2; // For the gap between the strings
return fillLine(" ", div) + string + fillLine(" ", div);
}
public static int lowerCaseCount(String input) {
int count = 0;
for (int k = 0; k < input.length(); k++) {
char ch = input.charAt(k);
if (Character.isLowerCase(ch))
count++;
public static String alignRight(String string, LineFormat lineFormat)
{
int length = getLength(string);
if (length > lineFormat.getLength())
{
return string;
}
return count;
// Get the number of empty pixels on both sides of the string
int div = lineFormat.getLength() - length;
div -= 1; // For the gap between the strings
return fillLine(" ", div) + string;
}
public static String centerChat(String string, LineFormat lineFormat)
{
int length = getLength(string);
if (length > lineFormat.getLength())
{
return string;
}
// Get the number of empty pixels on both sides of the string
int div = (int) Math.floor(((lineFormat.getLength() + 10) - length) / 2D);
div -= 2; // For the gap between the strings
return fillLine(" ", div) + string;
}
public static String substringPixels(String string, int cutoff)
{
int len = 0;
char[] array = string.toCharArray();
boolean bold = false;
for (int i = 0; i < array.length; i++)
{
char c = array[i];
if (c == '<27>')
{
if (++i < array.length)
{
ChatColor color = ChatColor.getByChar(array[i]);
if (color != null)
{
if (color.equals(ChatColor.BOLD))
{
bold = true;
}
else if (color.equals(ChatColor.RESET) || color.isColor())
{
bold = false;
}
}
}
continue;
}
if (!_characters.containsKey(c))
{
continue;
}
int toAdd = _characters.get(c);
if (bold)
{
toAdd++;
}
if (len + toAdd > cutoff)
{
return string.substring(0, Math.max(0, i - 1));
}
if (i + 1 < array.length)
{
len++;
}
}
return string;
}
public static ArrayList<String> splitLines(String[] strings, LineFormat lineFormat)
{
ArrayList<String> lines = new ArrayList<String>();
for (String s : strings)
{
lines.addAll(splitLine(s, lineFormat));
}
return lines;
}
public static ArrayList<String> splitLine(String string, LineFormat lineFormat)
{
ArrayList<String> strings = new ArrayList<String>();
String current = "";
int currentLength = 0;
String[] split = string.split(" ");
String colors = "";
for (int i = 0; i < split.length; i++)
{
String word = split[i];
int wordLength = getLength(colors + word);
if (currentLength + wordLength + 4 > lineFormat.getLength() && !current.isEmpty())
{
strings.add(current);
current = colors + word;
currentLength = wordLength + 1;
continue;
}
if (i != 0)
{
current += " ";
currentLength += 4;
}
current += word;
currentLength += wordLength;
colors = ChatColor.getLastColors(current);
}
if (!current.isEmpty())
{
strings.add(current);
}
return strings;
}
public static String fillLine(String filler, int maxPixels)
{
int pixels = getLength(filler);
if (pixels <= 0)
{
return "";
}
String toReturn = "";
int currentLen = 0;
int offset = maxPixels % 4;
boolean isOffset = false;
if (offset > 0)
{
toReturn += C.Bold;
}
while (currentLen + pixels <= maxPixels)
{
currentLen += pixels + 1;
toReturn += filler;
if (offset-- > 0)
{
currentLen++;
if (offset == 0)
{
isOffset = false;
toReturn += ChatColor.RESET;
}
}
}
if (isOffset)
{
toReturn += ChatColor.RESET;
}
return toReturn;
}
public static boolean fitsOneLine(String string, LineFormat lineFormat)
{
return getLength(string) <= lineFormat.getLength();
}
public static int getLength(String string)
{
int len = 0;
char[] array = string.toCharArray();
boolean bold = false;
for (int i = 0; i < array.length; i++)
{
char c = array[i];
if (c == '<27>')
{
if (++i < array.length)
{
ChatColor color = ChatColor.getByChar(array[i]);
if (color != null)
{
if (color.equals(ChatColor.BOLD))
{
bold = true;
}
else if (color.equals(ChatColor.RESET) || color.isColor())
{
bold = false;
}
}
}
continue;
}
if (!_characters.containsKey(c))
{
continue;
}
len += _characters.get(c);
if (bold)
{
len++;
}
if (i + 1 < array.length)
{
len++;
}
}
return len;
}
private static void grab(Character character, BufferedImage image, int imageX, int imageY)
{
if (character == ' ')
{
_characters.put(character, 3);
return;
}
for (int x = 0; x < 8; x++)
{
boolean isTransparentLine = true;
for (int y = 0; y < 8; y++)
{
int pixel = image.getRGB(imageX + x, imageY + y);
if ((pixel >> 24) != 0x00)
{
isTransparentLine = false;
break;
}
}
if (isTransparentLine)
{
_characters.put(character, x);
return;
}
}
_characters.put(character, 8);
}
public static boolean isStringSimilar(String newString, String oldString, float matchRequirement)
@ -55,84 +455,136 @@ public class UtilText {
{
return newString.toLowerCase().equals(oldString.toLowerCase());
}
for (int i=0 ; i < newString.length() * matchRequirement ; i++)
for (int i = 0; i < newString.length() * matchRequirement; i++)
{
int matchFromIndex = 0;
//Look for substrings starting at i
for (int j=0 ; j < oldString.length() ; j++)
// Look for substrings starting at i
for (int j = 0; j < oldString.length(); j++)
{
//End of newString
if (i+j >= newString.length())
// End of newString
if (i + j >= newString.length())
{
break;
}
//Matched
if (newString.charAt(i+j) == oldString.charAt(j))
// Matched
if (newString.charAt(i + j) == oldString.charAt(j))
{
matchFromIndex++;
if (matchFromIndex >= newString.length() * matchRequirement)
return true;
}
//No Match > Reset
// No Match > Reset
else
{
break;
}
}
}
return false;
}
public static <T> String listToString(Collection<T> inputList, boolean comma)
{
String out = "";
for (T cur : inputList)
{
out += cur.toString() + (comma ? ", " : " ");
}
if (out.length() > 0)
{
out = out.substring(0, out.length() - (comma ? 2 : 1));
}
return out;
}
public static int lowerCaseCount(String input)
{
int count = 0;
for (int k = 0; k < input.length(); k++)
{
char ch = input.charAt(k);
if (Character.isLowerCase(ch))
count++;
}
return count;
}
public static int upperCaseCount(String input)
{
int count = 0;
for (int k = 0; k < input.length(); k++)
{
char ch = input.charAt(k);
if (Character.isUpperCase(ch))
count++;
}
return count;
}
public static String[] wrap(String text, int lineLength)
{
return wrap(text, lineLength, true);
}
public static String[] wrap(String text, int lineLength, boolean wrapLongerWords) {
public static String[] wrap(String text, int lineLength, boolean wrapLongerWords)
{
return WordUtils.wrap(text, lineLength, "\00D0", wrapLongerWords).split("\00D0");
}
public static String repeat(String txt, int times)
{
return new String(new byte[times]).replace("\0", txt);
}
public static boolean plural(int x){
public static boolean plural(int x)
{
return x <= 0 ? true : x > 1;
}
public static String trim(int maxLength, String s) {
public static String trim(int maxLength, String s)
{
return s.length() <= maxLength ? s : s.substring(0, maxLength);
}
public static <X> String arrayToString(X[] array, String delimiter)
{
StringBuilder string = new StringBuilder();
int index = 0;
for (X x : array)
{
string.append(x.toString());
if (index != array.length - 1)
{
string.append(delimiter);
}
index++;
}
return string.toString();
}
public static <X> String arrayToString(X[] array)
{
return arrayToString(array, null);
}
}
}

View File

@ -13,7 +13,7 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jooq-3.5.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/NoCheatPlus.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Cache"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -9,6 +9,9 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.gson.Gson;
import mineplex.cache.player.PlayerCache;
import mineplex.cache.player.PlayerInfo;
import mineplex.core.MiniPlugin;
import mineplex.core.account.command.TestRank;
import mineplex.core.account.command.UpdateRank;
@ -24,8 +27,6 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.playerCache.PlayerCache;
import mineplex.playerCache.PlayerInfo;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

View File

@ -816,6 +816,48 @@ public enum Achievement
new String[]{"Get hit by a monster and", "land on the Safe Pad"},
new int[]{1},
AchievementCategory.MONSTER_MAZE),
GLADIATORS_HARDENED_GLADIATOR("Hardened Gladiator", 1000,
new String[]{"Gladiators.Wins"},
new String[]{"Win 50 games of Gladiators"},
new int[]{50},
AchievementCategory.GLADIATORS),
GLADIATORS_BATTLE_BRED("Battle Bred", 1500,
new String[]{"Gladiators.Wins"},
new String[]{"Win 100 games of Gladiators"},
new int[]{100},
AchievementCategory.GLADIATORS),
GLADIATORS_BRAWLER("Brawler", 1000,
new String[]{"Gladiators.Brawler"},
new String[]{"Kill 3 Gladiators", "with your bare hands"},
new int[]{3},
AchievementCategory.GLADIATORS),
// GLADIATORS_UNTOUCHABLE("Untouchable", 1500,
// new String[]{"Gladiators.Untouchable"},
// new String[]{"Kill 10 Gladiators", "without taking any damage"},
// new int[]{10},
// AchievementCategory.GLADIATORS),
// GLADIATORS_FLAWLESS("Flawless", 1000,
// new String[]{"Gladiators.Flawless"},
// new String[]{"Win a game of gladiators", "without taking any damage"},
// new int[]{1},
// AchievementCategory.GLADIATORS),
GLADIATORS_PRECISION("Precision", 800,
new String[]{"Gladiators.Precision"},
new String[]{"Don't miss a single", "arrow in a game of", "Gladiators (Minimum 3)"},
new int[]{1},
AchievementCategory.GLADIATORS),
GLADIATORS_SWIFT_KILL("Swift Kill", 1000,
new String[]{"Gladiators.SwiftKill"},
new String[]{"Earn 15 first bloods", "in Gladiators"},
new int[]{15},
AchievementCategory.GLADIATORS)
;

View File

@ -154,6 +154,10 @@ public enum AchievementCategory
MONSTER_MAZE("Monster Maze", null,
new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED},
Material.ROTTEN_FLESH, 0, GameCategory.ARCADE, "SoonTM"),
GLADIATORS("Gladiators", null,
new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED },
Material.IRON_SWORD, 0, GameCategory.ARCADE, null)
;

View File

@ -7,29 +7,21 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Map;
import com.sun.org.apache.xpath.internal.operations.Bool;
import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge;
import mineplex.database.Tables;
import mineplex.database.tables.records.BonusRecord;
import org.jooq.Configuration;
import org.jooq.DSLContext;
import org.jooq.Record2;
import org.jooq.SQLDialect;
import org.jooq.TableField;
import org.jooq.impl.DSL;
import org.jooq.impl.DefaultConfiguration;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,5 +1,6 @@
package mineplex.core.cosmetic.ui.page;
import mineplex.cache.player.PlayerCache;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C;
@ -16,7 +17,6 @@ import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.pet.repository.token.PetToken;
import mineplex.core.shop.page.ConfirmationPage;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.playerCache.PlayerCache;
import net.minecraft.server.v1_8_R3.ItemStack;
import net.minecraft.server.v1_8_R3.Items;

View File

@ -10,6 +10,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson;
import mineplex.cache.player.PlayerCache;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientWebResponseEvent;
@ -24,7 +26,6 @@ import mineplex.core.donation.repository.token.DonorTokenWrapper;
import mineplex.core.server.util.TransactionResponse;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.playerCache.PlayerCache;
public class DonationManager extends MiniDbClientPlugin<Donor>
{

View File

@ -72,6 +72,8 @@ public enum GameDisplay
BouncyBalls("Bouncy Balls", Material.SLIME_BALL, (byte)0, GameCategory.ARCADE, 57),
Gladiators("Gladiators", Material.IRON_SWORD, (byte)0, GameCategory.ARCADE, 58),
Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999);
String _name;

View File

@ -22,6 +22,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.cache.player.PlayerCache;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
@ -31,7 +32,6 @@ import mineplex.core.inventory.data.InventoryRepository;
import mineplex.core.inventory.data.Item;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.playerCache.PlayerCache;
public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
{

View File

@ -16,10 +16,10 @@ public class NBSReader
{
public static NoteSong loadSong(String fileName) throws FileNotFoundException
{
return loadSong(new DataInputStream(new FileInputStream(new File(fileName))));
return loadSong(new DataInputStream(new FileInputStream(new File(fileName))), fileName);
}
public static NoteSong loadSong(DataInputStream stream)
public static NoteSong loadSong(DataInputStream stream, String defaultName)
{
try
{
@ -41,6 +41,9 @@ public class NBSReader
int blocksRemoved = readInt(stream);
String midiFileName = readString(stream);
if ((name == null || name.length() == 0) && defaultName != null)
name = defaultName;
HashMap<Integer, NoteLayer> layerMap = new HashMap<Integer, NoteLayer>();
// Note Block Information

View File

@ -1,10 +1,7 @@
package mineplex.core.noteblock;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -43,38 +40,49 @@ public class NotePlayer
private void startThread()
{
Thread thread = new Thread(() -> {
while (!_finished)
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
_tick++;
if (_tick > _song.getLength())
long startTime = System.currentTimeMillis();
while (!_finished)
{
if (_loop)
_tick++;
if (_tick > _song.getLength())
{
_tick = 1;
if (_loop)
{
_tick = 1;
}
else
{
_finished = true;
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
{
@Override
public void run()
{
SongFinishEvent event = new SongFinishEvent(_song);
_plugin.getServer().getPluginManager().callEvent(event);
}
});
return;
}
}
else
playTick(_tick);
try
{
_finished = true;
_plugin.getServer().getScheduler().runTask(_plugin, () -> {
SongFinishEvent event = new SongFinishEvent(_song);
_plugin.getServer().getPluginManager().callEvent(event);
});
return;
Thread.sleep(_sleepMs);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
playTick(_tick);
try
{
Thread.sleep(_sleepMs);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
});
@ -82,18 +90,28 @@ public class NotePlayer
thread.start();
}
private void playNote(Note note, float volume, Collection<? extends Player> players)
{
players.stream().filter(_verifier::shouldPlay).forEach((player) ->
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33)));
}
private void playTick(int tick)
{
Collection<? extends Player> players = UtilServer.getPlayersCollection();
Player[] playerArray = UtilServer.getPlayers();
List<Player> players = new ArrayList<>(playerArray.length);
for (Player player : playerArray)
{
if (_verifier.shouldPlay(player))
players.add(player);
}
float volume = _volumeMult * 1F;
_song.getLayers().stream().map(layer -> layer.getNote(tick)).filter(Objects::nonNull).forEach((note) -> playNote(note, volume, players));
for (NoteLayer layer : _song.getLayers())
{
Note note = layer.getNote(tick);
if (note != null)
{
float volume = _volumeMult * (layer.getVolume() / 100F);
for (Player player : players)
{
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33));
}
}
}
}
public void cancel()

View File

@ -0,0 +1,73 @@
package mineplex.core.playerCount;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.BungeeServer;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
public class PlayerCountManager extends MiniPlugin
{
private Region _region;
private DataRepository<BungeeServer> _repository;
private DataRepository<BungeeServer> _secondRepository;
private volatile int _playerCount;
public PlayerCountManager(JavaPlugin plugin)
{
super("PlayerCount", plugin);
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
Region.ALL, BungeeServer.class, "bungeeServers");
if (_region == Region.US)
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.81.1.156", 6379, ConnectionData.ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionData.ConnectionType.SLAVE, "ServerStatus"),
Region.ALL, BungeeServer.class, "bungeeServers");
else
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.33.53.16", 6379, ConnectionData.ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionData.ConnectionType.SLAVE, "ServerStatus"),
Region.ALL, BungeeServer.class, "bungeeServers");
updatePlayerCount();
}
private void updatePlayerCount()
{
int totalPlayers = 0;
for (BungeeServer server : _repository.getElements())
{
totalPlayers += server.getPlayerCount();
}
for (BungeeServer server : _secondRepository.getElements())
{
totalPlayers += server.getPlayerCount();
}
_playerCount = totalPlayers;
}
public int getPlayerCount()
{
return _playerCount;
}
@EventHandler
public void refresh(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
runAsync(this::updatePlayerCount);
}
}

View File

@ -128,7 +128,6 @@ public class PreferencesRepository extends RepositoryBase
preferences.ClanTips = resultSet.getBoolean(13);
preferences.HubMusic = resultSet.getBoolean(14);
preferences.DisableAds = resultSet.getBoolean(15);
System.out.println("<< " + resultSet.getBoolean(13));
}
return preferences;

View File

@ -0,0 +1,29 @@
package mineplex.core.profileCache;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
public class ProfileCacheLookupCallback implements ProfileLookupCallback
{
private ProfileCacheManager _profileCacheManager;
private ProfileLookupCallback _profileLookupCallback;
public ProfileCacheLookupCallback(ProfileCacheManager profileCacheManager, ProfileLookupCallback profileLookupCallback)
{
_profileCacheManager = profileCacheManager;
_profileLookupCallback = profileLookupCallback;
}
@Override
public void onProfileLookupFailed(GameProfile gameProfile, Exception exception)
{
_profileLookupCallback.onProfileLookupFailed(gameProfile, exception);
}
@Override
public void onProfileLookupSucceeded(GameProfile gameProfile)
{
_profileCacheManager.cacheProfile(gameProfile);
_profileLookupCallback.onProfileLookupSucceeded(gameProfile);
}
}

View File

@ -1,81 +1,134 @@
//package mineplex.core.profileCache;
//
//import java.util.UUID;
//
//import org.bukkit.plugin.java.JavaPlugin;
//import net.minecraft.util.com.google.gson.Gson;
//import net.minecraft.util.com.google.gson.GsonBuilder;
//import net.minecraft.util.com.mojang.authlib.GameProfile;
//import net.minecraft.util.com.mojang.authlib.properties.PropertyMap;
//import net.minecraft.util.com.mojang.authlib.yggdrasil.ProfileCache;
//import net.minecraft.util.com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
//import net.minecraft.util.com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
//import net.minecraft.util.com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse;
//import net.minecraft.util.com.mojang.util.UUIDTypeAdapter;
//
//import mineplex.core.MiniPlugin;
//import mineplex.serverdata.Region;
//import mineplex.serverdata.redis.RedisDataRepository;
//import mineplex.serverdata.servers.ServerManager;
//
//public class ProfileCacheManager extends MiniPlugin implements ProfileCache
//{
// private RedisDataRepository<ProfileData> _profileRepository;
// private Gson _gson;
//
// public ProfileCacheManager(JavaPlugin plugin)
// {
// super("Profile Cache", plugin);
//
// _profileRepository = new RedisDataRepository<ProfileData>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
// Region.ALL, ProfileData.class, "profileCacheRepo");
//
// GsonBuilder builder = new GsonBuilder();
// builder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer());
// builder.registerTypeAdapter(UUID.class, new UUIDTypeAdapter());
// builder.registerTypeAdapter(ProfileSearchResultsResponse.class, new net.minecraft.util.com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse.Serializer());
// _gson = builder.create();
//
// try
// {
// YggdrasilMinecraftSessionService.setProfileCache(this);
// YggdrasilGameProfileRepository.setProfileCache(this);
// }
// catch (Exception e)
// {
// System.out.println("================================================");
// System.out.println("Failed to load Profile Cache (Skins)");
// System.out.println("Are you using the correct modified Craftbukkit?");
// System.out.println("================================================");
// }
// }
//
//
// @Override
// public GameProfile attemptToLoadProfile(String playerName)
// {
// ProfileData profile = _profileRepository.getElement(playerName.toLowerCase());
//
// if (profile != null)
// {
// PropertyMap propertyMap = _gson.fromJson(profile.getPropertyMap(), PropertyMap.class);
// GameProfile gameProfile = new GameProfile(profile.getUuid(), profile.getPlayerName());
// gameProfile.getProperties().putAll(propertyMap);
//
//// System.out.println("Loaded profile " + playerName + " from repository!");
// return gameProfile;
// }
//
//// System.out.println("Profile Null");
//
// return null;
// }
//
// @Override
// public void cacheProfile(GameProfile profile)
// {
//// System.out.println("Cached profile: " + profile.getName());
// ProfileData data = new ProfileData(profile.getId(), profile.getName(), _gson.toJson(profile.getProperties()));
// _profileRepository.addElement(data, 60 * 60 * 24); // 1 day
// }
//}
package mineplex.core.profileCache;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository;
import com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse;
import com.mojang.util.UUIDTypeAdapter;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
public class ProfileCacheManager extends MiniPlugin implements GameProfileRepository
{
private YggdrasilGameProfileRepository _mojangProfileRepository;
private RedisDataRepository<ProfileData> _profileRepository;
private Gson _gson;
public ProfileCacheManager(JavaPlugin plugin)
{
super("Profile Cache", plugin);
_profileRepository = new RedisDataRepository<ProfileData>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.ALL, ProfileData.class, "profileCacheRepo");
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer());
builder.registerTypeAdapter(UUID.class, new UUIDTypeAdapter());
builder.registerTypeAdapter(ProfileSearchResultsResponse.class, new com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse.Serializer());
_gson = builder.create();
try
{
Field mojangProfileRepo = net.minecraft.server.v1_8_R3.MinecraftServer.class.getDeclaredField("Y");
mojangProfileRepo.setAccessible(true);
_mojangProfileRepository = (YggdrasilGameProfileRepository) mojangProfileRepo.get(((CraftServer)Bukkit.getServer()).getServer());
mojangProfileRepo.set(((CraftServer)Bukkit.getServer()).getServer(), this);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("================================================");
System.out.println("Failed to load Profile Cache (Skins)");
System.out.println("Are you using the correct modified Craftbukkit?");
System.out.println("================================================");
}
}
public GameProfile attemptToLoadProfile(String playerName)
{
ProfileData profile = _profileRepository.getElement(playerName.toLowerCase());
if (profile != null)
{
PropertyMap propertyMap = _gson.fromJson(profile.getPropertyMap(), PropertyMap.class);
GameProfile gameProfile = new GameProfile(profile.getUuid(), profile.getPlayerName());
gameProfile.getProperties().putAll(propertyMap);
return gameProfile;
}
return null;
}
public void cacheProfile(final GameProfile profile)
{
if (Bukkit.isPrimaryThread())
{
runAsync(new Runnable()
{
public void run()
{
cacheProfileSafely(profile);
}
});
}
else
cacheProfileSafely(profile);
}
@Override
public void findProfilesByNames(String[] profileNames, Agent agent, ProfileLookupCallback profileLookupCallback)
{
List<String> uncachedProfileNames = new ArrayList<>();
for (String profileName : profileNames)
{
GameProfile profile = attemptToLoadProfile(profileName);
if (profile == null)
uncachedProfileNames.add(profileName);
else
profileLookupCallback.onProfileLookupSucceeded(profile);
}
_mojangProfileRepository.findProfilesByNames(uncachedProfileNames.toArray(new String[uncachedProfileNames.size()]), agent, new ProfileCacheLookupCallback(this, profileLookupCallback));
}
@EventHandler
public void clearRepository(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_10)
return;
_profileRepository.clean();
}
private void cacheProfileSafely(GameProfile profile)
{
ProfileData data = new ProfileData(profile.getId(), profile.getName(), _gson.toJson(profile.getProperties()));
_profileRepository.addElement(data, 60 * 60 * 24); // 1 day
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.cache.player.PlayerCache;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.pet.PetManager;
@ -13,7 +14,6 @@ import mineplex.core.pet.repository.token.PetToken;
import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity;
import mineplex.core.reward.RewardType;
import mineplex.playerCache.PlayerCache;
/**
* Created by shaun on 14-09-18.

View File

@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.cache.player.PlayerCache;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
@ -16,7 +17,6 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.command.GiveStatCommand;
import mineplex.core.stats.command.TimeCommand;
import mineplex.core.stats.event.StatChangeEvent;
import mineplex.playerCache.PlayerCache;
public class StatsManager extends MiniDbClientPlugin<PlayerStats>
{

View File

@ -5,12 +5,12 @@ import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
import mineplex.cache.player.PlayerCache;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.task.repository.TaskRepository;
import mineplex.playerCache.PlayerCache;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Database"/>

View File

@ -38,6 +38,7 @@ import mineplex.core.pet.PetManager;
import mineplex.core.poll.PollManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
@ -182,6 +183,8 @@ public class Hub extends JavaPlugin implements IRelation
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true);
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true);
new ProfileCacheManager(this);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
}

View File

@ -261,7 +261,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
if (file.getName().endsWith(".nbs"))
{
System.out.println("Loading Song " + file.getPath());
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(file)));
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(file)), file.getName().replace("_", " ").replace(".nbs", ""));
if (song != null)
{
_songs.add(song);

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mineplex.PlayerCache</name>
<name>Mineplex.Cache</name>
<comment></comment>
<projects>
</projects>

View File

@ -1,4 +1,4 @@
package mineplex.playerCache;
package mineplex.cache.player;
import java.util.UUID;

View File

@ -1,4 +1,4 @@
package mineplex.playerCache;
package mineplex.cache.player;
import java.util.UUID;

View File

@ -15,6 +15,7 @@ import mineplex.core.monitor.LagMeter;
import mineplex.core.npc.NpcManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.stats.StatsManager;
@ -88,6 +89,8 @@ public class StaffServer extends JavaPlugin
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("377bdea3-badc-448d-81c1-65db43b17ea4"), "Strutt20"));
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp"));
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo"));
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo"));
new ProfileCacheManager(this);
}
}

View File

@ -45,6 +45,7 @@ import mineplex.core.pet.PetManager;
import mineplex.core.poll.PollManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
@ -160,6 +161,8 @@ public class Arcade extends JavaPlugin
new PacketsInteractionFix(this, packetHandler);
new FoodDupeFix(this);
new ProfileCacheManager(this);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -26,6 +26,7 @@ import nautilus.game.arcade.game.games.dragons.DragonsTeams;
import nautilus.game.arcade.game.games.draw.Draw;
import nautilus.game.arcade.game.games.event.EventGame;
import nautilus.game.arcade.game.games.evolution.Evolution;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.game.games.gravity.Gravity;
import nautilus.game.arcade.game.games.halloween.Halloween;
import nautilus.game.arcade.game.games.hideseek.HideSeek;
@ -128,6 +129,7 @@ public enum GameType
SkywarsTeams(TeamSkywars.class, GameDisplay.SkywarsTeams, new GameType[]{GameType.Skywars}, false),
MonsterMaze(MonsterMaze.class, GameDisplay.MonsterMaze),
MonsterLeague(MonsterLeague.class, GameDisplay.MonsterLeague),
Gladiators(Gladiators.class, GameDisplay.Gladiators),
BouncyBalls(BouncyBalls.class, GameDisplay.BouncyBalls),

View File

@ -0,0 +1,39 @@
package nautilus.game.arcade.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class FirstBloodEvent extends Event
{
private Player player;
public FirstBloodEvent(Player player)
{
this.player = player;
}
public Player getPlayer()
{
return player;
}
private static HandlerList _handlers = new HandlerList();
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -36,7 +36,6 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -73,6 +72,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerGameRespawnEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
@ -303,6 +303,8 @@ public abstract class Game implements Listener
public boolean DeadBodiesDeath = true;
public int DeadBodiesExpire = -1;
public boolean EnableTutorials = false;
public boolean FixSpawnFacing = true;
private IPacketHandler _useEntityPacketHandler;
@ -1724,21 +1726,6 @@ public abstract class Game implements Listener
}
}
}
@EventHandler
public void debug(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equals("/debugteams"))
{
for (GameTeam team : GetTeamList())
{
event.getPlayer().sendMessage(team.GetFormattedName());
for (Player player : team.GetPlayers(false))
{
event.getPlayer().sendMessage(player.getName() + ": " + team.IsAlive(player));
}
}
}
}
public void addTutorials(){}
}

View File

@ -14,6 +14,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
@ -58,6 +59,8 @@ public class GameTeam
private String _name;
private String _displayName;
private ChatColor _color;
private GameTutorial _tutorial;
private HashMap<Player, PlayerState> _players = new HashMap<Player, PlayerState>();
@ -447,4 +450,15 @@ public class GameTeam
return _places;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public void setTutorial(GameTutorial tutorial)
{
_tutorial = tutorial;
}
}

View File

@ -0,0 +1,409 @@
package nautilus.game.arcade.game.games.gladiators;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import nautilus.game.arcade.game.games.gladiators.events.PlayerChangeArenaEvent;
/**
* Created by William (WilliamTiger).
* 07/12/15
*/
public class Arena
{
private Gladiators _host;
private ArenaType _colour;
private Location _mid;
private ArrayList<Location> _spawns;
private Arena _parent;
private Arena[] _childs = new Arena[2];
private boolean _isUsed;
private ArrayList<Location> _doorBlocks;
private boolean _isOpenDoor;
private boolean _doBye;
private ArrayList<Player> _pastPlayers;
private ArenaState _state;
private long _stateTime;
private boolean _alertedAlready;
private boolean _alertedAlready2;
private HashMap<Player, ArrayList<ParticleData>> _particles;
public Arena(Gladiators host, Location mid, ArenaType colour)
{
_host = host;
_mid = mid;
_colour = colour;
_spawns = new ArrayList<>();
_parent = null;
_isUsed = false;
_doorBlocks = new ArrayList<>();
_isOpenDoor = false;
_pastPlayers = new ArrayList<>();
_state = ArenaState.EMPTY;
_stateTime = System.currentTimeMillis();
_particles = new HashMap<>();
_doBye = false;
_alertedAlready = false;
_alertedAlready2 = false;
setupSpawns();
}
public boolean isDoBye()
{
return _doBye;
}
public void setDoBye(boolean doBye)
{
_doBye = doBye;
}
public Arena getParent()
{
return _parent;
}
public long getStateTime()
{
return _stateTime;
}
public void setStateTime(long stateTime)
{
_stateTime = stateTime;
}
public void setParent(Arena parent)
{
_parent = parent;
}
public Arena getChildAt(int index)
{
return _childs[index];
}
public Arena[] getChilds()
{
return _childs;
}
public int getCapacity()
{
int cap = _childs.length;
for(Arena child : _childs)
{
if(child != null)
if(child.isUsed()) cap--;
}
return cap;
}
public ArenaState getState()
{
return _state;
}
public void setState(ArenaState state)
{
_state = state;
}
public ArrayList<Location> getDoorBlocks()
{
return _doorBlocks;
}
public void setChild(int index, Arena child)
{
_childs[index] = child;
child.setParent(this);
}
public void getUsageMap(HashMap<Arena, Integer> used)
{
if(isUsed()) used.put(this, getCapacity());
for(Arena child : _childs)
{
if(child != null) child.getUsageMap(used);
}
}
public boolean areChildrenUsed()
{
for(Arena child : _childs)
{
if(child != null)
if(!child.isUsed()) return false;
}
return true;
}
public Arena getUnusedChild()
{
for(Arena child : _childs)
{
if(child != null)
if(!child.isUsed()) return child;
}
return null;
}
public boolean isAlertedAlready()
{
return _alertedAlready;
}
public void setAlertedAlready(boolean alertedAlready)
{
_alertedAlready = alertedAlready;
}
private void setupSpawns()
{
ArrayList<Location> possible = (ArrayList<Location>) _host.WorldData.GetDataLocs("BLACK").clone();
_mid.setY(UtilAlg.findClosest(_mid, possible).getY());
_spawns.add(correctFace(UtilAlg.findClosest(_mid, possible)));
possible.remove(_spawns.get(0));
_spawns.add(correctFace(UtilAlg.findClosest(_mid, possible)));
}
private Location correctFace(Location l)
{
l.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(l, _mid)));
l.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(l, _mid)));
return l;
}
public Gladiators getHost()
{
return _host;
}
public ArenaType getColour()
{
return _colour;
}
public Location getMid()
{
return _mid;
}
public ArrayList<Location> getSpawns()
{
return _spawns;
}
public ArrayList<Location> capacitySpawns()
{
ArrayList<Location> ret = new ArrayList<>();
if (getCapacity() == 0) return ret;
if (getCapacity() == 1)
{
ret.add(_spawns.get(0));
return ret;
}
if (getCapacity() == 2)
{
ret.add(_spawns.get(0));
ret.add(_spawns.get(1));
return ret;
}
return ret;
}
public ArrayList<Player> getPastPlayers()
{
return _pastPlayers;
}
public boolean isUsed()
{
return _isUsed;
}
public void setIsUsed(boolean isUsed)
{
_isUsed = isUsed;
}
public void closeDoor()
{
for (Location loc : _doorBlocks)
loc.getBlock().setType(Material.OBSIDIAN);
}
public boolean isOpenDoor()
{
return _isOpenDoor;
}
public void openDoor()
{
_isOpenDoor = true;
_host.Manager.getScheduler().scheduleSyncDelayedTask(_host.Manager.getPlugin(), () -> {
for (Location loc : _doorBlocks)
{
loc.getBlock().setType(Material.AIR);
}
}, 5L);
}
public void update()
{
if (getPastPlayers().size() <= 0)
{
setState(ArenaState.EMPTY);
return; // Empty check.
}
if (_state.equals(ArenaState.WAITING))
{
if (_host.getRoundState() != RoundState.FIGHTING)
return;
if (_alertedAlready)
return;
for (Player p : getPastPlayers())
{
UtilTextMiddle.display(C.cAqua + "Please Wait", "The next round will start shortly", 0, 20 * 100, 0, p);
}
_alertedAlready = true;
}
else if (_state.equals(ArenaState.FIGHTING))
{
if (getPastPlayers().size() == 1)
{
openDoor();
setState(ArenaState.RUNNING);
setStateTime(System.currentTimeMillis());
return;
}
if (!UtilTime.elapsed(_stateTime, 60000))
return; // No poison yet.
for (Player p : getPastPlayers())
{
UtilTextBottom.display(C.cRed + C.Bold + "YOU ARE POISONED! KEEP FIGHTING!", p);
_host.Manager.GetDamage().NewDamageEvent(p, null, null, EntityDamageEvent.DamageCause.CUSTOM, 1D, false, true, true, "Health Loss", "Health Loss");
}
}
else if (_state.equals(ArenaState.RUNNING))
{
for (Player p : getPastPlayers())
{
if (_alertedAlready2)
continue;
UtilTextMiddle.display(C.cGreen + "Next Battle", "Follow the particles", 0, 20 * 100, 0, p);
}
_alertedAlready2 = true;
if (UtilTime.elapsed(_stateTime, 15000))
handleSlowMovers();
}
}
public void updateTick()
{
if (_state.equals(ArenaState.RUNNING))
{
for (Player p : getPastPlayers())
showParticles(p);
}
}
private void showParticles(Player p)
{
if (!getPastPlayers().contains(p) || !_state.equals(ArenaState.RUNNING))
{
_particles.remove(p);
return;
}
//New Trails
if (Recharge.Instance.use(p, "Particle Trail", 3000, false, false))
{
if (!_particles.containsKey(p))
_particles.put(p, new ArrayList<ParticleData>());
Location end = UtilAlg.findClosest(_mid, _host.WorldData.GetDataLocs("PINK"));
_particles.get(p).add(new ParticleData(p, end));
}
//Old Trails
if (_particles.containsKey(p) && !_particles.get(p).isEmpty())
{
Iterator<ParticleData> trailIter = _particles.get(p).iterator();
while (trailIter.hasNext())
{
ParticleData data = trailIter.next();
//Returns true if its hit the endpoint
if (data.update())
trailIter.remove();
}
}
}
private void handleSlowMovers()
{
setState(ArenaState.ENDED);
Arena next = _host.getArenaByMid(UtilAlg.findClosest(_mid, _host.getAllArenaMidsOfType(_host.getNextColour(_colour))));
for (Player p : new ArrayList<Player>(_pastPlayers))
{
// TP after 15 seconds of waiting.
p.teleport(UtilAlg.getLocationAwayFromPlayers(next.getSpawns(), _host.GetPlayers(true)).clone());
//p.sendMessage("HANDLE SLOW MOVERS METHOD!");
_host.Manager.getPluginManager().callEvent(new PlayerChangeArenaEvent(p, next, this));
closeDoor();
_host.setPlayerArena(p, next);
UtilTextBottom.display("§c§lTELEPORTED! YOU TOOK TOO LONG!", p);
next.setDoBye(true);
}
_pastPlayers.clear(); // Clear out the un-used players.
}
}

View File

@ -0,0 +1,14 @@
package nautilus.game.arcade.game.games.gladiators;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public enum ArenaState
{
EMPTY,
WAITING,
FIGHTING,
RUNNING,
ENDED;
}

View File

@ -0,0 +1,243 @@
package nautilus.game.arcade.game.games.gladiators;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
/**
* Created by William (WilliamTiger).
* 07/12/15
*/
public enum ArenaType
{
RED(1, new Loadout()
{
@Override
public ItemStack getSword()
{
return new ItemStack(Material.DIAMOND_SWORD, 1);
}
@Override
public ItemStack getRod()
{
return new ItemStack(Material.FISHING_ROD, 1);
}
@Override
public ItemStack getBow()
{
return new ItemStack(Material.BOW, 1);
}
@Override
public ItemStack getArrows()
{
return new ItemStack(Material.ARROW, 10);
}
@Override
public ItemStack getHelmet()
{
return new ItemStack(Material.IRON_HELMET, 1);
}
@Override
public ItemStack getChestplate()
{
return new ItemStack(Material.IRON_CHESTPLATE, 1);
}
@Override
public ItemStack getLeggings()
{
return new ItemStack(Material.IRON_LEGGINGS, 1);
}
@Override
public ItemStack getBoots()
{
return new ItemStack(Material.IRON_BOOTS, 1);
}
}),
ORANGE(2, new Loadout()
{
@Override
public ItemStack getSword()
{
return new ItemStack(Material.IRON_SWORD, 1);
}
@Override
public ItemStack getRod()
{
return new ItemStack(Material.FISHING_ROD, 1);
}
@Override
public ItemStack getBow()
{
return new ItemStack(Material.BOW, 1);
}
@Override
public ItemStack getArrows()
{
return new ItemStack(Material.ARROW, 7);
}
@Override
public ItemStack getHelmet()
{
return new ItemStack(Material.CHAINMAIL_HELMET);
}
@Override
public ItemStack getChestplate()
{
return new ItemStack(Material.CHAINMAIL_CHESTPLATE, 1);
}
@Override
public ItemStack getLeggings()
{
return new ItemStack(Material.CHAINMAIL_LEGGINGS, 1);
}
@Override
public ItemStack getBoots()
{
return new ItemStack(Material.CHAINMAIL_BOOTS, 1);
}
}),
YELLOW(4, new Loadout()
{
@Override
public ItemStack getSword()
{
return new ItemStack(Material.STONE_SWORD, 1);
}
@Override
public ItemStack getRod()
{
return new ItemStack(Material.FISHING_ROD, 1);
}
@Override
public ItemStack getBow()
{
return new ItemStack(Material.BOW, 1);
}
@Override
public ItemStack getArrows()
{
return new ItemStack(Material.ARROW, 5);
}
@Override
public ItemStack getHelmet()
{
return new ItemStack(Material.GOLD_HELMET, 1);
}
@Override
public ItemStack getChestplate()
{
return new ItemStack(Material.GOLD_CHESTPLATE, 1);
}
@Override
public ItemStack getLeggings()
{
return new ItemStack(Material.GOLD_LEGGINGS, 1);
}
@Override
public ItemStack getBoots()
{
return new ItemStack(Material.GOLD_BOOTS, 1);
}
}),
GREEN(8, new Loadout()
{
@Override
public ItemStack getSword()
{
return new ItemStack(Material.WOOD_SWORD, 1);
}
@Override
public ItemStack getRod()
{
return new ItemStack(Material.FISHING_ROD, 1);
}
@Override
public ItemStack getBow()
{
return new ItemStack(Material.BOW, 1);
}
@Override
public ItemStack getArrows()
{
return new ItemStack(Material.ARROW, 3);
}
@Override
public ItemStack getHelmet()
{
return new ItemStack(Material.LEATHER_HELMET, 1);
}
@Override
public ItemStack getChestplate()
{
return new ItemStack(Material.LEATHER_CHESTPLATE, 1);
}
@Override
public ItemStack getLeggings()
{
return new ItemStack(Material.LEATHER_LEGGINGS, 1);
}
@Override
public ItemStack getBoots()
{
return new ItemStack(Material.LEATHER_BOOTS, 1);
}
});
private int _endsAt;
private Loadout _loadout;
ArenaType(int endsAt, Loadout loadout)
{
_endsAt = endsAt;
_loadout = loadout;
}
public Loadout getLoadout()
{
return _loadout;
}
public int getEndsAt()
{
return _endsAt;
}
public String getName()
{
return toString().toLowerCase();
}
public boolean furtherOut(ArenaType other)
{
return !(compareTo(other) <= 0);
}
}

View File

@ -0,0 +1,22 @@
package nautilus.game.arcade.game.games.gladiators;
import org.bukkit.inventory.ItemStack;
/**
* Created by William (WilliamTiger).
* 07/12/15
*/
public interface Loadout
{
public ItemStack getSword();
public ItemStack getRod();
public ItemStack getBow();
public ItemStack getArrows();
public ItemStack getHelmet();
public ItemStack getChestplate();
public ItemStack getLeggings();
public ItemStack getBoots();
}

View File

@ -0,0 +1,56 @@
package nautilus.game.arcade.game.games.gladiators;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public class ParticleData
{
public Player Player;
public Location CurrentLocation;
public Vector Velocity;
public Location Target;
public ParticleData(Player player, Location target)
{
Player = player;
Velocity = player.getLocation().getDirection();
if (Velocity.getY() < 0)
Velocity.setY(0);
Velocity.normalize();
CurrentLocation = player.getLocation().add(0, 1, 0);
Target = target;
}
public boolean update()
{
//Turn
Velocity.add(UtilAlg.getTrajectory(CurrentLocation, Target).multiply(0.15));
//Normalize Speed
UtilAlg.Normalize(Velocity);
//Move
CurrentLocation.add(Velocity.clone().multiply(0.5));
//Particle
UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, CurrentLocation, 0.03f, 0.03f, 0.03f, 0, 3,
UtilParticle.ViewDist.LONG, Player);
//Sound
CurrentLocation.getWorld().playSound(CurrentLocation, Sound.FIZZ, 0.2f, 3f);
return UtilMath.offset(CurrentLocation, Target) < 4;
}
}

View File

@ -0,0 +1,29 @@
package nautilus.game.arcade.game.games.gladiators;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public enum RoundState
{
WAITING("Waiting"),
STARTING_5("Starting in 5s"),
STARTING_4("Starting in 4s"),
STARTING_3("Starting in 3s"),
STARTING_2("Starting in 2s"),
STARTING_1("Starting in 1s"),
STARTED("FIGHT!"),
FIGHTING("Fighting");
private String scoreboardText;
RoundState(String scoreboardText)
{
this.scoreboardText = scoreboardText;
}
public String getScoreboardText()
{
return scoreboardText;
}
}

View File

@ -0,0 +1,53 @@
package nautilus.game.arcade.game.games.gladiators.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import nautilus.game.arcade.game.games.gladiators.Arena;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public class PlayerChangeArenaEvent extends Event
{
private static final HandlerList _handlers = new HandlerList();
private Player player;
private Arena to;
private Arena from;
public PlayerChangeArenaEvent(Player player, Arena to, Arena from)
{
this.player = player;
this.to = to;
this.from = from;
}
public Player getPlayer()
{
return player;
}
public Arena getTo()
{
return to;
}
public Arena getFrom()
{
return from;
}
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -0,0 +1,24 @@
package nautilus.game.arcade.game.games.gladiators.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class RoundStartEvent extends Event
{
private static final HandlerList _handlers = new HandlerList();
public static HandlerList getHandlerList()
{
return _handlers;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
}

View File

@ -0,0 +1,38 @@
package nautilus.game.arcade.game.games.gladiators.kits;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
/**
* Created by William (WilliamTiger).
* 07/12/15
*/
public class KitGladiator extends Kit
{
public KitGladiator(ArcadeManager manager)
{
super(manager, "Gladiator", KitAvailability.Free,
new String[]
{
"At my signal, unleash hell."
},
new Perk[]
{
},
EntityType.ZOMBIE, new ItemStack(Material.IRON_SWORD));
}
@Override
public void GiveItems(Player player)
{
//todo: items based on loadout
}
}

View File

@ -0,0 +1,39 @@
package nautilus.game.arcade.game.games.gladiators.trackers;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.stats.StatTracker;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public class BrawlerTracker extends StatTracker<Gladiators>
{
public BrawlerTracker(Gladiators game)
{
super(game);
}
@EventHandler
public void death(CombatDeathEvent e)
{
if (e.GetLog().GetKiller() == null)
return;
if (Bukkit.getPlayerExact(e.GetLog().GetKiller().GetName()) != null)
{
Player p = Bukkit.getPlayerExact(e.GetLog().GetKiller().GetName());
if (p.getItemInHand() == null)
return;
if (p.getItemInHand().getType().equals(Material.AIR))
addStat(p, "Brawler", 1, false, false);
}
}
}

View File

@ -0,0 +1,63 @@
package nautilus.game.arcade.game.games.gladiators.trackers;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.stats.StatTracker;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public class FlawlessTracker extends StatTracker<Gladiators>
{
private List<String> _noWin;
public FlawlessTracker(Gladiators game)
{
super(game);
_noWin = new ArrayList<>();
}
@EventHandler
public void onDmg(EntityDamageEvent e)
{
if (e.isCancelled())
return;
System.out.println(e.getEventName() + " took damage by " + e.getCause().toString());
if (e.getEntity() instanceof Player)
{
_noWin.add(((Player)e.getEntity()).getName());
}
}
@EventHandler
public void end(GameStateChangeEvent e)
{
if (e.GetState() != Game.GameState.End)
return;
if (getGame().getWinners() == null)
return;
for (Player p : getGame().getWinners())
{
if (_noWin.contains(p.getName()))
continue;
addStat(p, "Flawless", 1, true, false);
}
}
}

View File

@ -0,0 +1,79 @@
package nautilus.game.arcade.game.games.gladiators.trackers;
import java.util.HashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.stats.StatTracker;
/**
* Created by William (WilliamTiger).
* 08/12/15
*/
public class PrecisionTracker extends StatTracker<Gladiators>
{
private HashMap<String, Integer> _shot;
private HashMap<String, Integer> _hit;
public PrecisionTracker(Gladiators game)
{
super(game);
_shot = new HashMap<>();
_hit = new HashMap<>();
}
@EventHandler
public void end(GameStateChangeEvent e)
{
if (e.GetState() != Game.GameState.End)
return;
for (Player p : getGame().getWinners())
{
if (_shot.containsKey(p.getName()) && _hit.containsKey(p.getName()))
{
if (_shot.get(p.getName()) == _hit.get(p.getName()))
{
if (_shot.get(p.getName()) >= 3)
addStat(p, "Precision", 1, true, false);
}
}
}
}
@EventHandler
public void shoot(EntityShootBowEvent e)
{
if (!(e.getEntity() instanceof Player))
return;
Player p = (Player) e.getEntity();
if (_shot.containsKey(p.getName()))
_shot.put(p.getName(), _shot.get(p.getName()) + 1);
else
_shot.put(p.getName(), 1);
}
@EventHandler
public void hit(ProjectileHitEvent e)
{
if (e.getEntity().getShooter() instanceof Player)
{
Player p = (Player) e.getEntity().getShooter();
if (_hit.containsKey(p.getName()))
_hit.put(p.getName(), _hit.get(p.getName()) + 1);
else
_hit.put(p.getName(), 1);
}
}
}

View File

@ -0,0 +1,26 @@
package nautilus.game.arcade.game.games.gladiators.trackers;
import org.bukkit.event.EventHandler;
import nautilus.game.arcade.events.FirstBloodEvent;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.stats.StatTracker;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class SwiftKillTracker extends StatTracker<Gladiators>
{
public SwiftKillTracker(Gladiators game)
{
super(game);
}
@EventHandler
public void blood(FirstBloodEvent e)
{
addStat(e.getPlayer(), "SwiftKill", 1, false, false);
}
}

View File

@ -0,0 +1,55 @@
package nautilus.game.arcade.game.games.gladiators.trackers;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.game.games.gladiators.events.RoundStartEvent;
import nautilus.game.arcade.stats.StatTracker;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class UntouchableTracker extends StatTracker<Gladiators>
{
private List<String> _noWin;
public UntouchableTracker(Gladiators game)
{
super(game);
_noWin = new ArrayList<>();
}
@EventHandler
public void onDmg(EntityDamageEvent e)
{
if (e.isCancelled())
return;
if (e.getEntity() instanceof Player)
{
_noWin.add(((Player)e.getEntity()).getName());
}
}
@EventHandler
public void onEnd(RoundStartEvent e)
{
for (Player p : getGame().GetPlayers(true))
{
if (_noWin.contains(p.getName()))
continue;
addStat(p, "Untouchable", 1, false, false);
}
_noWin.clear();
}
}

View File

@ -0,0 +1,140 @@
package nautilus.game.arcade.game.games.gladiators.tutorial;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.gladiators.Arena;
import nautilus.game.arcade.game.games.gladiators.Gladiators;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class TutorialGladiators extends GameTutorial
{
private Gladiators _host;
private Location _pink, _orange;
private Zombie _zombie1, _zombie2;
private boolean hasHit1, hasHit2;
public TutorialGladiators(ArcadeManager manager)
{
super(manager, new TutorialPhase[]{
new TutorialPhaseGladiators()
});
TeleportOnEnd = false;
hasHit1 = false;
hasHit2 = false;
_host = (Gladiators) manager.GetGame();
}
public Location getPink()
{
return _pink;
}
public void setPink(Location pink)
{
_pink = pink;
}
public Location getOrange()
{
return _orange;
}
public void setOrange(Location orange)
{
_orange = orange;
}
public Zombie getZombie1()
{
return _zombie1;
}
public void setZombie1(Zombie zombie1)
{
_zombie1 = zombie1;
}
public Zombie getZombie2()
{
return _zombie2;
}
public void setZombie2(Zombie zombie2)
{
_zombie2 = zombie2;
}
public boolean isHasHit1()
{
return hasHit1;
}
public void setHasHit1(boolean hasHit1)
{
this.hasHit1 = hasHit1;
}
public boolean isHasHit2()
{
return hasHit2;
}
public void setHasHit2(boolean hasHit2)
{
this.hasHit2 = hasHit2;
}
@Override
public void onEnd()
{
Gladiators game = (Gladiators) Manager.GetGame();
for (Player p : game.GetPlayers(true))
{
p.teleport(game.GetTeam(p).GetSpawn().clone());
}
if (_zombie1 != null)
_zombie1.remove();
if (_zombie2 != null)
_zombie2.remove();
Arena gateArena = _host.getArenaByMid(getOrange());
for (Location loc : gateArena.getDoorBlocks())
loc.getBlock().setType(Material.FENCE); // Manual door close.
// Spawns
_host.GetTeamList().get(0).GetSpawns().clear();
for (Arena a : _host.getGameArenaSet())
{
if (a.getCapacity() <= 0)
continue;
for (Location l : a.capacitySpawns())
_host.GetTeamList().get(0).GetSpawns().add(l);
}
for (Player p : _host.GetPlayers(true))
{
_host.GetTeam(p).SpawnTeleport(p);
}
}
}

View File

@ -0,0 +1,26 @@
package nautilus.game.arcade.game.games.gladiators.tutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
import nautilus.game.arcade.gametutorial.TutorialText;
/**
* Created by William (WilliamTiger).
* 10/12/15
*/
public class TutorialPhaseGladiators extends TutorialPhase
{
public TutorialPhaseGladiators()
{
super(new TutorialText[]{
new TutorialText("Defeat your opponent!", 20 * 4, 1),
new TutorialText("", 20 * 2, 2),
});
}
@Override
public int ID()
{
return 1;
}
}

View File

@ -0,0 +1,252 @@
package nautilus.game.arcade.gametutorial;
import java.util.HashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.gametutorial.events.GameTutorialEndEvent;
import nautilus.game.arcade.gametutorial.events.GameTutorialPhaseEvent;
import nautilus.game.arcade.gametutorial.events.GameTutorialStartEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public abstract class GameTutorial
{
public ArcadeManager Manager;
private TutorialPhase[] _phases;
private GameTeam _team;
private HashMap<Player, Location> _players;
private TutorialPhase _currentPhase;
private boolean _hasEnded;
private boolean _hasStarted;
private int _tick;
private long _started;
public boolean SetTutorialPositions = true;
public boolean TeleportOnEnd = true;
public boolean RunTasksSync = true;
public boolean PlayTutorialSounds = false;
public boolean ShowPrepareTimer = false;
public long TimeBetweenPhase = 0;
public long StartAfterTutorial = 5000;
public GameTutorial(ArcadeManager manager, TutorialPhase[] phases)
{
Manager = manager;
_phases = phases;
_players = new HashMap<>();
}
final public void start()
{
_hasStarted = true;
_tick = 0;
for(TutorialPhase phase : _phases)
phase.setTutorial(this);
//Manager.GetGame().PrepareTime = 60000;
Manager.GetChat().Silence(60000, false);
_started = System.currentTimeMillis();
Manager.getPluginManager().callEvent(new GameTutorialStartEvent(this));
onStart();
preparePlayers();
_currentPhase = getNextPhase();
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
nextPhase(true);
}
}, 40);
_currentPhase.teleport();
}
protected void nextPhase(boolean phaseOne)
{
TutorialPhase from = _currentPhase;
if(!phaseOne)
_currentPhase = getNextPhase();
if(_currentPhase == null)
{
onEnd();
_hasEnded = true;
endTutorial();
final GameTutorial tutorial = this;
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
Manager.getPluginManager().callEvent(new GameTutorialEndEvent(tutorial));
}
}, 5);
}
else
{
Manager.GetChat().Silence(70000, false);
onPhaseChange(_currentPhase);
Manager.getPluginManager().callEvent(new GameTutorialPhaseEvent(this, from, _currentPhase));
_currentPhase.start(phaseOne);
}
}
public void setTeam(GameTeam team)
{
_team = team;
}
private void endTutorial()
{
for(final Player player : _players.keySet())
{
//VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers());
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
for(Player player : Manager.GetGame().GetPlayers(true))
{
for(Player other : Manager.GetGame().GetPlayers(true))
{
player.showPlayer(other);
}
}
player.setAllowFlight(false);
player.setFlying(false);
}
}, 5);
if(TeleportOnEnd)
{
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
_team.SpawnTeleport();
}
}, 5);
}
}
Manager.GetChat().Silence(StartAfterTutorial, false);
Manager.GetGame().PrepareTime = (System.currentTimeMillis() - Manager.GetGame().GetStateTime()) + StartAfterTutorial;
}
protected TutorialPhase getNextPhase()
{
for(TutorialPhase phase : _phases)
{
if(_currentPhase == null && phase.ID() == 1)
{
return phase;
}
else if(_currentPhase != null && _currentPhase.ID() + 1 == phase.ID())
{
return phase;
}
}
return null;
}
private void preparePlayers()
{
for(Player player : UtilServer.getPlayers())
{
int i = 0;
if(Manager.GetGame().GetTeam(player) == _team)
{
_players.put(player, Manager.GetGame().GetTeam(player).GetSpawns().get(i));
player.setAllowFlight(true);
player.setFlying(true);
// VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers());
i++;
}
}
}
public TutorialPhase getPhase(int index)
{
for(TutorialPhase phase : _phases)
{
if(phase.ID() == index)
return phase;
}
return null;
}
public boolean hasEnded()
{
return _hasEnded;
}
public boolean hasStarted()
{
return _hasStarted;
}
public HashMap<Player, Location> getPlayers()
{
return _players;
}
public GameTeam getTeam()
{
return _team;
}
public void onTick(int tick){}
public void onStart(){}
public void onPhaseChange(TutorialPhase phase){}
public void onEnd(){}
public int tick()
{
if(!_hasEnded && hasStarted())
{
for(Player player : UtilServer.getPlayers())
{
for(Player other : _players.keySet())
{
player.hidePlayer(other);
}
}
}
_tick++;
return _tick;
}
public TutorialPhase[] getPhases()
{
return _phases;
}
public long getTutorialStart()
{
return _started;
}
public long getRunning()
{
return System.currentTimeMillis() - _started;
}
public long getPhaseTime()
{
return _currentPhase.getPhaseTime();
}
}

View File

@ -0,0 +1,237 @@
package nautilus.game.arcade.gametutorial;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilTextMiddle;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public abstract class TutorialPhase
{
public abstract int ID();
private GameTutorial _tutorial;
private TutorialText[] _text;
private Location _location;
private Location _target;
private boolean _hasEnded;
private long _started;
private TutorialText _currentText;
public TutorialPhase(TutorialText[] text)
{
_text = text;
}
final public void start(boolean phaseOne)
{
_hasEnded = false;
_started = System.currentTimeMillis();
onStart();
if(!phaseOne)
{
teleport();
}
displayText();
}
final public void teleport()
{
if(!getTutorial().SetTutorialPositions)
return;
if(_location != null && _target != null)
{
prepareLocations();
updatePlayers();
}
}
private void prepareLocations()
{
Vector vector = new Vector(_target.getBlockX() - _location.getBlockX(), _target.getBlockY() - _location.getBlockY(), _target.getBlockZ() - _location.getBlockZ());
float pitch = UtilAlg.GetPitch(vector);
float yaw = UtilAlg.GetYaw(vector);
_location.setPitch(pitch);
_location.setYaw(yaw);
}
private void updatePlayers()
{
new Thread(new Runnable()
{
@Override
public void run()
{
while(!_hasEnded && !getTutorial().hasEnded())
{
_tutorial.Manager.runSync(new Runnable()
{
@Override
public void run()
{
if(!_hasEnded && !getTutorial().hasEnded())
{
for(Player player : _tutorial.getPlayers().keySet())
{
player.setAllowFlight(true);
player.setFlying(true);
player.teleport(_location);
}
}
}
});
try
{
Thread.sleep(50);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}).start();
}
public void displayText()
{
new Thread(new Runnable()
{
@Override
public void run()
{
while(true)
{
TutorialText text = getNextMessage();
if(text == null)
{
_tutorial.Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
_hasEnded = true;
onEnd();
_tutorial.nextPhase(false);
}
}, getTutorial().TimeBetweenPhase);
break;
}
else
{
Player[] players = new Player[_tutorial.getPlayers().keySet().size()];
int i = 0;
for(Player player : _tutorial.getPlayers().keySet())
{
if(_tutorial.PlayTutorialSounds)
{
if(text.getSound() != null)
player.playSound(player.getLocation(), text.getSound(), 2f, 2f);
}
players[i] = player;
i++;
}
displayMessage(text);
UtilTextMiddle.display("", text.getText(), 0, text.getStayTime(), 0, players);
try
{
Thread.sleep(text.getStayTime() * 50);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}).start();
}
private void displayMessage(final TutorialText text)
{
if(_tutorial.RunTasksSync)
{
_tutorial.Manager.runSync(new Runnable()
{
@Override
public void run()
{
onMessageDisplay(text);
}
});
}
else
{
onMessageDisplay(text);
}
}
protected TutorialText getNextMessage()
{
for(TutorialText text : _text)
{
if(_currentText == null && text.ID() == 1)
{
_currentText = text;
return text;
}
else if(_currentText != null && _currentText.ID() + 1 == text.ID())
{
_currentText = text;
return text;
}
}
return null;
}
public TutorialText[] getText()
{
return _text;
}
public Location getLocation()
{
return _location;
}
public void setTutorial(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public void setLocation(Location location)
{
_location = location;
}
public void setTarget(Location target)
{
_target = target;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public Location getTarget()
{
return _target;
}
public long getPhaseTime()
{
return _started;
}
public void onStart(){}
public void onMessageDisplay(TutorialText text){}
public void onEnd(){}
}

View File

@ -0,0 +1,62 @@
package nautilus.game.arcade.gametutorial;
import org.bukkit.Sound;
public class TutorialText
{
private String _text;
private int _stayTime;
private int _id;
private Sound _sound;
public TutorialText(String text, int stayTime, int id, Sound sound)
{
_text = text;
_id = id;
_stayTime = stayTime;
_sound = sound;
}
public TutorialText(String text, int id)
{
this(text, (int) (Math.round(1.5 * text.length()) + 25), id, Sound.NOTE_PLING);
}
public TutorialText(String text, int id, Sound sound)
{
this(text, (int) (Math.round(1.5 * text.length()) + 25), id, sound);
}
public TutorialText(String text, int stayTime, int id)
{
this(text, stayTime, id, Sound.NOTE_PLING);
}
public String getText()
{
return _text;
}
public int ID()
{
return _id;
}
public Sound getSound()
{
return _sound;
}
public int getStayTime()
{
return _stayTime;
}
public void setText(String text)
{
_text = text;
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialEndEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
public GameTutorialEndEvent(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
}

View File

@ -0,0 +1,49 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialPhaseEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
private TutorialPhase _from;
private TutorialPhase _to;
public GameTutorialPhaseEvent(GameTutorial tutorial, TutorialPhase from, TutorialPhase to)
{
_tutorial = tutorial;
_from = from;
_to = to;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
public TutorialPhase getFrom()
{
return _from;
}
public TutorialPhase getTo()
{
return _to;
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.gametutorial.events;
import nautilus.game.arcade.gametutorial.GameTutorial;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameTutorialStartEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private GameTutorial _tutorial;
public GameTutorialStartEvent(GameTutorial tutorial)
{
_tutorial = tutorial;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public GameTutorial getTutorial()
{
return _tutorial;
}
}

View File

@ -16,6 +16,7 @@ import mineplex.serverdata.Utility;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.FirstBloodEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerStateChangeEvent;
import nautilus.game.arcade.game.Game;
@ -77,6 +78,8 @@ public class GameGemManager implements Listener
{
game.AddGems(killer, 10, "First Blood", false, false);
Manager.getPluginManager().callEvent(new FirstBloodEvent(killer));
game.FirstKill = false;
game.Announce(F.main("Game", Manager.GetColor(killer) + killer.getName() + " drew first blood!"));

View File

@ -34,6 +34,9 @@ import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.gametutorial.GameTutorial;
import nautilus.game.arcade.gametutorial.TutorialPhase;
import nautilus.game.arcade.gametutorial.TutorialText;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -183,6 +186,75 @@ public class GameManager implements Listener
}
}
public boolean isInTutorial(boolean checkForTimer)
{
if (Manager.GetGame() == null || Manager.GetGame().GetState() != GameState.Prepare)
return false;
Game game = Manager.GetGame();
boolean tutorialSet = false;
for(GameTeam team : game.GetTeamList())
{
if(team.getTutorial() != null)
tutorialSet = true;
}
if(!tutorialSet)
{
game.addTutorials();
}
boolean finished = true;
if(game.EnableTutorials)
{
for(Player player : UtilServer.getPlayers())
{
if(player.getWorld() == Manager.GetLobby().GetSpawn().getWorld())
return true;
}
long prepTime = 0;
for(GameTeam team : game.GetTeamList())
{
long timeUsage = 0;
if(team.getTutorial() != null)
{
if(!team.getTutorial().hasStarted())
{
team.getTutorial().setTeam(team);
team.getTutorial().start();
timeUsage = team.getTutorial().StartAfterTutorial;
timeUsage = timeUsage + (team.getTutorial().TimeBetweenPhase * team.getTutorial().getPhases().length);
for(TutorialPhase phase : team.getTutorial().getPhases())
{
for(TutorialText text : phase.getText())
{
timeUsage = timeUsage + (text.getStayTime() * 50);
}
}
}
if(!team.getTutorial().hasEnded())
{
finished = false;
if(checkForTimer)
{
if(team.getTutorial().ShowPrepareTimer)
finished = false;
else
finished = true;
}
}
}
if(prepTime <= timeUsage)
prepTime = timeUsage;
}
if(prepTime > 0)
Manager.GetGame().PrepareTime = prepTime;
if(!finished)
return true;
}
return false;
}
@EventHandler
public void DisplayPrepareTime(UpdateEvent event)
{
@ -193,6 +265,9 @@ public class GameManager implements Listener
return;
Game game = Manager.GetGame();
if(isInTutorial(true))
return;
double percentage = (double) (System.currentTimeMillis() - game.GetStateTime()) / game.PrepareTime;
@ -200,6 +275,35 @@ public class GameManager implements Listener
UtilTextBottom.displayProgress("Game Start", percentage,
UtilTime.MakeStr(Math.max(0, game.PrepareTime - (System.currentTimeMillis() - game.GetStateTime()))), player);
}
@EventHandler
public void updateGameTutorials(UpdateEvent event)
{
if(event.getType() != UpdateType.TICK)
return;
Game game = Manager.GetGame();
if(game == null)
return;
if(game.GetState() != GameState.Prepare)
return;
if(game.EnableTutorials)
{
for(GameTeam team : game.GetTeamList())
{
if(team.getTutorial() != null)
{
if(!team.getTutorial().hasEnded() && team.getTutorial().hasStarted())
{
team.getTutorial().onTick(team.getTutorial().tick());
}
}
}
}
}
@EventHandler
public void StateUpdate(UpdateEvent event)
@ -247,6 +351,9 @@ public class GameManager implements Listener
}
else if (game.GetState() == GameState.Prepare)
{
if(isInTutorial(false))
return;
if (game.CanStartPrepareCountdown())
{
if (UtilTime.elapsed(game.GetStateTime(), game.PrepareTime))