use of org.bukkit.inventory.ItemStack in project Minigames by AddstarMC.
the class OfflineMinigamePlayer method savePlayerData.
public void savePlayerData() {
MinigameSave save = new MinigameSave("playerdata/inventories/" + uuid.toString());
FileConfiguration con = save.getConfig();
if (storedItems != null) {
int num = 0;
for (ItemStack item : storedItems) {
if (item != null) {
con.set("items." + num, item);
}
num++;
}
}
if (storedArmour != null) {
int num = 0;
for (ItemStack item : storedArmour) {
if (item != null) {
con.set("armour." + num, item);
}
num++;
}
}
con.set("food", food);
con.set("saturation", saturation);
con.set("health", health);
con.set("gamemode", lastGM.toString());
con.set("exp", exp);
con.set("level", level);
if (loginLocation != null) {
con.set("location.x", loginLocation.getBlockX());
con.set("location.y", loginLocation.getBlockY());
con.set("location.z", loginLocation.getBlockZ());
con.set("location.yaw", loginLocation.getYaw());
con.set("location.pitch", loginLocation.getPitch());
con.set("location.world", loginLocation.getWorld().getName());
}
save.saveConfig();
}
use of org.bukkit.inventory.ItemStack in project Minigames by AddstarMC.
the class PlayerData method endMinigame.
public void endMinigame(Minigame minigame, List<MinigamePlayer> winners, List<MinigamePlayer> losers) {
EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
winners = event.getWinners();
losers = event.getLosers();
//Call Mechanics End
minigame.getMechanic().endMinigame(minigame, winners, losers);
//Prepare split money
double bets = 0;
if (minigame.getMpBets() != null) {
if (minigame.getMpBets().hasMoneyBets()) {
List<MinigamePlayer> plys = new ArrayList<MinigamePlayer>();
plys.addAll(event.getWinners());
if (!plys.isEmpty()) {
bets = minigame.getMpBets().claimMoneyBets() / (double) plys.size();
BigDecimal roundBets = new BigDecimal(bets);
roundBets = roundBets.setScale(2, BigDecimal.ROUND_HALF_UP);
bets = roundBets.doubleValue();
}
minigame.setMpBets(null);
}
}
//Broadcast Message
if (plugin.getConfig().getBoolean("broadcastCompletion") && minigame.isEnabled()) {
if (minigame.isTeamGame()) {
if (winners.size() > 0 || ((TeamsModule) minigame.getModule("Teams")).getDefaultWinner() != null) {
Team team;
if (winners.size() > 0)
team = winners.get(0).getTeam();
else
team = ((TeamsModule) minigame.getModule("Teams")).getTeam(((TeamsModule) minigame.getModule("Teams")).getDefaultWinner());
String score = "";
List<Team> teams = TeamsModule.getMinigameModule(minigame).getTeams();
for (Team t : teams) {
score += t.getColor().getColor().toString() + t.getScore();
if (t != teams.get(teams.size() - 1)) {
score += ChatColor.WHITE + " : ";
}
}
String nscore = ", " + MinigameUtils.formStr("player.end.team.score", score);
if (team.getScore() > 0) {
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.team.win", team.getChatColor() + team.getDisplayName() + ChatColor.WHITE, minigame.getName(true)) + nscore, minigame, ChatColor.GREEN);
} else {
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.team.win", team.getChatColor() + team.getDisplayName() + ChatColor.WHITE, minigame.getName(true)), minigame, ChatColor.GREEN);
}
} else {
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastNobodyWon", minigame.getName(true)), minigame, ChatColor.RED);
}
} else {
if (winners.size() == 1) {
String score = "";
if (winners.get(0).getScore() != 0)
score = MinigameUtils.formStr("player.end.broadcastScore", winners.get(0).getScore());
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastMsg", winners.get(0).getDisplayName(minigame.usePlayerDisplayNames()), minigame.getName(true)) + ". " + score, minigame, ChatColor.GREEN);
} else if (winners.size() > 1) {
String win = "";
Collections.sort(winners, new Comparator<MinigamePlayer>() {
@Override
public int compare(MinigamePlayer o1, MinigamePlayer o2) {
return Integer.valueOf(o1.getScore()).compareTo(o2.getScore());
}
});
for (MinigamePlayer pl : winners) {
if (winners.indexOf(pl) < 2) {
win += pl.getDisplayName(minigame.usePlayerDisplayNames());
if (winners.indexOf(pl) + 2 >= winners.size()) {
win += " and ";
} else {
win += ", ";
}
} else {
win += String.valueOf(winners.size() - 3) + " others";
}
}
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastMsg", win, minigame.getName(true)) + ". ", minigame, ChatColor.GREEN);
} else {
MinigameUtils.broadcast(MinigameUtils.formStr("player.end.broadcastNobodyWon", minigame.getName(true)), minigame, ChatColor.RED);
}
}
}
GameOverModule gom = GameOverModule.getMinigameModule(minigame);
boolean usedTimer = false;
gom.setWinners(winners);
gom.setLosers(losers);
if (gom.getTimer() > 0 && minigame.getType() == MinigameType.MULTIPLAYER) {
gom.startEndGameTimer();
usedTimer = true;
}
for (MinigamePlayer player : losers) {
player.setEndTime(System.currentTimeMillis());
if (!usedTimer)
quitMinigame(player, true);
PlayMGSound.playSound(player, MGSounds.getSound("lose"));
}
for (MinigamePlayer player : winners) {
player.setEndTime(System.currentTimeMillis());
StoredGameStats saveData = new StoredGameStats(minigame, player);
saveData.addStat(MinigameStats.Attempts, 1);
saveData.addStat(MinigameStats.Wins, 1);
saveData.addStat(MinigameStats.Kills, player.getKills());
saveData.addStat(MinigameStats.Deaths, player.getDeaths());
saveData.addStat(MinigameStats.Score, player.getScore());
saveData.addStat(MinigameStats.Reverts, player.getReverts());
saveData.addStat(MinigameStats.CompletionTime, player.getEndTime() - player.getStartTime() + player.getStoredTime());
for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
if (stat.doesApply(minigame, player, true)) {
saveData.addStat(stat, stat.getValue(minigame, player, true));
}
}
saveData.applySettings(minigame.getStatSettings(saveData));
if (!usedTimer)
quitMinigame(player, true);
//Group money bets
if (bets != 0) {
plugin.getEconomy().depositPlayer(player.getPlayer().getPlayer(), bets);
player.sendMessage(MinigameUtils.formStr("player.bet.winMoney", Minigames.plugin.getEconomy().format(bets)), null);
}
// Record player completion and give rewards
if (minigame.isEnabled()) {
plugin.queueStatSave(saveData, true);
} else {
MinigameUtils.debugMessage("Skipping SQL data save for " + saveData + "; minigame is disabled");
}
//Item Bets (for non groups)
if (minigame.getMpBets() != null) {
if (minigame.getMpBets().hasBets()) {
if (!player.isInMinigame())
player.getPlayer().getInventory().addItem(minigame.getMpBets().claimBets());
else {
for (ItemStack i : minigame.getMpBets().claimBets()) {
player.addTempRewardItem(i);
}
}
minigame.setMpBets(null);
}
}
PlayMGSound.playSound(player, MGSounds.getSound("win"));
}
if (!usedTimer) {
gom.clearLosers();
gom.clearWinners();
}
mdata.clearClaimedScore(minigame);
//Call Types End.
mdata.minigameType(minigame.getType()).endMinigame(winners, losers, minigame);
minigame.getScoreboardData().reload();
}
}
use of org.bukkit.inventory.ItemStack in project Minigames by AddstarMC.
the class PlayerData method joinMinigame.
public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
MinigameType type = minigame.getType();
JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
boolean canStart = minigame.getMechanic().checkCanStart(minigame, player);
if (!event.isCancelled()) {
if ((minigame.isEnabled() || player.getPlayer().hasPermission("minigame.join.disabled")) && (minigame.getState() == MinigameState.IDLE || minigame.getState() == MinigameState.OCCUPIED || minigame.getState() == MinigameState.WAITING || (minigame.getState() == MinigameState.STARTED && minigame.canLateJoin())) && /*!minigame.isRegenerating() &&
(!minigame.isNotWaitingForPlayers() || (minigame.canLateJoin() && minigame.getMpTimer().getPlayerWaitTimeLeft() == 0)) &&*/
(minigame.getStartLocations().size() > 0 || (minigame.isTeamGame() && TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) && minigame.getEndPosition() != null && minigame.getQuitPosition() != null && (minigame.getType() == MinigameType.SINGLEPLAYER || minigame.getLobbyPosition() != null) && ((type == MinigameType.SINGLEPLAYER && !minigame.isSpMaxPlayers()) || minigame.getPlayers().size() < minigame.getMaxPlayers()) && minigame.getMechanic().validTypes().contains(minigame.getType()) && canStart) {
//Do betting stuff
if (isBetting) {
if (minigame.getMpBets() == null && (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR || betAmount != 0)) {
minigame.setMpBets(new MultiplayerBets());
}
MultiplayerBets pbet = minigame.getMpBets();
ItemStack item = player.getPlayer().getInventory().getItemInMainHand().clone();
if (pbet != null && ((betAmount != 0 && pbet.canBet(player, betAmount) && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) >= betAmount) || (pbet.canBet(player, item) && item.getType() != Material.AIR && pbet.betValue(item.getType()) > 0))) {
player.sendMessage(MinigameUtils.getLang("player.bet.plyMsg"), null);
if (betAmount == 0) {
pbet.addBet(player, item);
} else {
pbet.addBet(player, betAmount);
plugin.getEconomy().withdrawPlayer(player.getPlayer().getPlayer(), betAmount);
}
player.getPlayer().getInventory().removeItem(new ItemStack(item.getType(), 1));
} else if (item.getType() == Material.AIR && betAmount == 0) {
player.sendMessage(MinigameUtils.getLang("player.bet.plyNoBet"), "error");
return;
} else if (betAmount != 0 && !pbet.canBet(player, betAmount)) {
player.sendMessage(MinigameUtils.getLang("player.bet.incorrectAmount"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.incorrectAmountInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
return;
} else if (betAmount != 0 && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) < betAmount) {
player.sendMessage(MinigameUtils.getLang("player.bet.notEnoughMoney"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.notEnoughMoneyInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
return;
} else {
player.sendMessage(MinigameUtils.getLang("player.bet.incorrectItem"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.incorrectItemInfo", 1, minigame.getMpBets().highestBetName()), "error");
return;
}
}
//Try teleport the player to their designated area.
boolean tpd = false;
if (type == MinigameType.SINGLEPLAYER) {
List<Location> locs = new ArrayList<Location>(minigame.getStartLocations());
Collections.shuffle(locs);
tpd = player.teleport(locs.get(0));
if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() && player.getPlayer().hasPermission("minigame.set.start")) {
player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Join location is across worlds! This may cause some server performance issues!", "error");
}
} else {
tpd = player.teleport(minigame.getLobbyPosition());
if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != minigame.getLobbyPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.lobby")) {
player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Lobby location is across worlds! This may cause some server performance issues!", "error");
}
}
if (!tpd) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
return;
}
//Give them the game type name
if (minigame.getGametypeName() == null)
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), "win");
else
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), "win");
//Give them the objective
if (minigame.getObjective() != null) {
player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
player.sendMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
}
//Prepare regeneration region for rollback.
if (minigame.getBlockRecorder().hasRegenArea() && !minigame.getBlockRecorder().hasCreatedRegenBlocks()) {
RecorderData d = minigame.getBlockRecorder();
d.setCreatedRegenBlocks(true);
Location cur = new Location(minigame.getRegenArea1().getWorld(), 0, 0, 0);
for (double y = d.getRegenMinY(); y <= d.getRegenMaxY(); y++) {
cur.setY(y);
for (double x = d.getRegenMinX(); x <= d.getRegenMaxX(); x++) {
cur.setX(x);
for (double z = d.getRegenMinZ(); z <= d.getRegenMaxZ(); z++) {
cur.setZ(z);
d.addBlock(cur.getBlock(), null);
}
}
}
}
//Standardize player
player.storePlayerData();
player.setMinigame(minigame);
minigame.addPlayer(player);
WeatherTimeModule.getMinigameModule(minigame).applyCustomTime(player);
WeatherTimeModule.getMinigameModule(minigame).applyCustomWeather(player);
player.setCheckpoint(player.getPlayer().getLocation());
player.getPlayer().setFallDistance(0);
player.getPlayer().setWalkSpeed(0.2f);
player.setStartTime(Calendar.getInstance().getTimeInMillis());
player.setGamemode(minigame.getDefaultGamemode());
if (minigame.getType() == MinigameType.SINGLEPLAYER) {
if (!minigame.isAllowedFlight()) {
player.setCanFly(false);
} else {
player.setCanFly(true);
if (minigame.isFlightEnabled())
player.getPlayer().setFlying(true);
}
} else {
player.getPlayer().setAllowFlight(false);
}
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
//Hide Spectators
for (MinigamePlayer pl : minigame.getSpectators()) {
player.getPlayer().hidePlayer(pl.getPlayer());
}
if (minigame.getPlayers().size() == 1) {
//Register regen recorder events
if (minigame.getBlockRecorder().hasRegenArea())
Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
WeatherTimeModule.getMinigameModule(minigame).startTimeLoop();
}
//Call Type specific join
mdata.minigameType(type).joinMinigame(player, minigame);
//Call Mechanic specific join
minigame.getMechanic().joinMinigame(minigame, player);
//Send other players the join message.
mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
player.updateInventory();
if (minigame.canDisplayScoreboard()) {
player.getPlayer().setScoreboard(minigame.getScoreboardManager());
minigame.setScore(player, 1);
minigame.setScore(player, 0);
}
} else if (!minigame.isEnabled()) {
player.sendMessage(MinigameUtils.getLang("minigame.error.notEnabled"), "error");
} else if (minigame.getState() == MinigameState.REGENERATING) {
player.sendMessage(MinigameUtils.getLang("minigame.error.regenerating"), "error");
} else if (minigame.getState() == MinigameState.STARTED && !minigame.canLateJoin()) {
player.sendMessage(MinigameUtils.getLang("minigame.started"), "error");
} else if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin() && minigame.getPlayers().size() != minigame.getMaxPlayers()) {
player.sendMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()), null);
} else if (minigame.getStartLocations().size() == 0 || (minigame.isTeamGame() && !TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noStart"), "error");
} else if (minigame.getEndPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), "error");
} else if (minigame.getQuitPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), "error");
} else if (minigame.getLobbyPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noLobby"), "error");
} else if (minigame.getPlayers().size() >= minigame.getMaxPlayers()) {
player.sendMessage(MinigameUtils.getLang("minigame.full"), "error");
} else if (!minigame.getMechanic().validTypes().contains(minigame.getType())) {
player.sendMessage(MinigameUtils.getLang("minigame.error.invalidMechanic"), "error");
} else if (!canStart) {
player.sendMessage(MinigameUtils.getLang("minigame.error.mechanicStartFail"), "error");
}
}
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class FakeItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
final Element elSlot = scriptEntry.getElement("slot");
Duration duration = scriptEntry.getdObject("duration");
final List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
final Element player_only = scriptEntry.getElement("player_only");
dB.report(scriptEntry, getName(), aH.debugList("items", items) + elSlot.debug() + duration.debug() + aH.debugList("players", players) + player_only.debug());
int slot = elSlot.asInt() - 1;
final boolean playerOnly = player_only.asBoolean();
final PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
for (dItem item : items) {
if (item == null) {
slot++;
continue;
}
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
packetHelper.setSlot(ent, translateSlot(ent, slot, playerOnly), item.getItemStack(), playerOnly);
}
final int slotSnapshot = slot;
slot++;
if (duration.getSeconds() > 0) {
DenizenCore.schedule(new OneTimeSchedulable(new Runnable() {
@Override
public void run() {
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
ItemStack original = ent.getOpenInventory().getItem(translateSlot(ent, slotSnapshot, playerOnly));
packetHelper.setSlot(ent, slotSnapshot, original, playerOnly);
}
}
}, (float) duration.getSeconds()));
}
}
}
use of org.bukkit.inventory.ItemStack in project Denizen-For-Bukkit by DenizenScript.
the class NBTCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dItem item = scriptEntry.getdObject("item");
Element key = scriptEntry.getElement("key");
Element value = scriptEntry.getElement("value");
dB.report(scriptEntry, getName(), item.debug() + key.debug() + value.debug());
ItemStack itemStack = item.getItemStack();
if (value.asString().equals("!")) {
itemStack = CustomNBT.removeCustomNBT(itemStack, key.asString(), CustomNBT.KEY_DENIZEN);
} else {
itemStack = CustomNBT.addCustomNBT(itemStack, key.asString(), value.asString(), CustomNBT.KEY_DENIZEN);
}
scriptEntry.addObject("new_item", new dItem(itemStack));
}
Aggregations