diff --git a/Plugins/Classpath.Dummy/src/net/minecraft/server/v1_7_R4/PacketPlayOutChat.java b/Plugins/Classpath.Dummy/src/net/minecraft/server/v1_7_R4/PacketPlayOutChat.java new file mode 100644 index 000000000..07537a12f --- /dev/null +++ b/Plugins/Classpath.Dummy/src/net/minecraft/server/v1_7_R4/PacketPlayOutChat.java @@ -0,0 +1,73 @@ +package net.minecraft.server.v1_7_R4; + +import java.io.IOException; + +public class PacketPlayOutChat + extends Packet +{ + private IChatBaseComponent a; + private boolean b; + private byte _chatType = 0; + + public PacketPlayOutChat() + { + this.b = true; + } + + public PacketPlayOutChat(IChatBaseComponent ichatbasecomponent) + { + this(ichatbasecomponent, true); + } + + public PacketPlayOutChat(IChatBaseComponent ichatbasecomponent, boolean flag) + { + this.b = true; + this.a = ichatbasecomponent; + this.b = flag; + } + + public PacketPlayOutChat(String text) + { + this(ChatSerializer.a(text)); + } + + public void a(PacketDataSerializer packetdataserializer) + throws IOException + { + this.a = ChatSerializer.a(packetdataserializer.c(32767)); + } + + public void b(PacketDataSerializer packetdataserializer) + throws IOException + { + packetdataserializer.a(ChatSerializer.a(this.a)); + if (packetdataserializer.version >= 16) { + packetdataserializer.writeByte(_chatType); + } + } + + public void setChatType(byte chatType) + { + _chatType = chatType; + } + + public void a(PacketPlayOutListener packetplayoutlistener) + { + packetplayoutlistener.a(this); + } + + public String b() + { + return String.format("message='%s'", new Object[] { this.a }); + } + + public boolean d() + { + return this.b; + } + + public void handle(PacketListener packetlistener) + { + a((PacketPlayOutListener)packetlistener); + } +} diff --git a/Plugins/Libraries/craftbukkit.jar b/Plugins/Libraries/craftbukkit.jar index 4000ffea7..6e642eb14 100644 Binary files a/Plugins/Libraries/craftbukkit.jar and b/Plugins/Libraries/craftbukkit.jar differ diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java index 428d3344e..a42d080fb 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java @@ -1,7 +1,11 @@ package mineplex.core.common.jsonchat; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_7_R4.ChatSerializer; +import net.minecraft.server.v1_7_R4.PacketPlayOutChat; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; public class JsonMessage @@ -63,4 +67,53 @@ public class JsonMessage { UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + player.getName() + " " + toString()); } + + /** + * Send a message to players using the new 1.8 message types + * + * @param messageType Message type to send + * @param players Players to send to + */ + public void send(MessageType messageType, Player... players) + { + send(messageType, false, players); + } + + /** + * Send a message to players using the new 1.8 message types + * + * @param messageType Message type to send + * @param defaultToChat Only applies to MessageType.ABOVE_HOTBAR. If true, it will send this to chat for 1.7 clients + * @param players Players to send to + */ + public void send(MessageType messageType, boolean defaultToChat, Player... players) + { + PacketPlayOutChat chatPacket = new PacketPlayOutChat(ChatSerializer.a(toString())); + chatPacket.setChatType(messageType.getId()); + + for (Player player : players) + { + if (defaultToChat || messageType != MessageType.ABOVE_HOTBAR || UtilPlayer.is1_8(player)) + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(chatPacket); + } + } + + public static enum MessageType + { + CHAT_BOX((byte) 0), // Inside Chat Box + SYSTEM_MESSAGE((byte) 1), // Inside Chat Box - This is used for the client to identify difference between chat message and server messages + ABOVE_HOTBAR((byte) 2); // Shows above hotbar + + private byte _id; + + MessageType(byte id) + { + _id = id; + } + + public byte getId() + { + return _id; + } + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java new file mode 100644 index 000000000..3f151a3ac --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java @@ -0,0 +1,51 @@ +package mineplex.core.donation; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; + +public class CoinCommand extends CommandBase +{ + public CoinCommand(DonationManager plugin) + { + super(plugin, Rank.ADMIN, "coin"); + } + + @Override + public void Execute(final Player caller, String[] args) + { + if (args.length < 2) + { + UtilPlayer.message(caller, F.main("Coin", "Missing Args")); + return; + } + + //Try Online + final Player target = UtilPlayer.searchOnline(caller, args[0], true); + + if (target == null) + return; + + //Give Coins to Target + try + { + final int coins = Integer.parseInt(args[1]); + Plugin.RewardCoins(new Callback() + { + public void run(Boolean completed) + { + UtilPlayer.message(caller, F.main("Coin", "You gave " + F.elem(coins + " Coins") + " to " + F.name(target.getName()) + ".")); + UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + ".")); + } + }, caller.getName(), target.getName(), target.getUniqueId(), coins); + } + catch (Exception e) + { + UtilPlayer.message(caller, F.main("Coin", "Invalid Coins Amount")); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index b9dc22e31..2d9f69b77 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -2,6 +2,11 @@ package mineplex.core.donation; import java.util.UUID; +import org.bukkit.craftbukkit.libs.com.google.gson.Gson; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + import mineplex.core.MiniPlugin; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; @@ -14,11 +19,6 @@ import mineplex.core.server.util.TransactionResponse; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import org.bukkit.craftbukkit.libs.com.google.gson.Gson; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.plugin.java.JavaPlugin; - public class DonationManager extends MiniPlugin { private DonationRepository _repository; @@ -42,6 +42,7 @@ public class DonationManager extends MiniPlugin public void AddCommands() { AddCommand(new GemCommand(this)); + AddCommand(new CoinCommand(this)); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/Npc.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/Npc.java index 3f4e0dd01..01590e771 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/npc/Npc.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/Npc.java @@ -29,8 +29,8 @@ public class Npc public void setEntity(LivingEntity entity) { - if (entity != null) - getNpcManager()._npcMap.remove(entity.getUniqueId()); + if (_entity != null) + getNpcManager()._npcMap.remove(_entity.getUniqueId()); _entity = entity; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java index b9661c984..818c4841e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java @@ -173,8 +173,7 @@ public class NpcManager extends MiniPlugin public boolean isDetachedNpc(LivingEntity entity) { - // Npc's name starts with ChatColor.RESET but it's missing from _npcMap - return !isNpc(entity) && entity.isCustomNameVisible() && (entity.getCustomName() == null || entity.getCustomName().startsWith(ChatColor.RESET.toString())); + return !isNpc(entity) && entity.getCustomName() != null && entity.getCustomName().startsWith(ChatColor.RESET.toString()); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @@ -302,16 +301,13 @@ public class NpcManager extends MiniPlugin LivingEntity entity = (LivingEntity) _creature.SpawnEntity(npc.getLocation(), EntityType.valueOf(npc.getDatabaseRecord().getEntityType())); entity.setCustomNameVisible(true); - if (npc.getDatabaseRecord().getName() != null) - { - String name = npc.getDatabaseRecord().getName(); - for (ChatColor color : ChatColor.values()) - name = name.replace("(" + color.name().toLowerCase() + ")", color.toString()); + String name = npc.getDatabaseRecord().getName() == null ? "" : npc.getDatabaseRecord().getName(); + for (ChatColor color : ChatColor.values()) + name = name.replace("(" + color.name().toLowerCase() + ")", color.toString()); - name = ChatColor.translateAlternateColorCodes('&', name); + name = ChatColor.translateAlternateColorCodes('&', name); - entity.setCustomName(ChatColor.RESET + name); - } + entity.setCustomName(ChatColor.RESET + name); entity.setCanPickupItems(false); entity.setRemoveWhenFarAway(false); @@ -521,6 +517,9 @@ public class NpcManager extends MiniPlugin if (event.getType() != UpdateType.SEC) return; + if (Bukkit.getOnlinePlayers().isEmpty()) + return; + for (World world : Bukkit.getWorlds()) { for (LivingEntity livingEntity : world.getEntitiesByClass(LivingEntity.class)) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java index b10c32986..8acf464c1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java @@ -1,13 +1,13 @@ package mineplex.core.shop.item; -import mineplex.core.common.util.UtilInv; -import net.minecraft.server.v1_7_R4.NBTTagList; -import net.minecraft.server.v1_7_R4.NBTTagString; - import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; +import net.minecraft.server.v1_7_R4.NBTTagList; +import net.minecraft.server.v1_7_R4.NBTTagString; + +import mineplex.core.common.util.UtilInv; public class ShopItem extends CraftItemStack { @@ -27,7 +27,8 @@ public class ShopItem extends CraftItemStack _displayItem = displayItem; _deliveryAmount = deliveryAmount; - getHandle().tag = ((CraftItemStack)itemStack).getHandle().tag; + CraftItemStack craftItem = CraftItemStack.asCraftCopy(itemStack); + getHandle().tag = craftItem.getHandle().tag; UpdateVisual(true); getHandle().tag.set("AttributeModifiers", new NBTTagList()); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 38793e994..fa1789a09 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -8,7 +8,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.server.ServerListPingEvent; import mineplex.core.MiniPlugin; import mineplex.core.common.Rank; @@ -240,7 +239,10 @@ public class NewsManager extends MiniPlugin { _newsIndex = (_newsIndex + 1)%_news.length; _newsTime = System.currentTimeMillis(); - } + +// JsonMessage jsonMessage = new JsonMessage(_news[_newsIndex]); +// jsonMessage.send(JsonMessage.MessageType.ABOVE_HOTBAR, UtilServer.getPlayers()); + } if (_newsIndex >= _news.length) { // Resets newsIndex if outside of bounds of news array after RefreshNews but before UtilTime.elapsed above diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index d35743540..ba35f2d1c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -88,7 +88,7 @@ public class ServerNpcPage extends ShopPageBase im ChatColor.RESET + C.cGreen + timeLeft + " Remaining...", ChatColor.RESET + "", ChatColor.RESET + C.cYellow + "Free players must wait a " + (beta ? "long" : "short") + " time", - ChatColor.RESET + C.cYellow + "to help lighten the load on our " + (beta ? "Beta" : "") + " servers.", + ChatColor.RESET + C.cYellow + "to help lighten the load on our" + (beta ? " Beta" : "") + " servers.", ChatColor.RESET + "", ChatColor.RESET + C.cAqua + "Ultra and Hero players have", ChatColor.RESET + C.cAqua + "instant access to our servers!", diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/BackupTask.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/BackupTask.java new file mode 100644 index 000000000..43052a30e --- /dev/null +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/BackupTask.java @@ -0,0 +1,90 @@ +package mineplex.mapparser; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.ZipUtil; + +/** + * Created by shaun on 14-09-23. + */ +public class BackupTask implements Runnable +{ + private final String _worldName; + private final Callback _callback; + private final JavaPlugin _plugin; + + public BackupTask(JavaPlugin plugin, String worldName, Callback callback) + { + _plugin = plugin; + _worldName = worldName; + _callback = callback; + + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, this); + } + + @Override + public void run() + { + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + List fileList = new ArrayList(); + List folderList = new ArrayList(); + String dest = "backup" + _worldName.substring(3) + "/" + format.format(date) + ".zip"; + File srcFile = new File(_worldName); + + // Create backup folder if it doesnt already exist + File folder = new File(dest.substring(0, dest.lastIndexOf('/'))); + if (!folder.exists()) + folder.mkdirs(); + + // Get all files to backup + for (File file : srcFile.listFiles()) + { + if (file.isFile()) + fileList.add(_worldName + File.separator + file.getName()); + else if (file.isDirectory()) + folderList.add(_worldName + File.separator + file.getName()); + } + + // Delete old folders if more than 20 backups exist + if (folder.listFiles().length > 20) + { + File[] files = folder.listFiles(); + File oldestFile = files[0]; + + for (int i = 1; i < files.length; i++) + { + File file = files[i]; + if (file.getName().endsWith(".zip") && file.lastModified() < oldestFile.lastModified()) + { + oldestFile = file; + } + } + + System.out.println("Deleting oldest file: " + oldestFile.getName()); + oldestFile.delete(); + } + + + ZipUtil.ZipFolders(srcFile.getAbsolutePath(), dest, folderList, fileList); + + if (_callback != null) + { + _plugin.getServer().getScheduler().runTask(_plugin, new Runnable() + { + @Override + public void run() + { + _callback.run(true); + } + }); + } + } +} diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java index 06b1e3599..077d353fd 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/MapParser.java @@ -3,6 +3,7 @@ package mineplex.mapparser; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -30,19 +31,19 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.MapUtil; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.mapparser.command.AdminCommand; import mineplex.mapparser.command.AuthorCommand; import mineplex.mapparser.command.BaseCommand; -import mineplex.mapparser.command.AdminCommand; import mineplex.mapparser.command.CopyCommand; import mineplex.mapparser.command.CopySchematicsCommand; import mineplex.mapparser.command.CreateCommand; @@ -60,22 +61,23 @@ import mineplex.mapparser.command.WorldsCommand; public class MapParser extends JavaPlugin implements Listener { private WorldManager _worldManager; - + private Parse _curParse = null; private HashMap _mapData = new HashMap(); + private HashSet _mapsBeingZipped = new HashSet(); private List _commands = new ArrayList(); private Location _spawnLocation; - + @Override public void onEnable() { _worldManager = new WorldManager(this); - + getServer().getPluginManager().registerEvents(this, this); - + getServer().getWorlds().get(0).setSpawnLocation(0, 106, 0); _spawnLocation = new Location(getServer().getWorlds().get(0), 0, 106, 0); - + //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Ticker(this), 1, 1); @@ -99,24 +101,24 @@ public class MapParser extends JavaPlugin implements Listener @Override public void onDisable() { - + } - + @EventHandler public void PlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - + player.teleport(getSpawnLocation()); - + ResetInventory(event.getPlayer()); - + DisplayHelp(player); - + for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) player.addAttachment(plugin, "worldedit.*", true); } - + public void DisplayHelp(Player player) { UtilPlayer.message(player, F.main("Parser", "Listing Commands;")); @@ -137,12 +139,12 @@ public class MapParser extends JavaPlugin implements Listener UtilPlayer.message(player, F.value("/map [gametype]", "Teleport to a map")); UtilPlayer.message(player, " "); UtilPlayer.message(player, C.cYellow + "Documentation: " + C.cGreen + "http://tinyurl.com/mpxmaps"); - + } - + @EventHandler public void Command(PlayerCommandPreprocessEvent event) - { + { Player player = event.getPlayer(); String[] parts = event.getMessage().split(" "); @@ -158,7 +160,7 @@ public class MapParser extends JavaPlugin implements Listener if (event.getMessage().toLowerCase().startsWith("/help")) { event.setCancelled(true); - + DisplayHelp(player); } @@ -200,13 +202,13 @@ public class MapParser extends JavaPlugin implements Listener { if (_curParse == null) return; - + if (_curParse.Update()) { Announce("Parse Completed!"); - + Announce("Cleaning and Creating ZIP..."); - + try { _worldManager.finalizeParsedWorld(_curParse.getWorld()); @@ -216,42 +218,42 @@ public class MapParser extends JavaPlugin implements Listener Announce("Creating ZIP Failed! Please Try Again!"); e.printStackTrace(); } - + _curParse = null; } } - + @EventHandler public void DisableCreatures(EntitySpawnEvent event) { if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntity() instanceof LivingEntity) event.setCancelled(true); } - + @EventHandler public void DisableBurn(BlockBurnEvent event) { event.setCancelled(true); } - + @EventHandler public void DisableFire(BlockSpreadEvent event) { event.setCancelled(true); } - + @EventHandler public void DisableFade(BlockFadeEvent event) { event.setCancelled(true); } - + @EventHandler public void DisableDecay(LeavesDecayEvent event) { event.setCancelled(true); } - + @EventHandler public void Updates(PlayerMoveEvent event) { @@ -263,16 +265,16 @@ public class MapParser extends JavaPlugin implements Listener world.setTime(8000); world.setStorm(false); } - - + + if (event.getPlayer().getGameMode() != GameMode.CREATIVE) event.getPlayer().setGameMode(GameMode.CREATIVE); } - + @EventHandler public void SaveUnloadWorlds(TickEvent event) { - for (World world : getServer().getWorlds()) + for (final World world : getServer().getWorlds()) { if (world.getName().equalsIgnoreCase("world")) continue; @@ -287,6 +289,18 @@ public class MapParser extends JavaPlugin implements Listener { Announce("Saving & Closing World: " + F.elem(world.getName())); MapUtil.UnloadWorld(this, world, true); + + _mapsBeingZipped.add(world.getName()); + System.out.println("Starting backup of " + world); + BackupTask backupTask = new BackupTask(this, world.getName(), new Callback() + { + @Override + public void run(Boolean data) + { + System.out.println("Finished backup of " + world); + _mapsBeingZipped.remove(world.getName()); + } + }); } } } @@ -488,6 +502,11 @@ public class MapParser extends JavaPlugin implements Listener } } + public HashSet getMapsBeingZipped() + { + return _mapsBeingZipped; + } + @EventHandler public void Join(PlayerJoinEvent event) { diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java index 9bb845b1b..490f4b8cf 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/MapCommand.java @@ -72,6 +72,12 @@ public class MapCommand extends BaseCommand worldName = getPlugin().getWorldString(args[0], gameType); } + if (getPlugin().getMapsBeingZipped().contains(worldName)) + { + message(player, "That map is being backed up now. Try again soon"); + return true; + } + World world = getPlugin().GetMapWorld(worldName); if (world == null) {