This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This plugin is an HungerGames plugin working with PlugNAPI.
- Loading branch information
1 parent
f08aa6c
commit e9a22f6
Showing
14 changed files
with
828 additions
and
0 deletions.
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
HungerGames/src/fr/zabricraft/hungergames/HungerGames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Copyright (C) 2018 FALLET Nathan | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
package fr.zabricraft.hungergames; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.PluginManager; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.ProtocolLibrary; | ||
import com.comphenix.protocol.events.PacketContainer; | ||
import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; | ||
import com.comphenix.protocol.wrappers.WrappedChatComponent; | ||
|
||
import fr.zabricraft.hungergames.events.BlockBreak; | ||
import fr.zabricraft.hungergames.events.EntityDamage; | ||
import fr.zabricraft.hungergames.events.GameStart; | ||
import fr.zabricraft.hungergames.events.InventoryClick; | ||
import fr.zabricraft.hungergames.events.PlayerDeath; | ||
import fr.zabricraft.hungergames.events.PlayerInteract; | ||
import fr.zabricraft.hungergames.events.PlayerJoin; | ||
import fr.zabricraft.hungergames.events.PlayerQuit; | ||
import fr.zabricraft.hungergames.events.PlayerRespawn; | ||
import fr.zabricraft.hungergames.utils.ZabriPlayer; | ||
import fr.zabricraft.plugnapi.PlugNAPI; | ||
import fr.zabricraft.plugnapi.utils.ServerStatus; | ||
|
||
public class HungerGames extends JavaPlugin { | ||
|
||
private static HungerGames instance; | ||
|
||
public static HungerGames getInstance() { | ||
return instance; | ||
} | ||
|
||
private ArrayList<ZabriPlayer> players = new ArrayList<ZabriPlayer>(); | ||
private int countdown; | ||
|
||
public ZabriPlayer getPlayer(UUID uuid) { | ||
for (ZabriPlayer current : players) { | ||
if (current.getUuid().equals(uuid)) { | ||
return current; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void initPlayer(Player p) { | ||
players.add(new ZabriPlayer(p)); | ||
} | ||
|
||
public void uninitPlayer(ZabriPlayer p) { | ||
if (players.contains(p)) { | ||
players.remove(p); | ||
} | ||
} | ||
|
||
public int getCountdown() { | ||
return countdown; | ||
} | ||
|
||
public void onEnable() { | ||
instance = this; | ||
countdown = 61; | ||
|
||
Location spawn = Bukkit.getWorlds().get(0).getHighestBlockAt(0, 0).getLocation(); | ||
Bukkit.getWorlds().get(0).setSpawnLocation(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()); | ||
|
||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
initPlayer(p); | ||
} | ||
|
||
PluginManager pm = Bukkit.getPluginManager(); | ||
pm.registerEvents(new InventoryClick(), this); | ||
pm.registerEvents(new PlayerInteract(), this); | ||
pm.registerEvents(new PlayerJoin(), this); | ||
pm.registerEvents(new PlayerQuit(), this); | ||
pm.registerEvents(new PlayerDeath(), this); | ||
pm.registerEvents(new PlayerRespawn(), this); | ||
pm.registerEvents(new EntityDamage(), this); | ||
pm.registerEvents(new GameStart(), this); | ||
pm.registerEvents(new BlockBreak(), this); | ||
|
||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { | ||
@Override | ||
public void run() { | ||
if (PlugNAPI.getInstance().getStatus().equals(ServerStatus.PLAYING)) { | ||
if (countdown > 0) { | ||
countdown--; | ||
if (countdown == 0) { | ||
PacketContainer pc = new PacketContainer(PacketType.Play.Server.TITLE); | ||
pc.getTitleActions().write(0, TitleAction.TITLE); | ||
pc.getChatComponents().write(0, WrappedChatComponent.fromText("§aPvP activé")); | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
p.sendMessage("§eLe PvP est activé, bonne chance !"); | ||
try { | ||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, pc); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} else if (countdown == 60 || countdown == 30 || countdown == 20 || countdown == 10 | ||
|| countdown <= 5) { | ||
PacketContainer pc = new PacketContainer(PacketType.Play.Server.TITLE); | ||
pc.getTitleActions().write(0, TitleAction.TITLE); | ||
pc.getChatComponents().write(0, | ||
WrappedChatComponent.fromText("§aPvP activé dans " + countdown + "s")); | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
p.sendMessage("§eLe PvP sera activé dans " + countdown + " secondes !"); | ||
try { | ||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, pc); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
verifNext(); | ||
} | ||
} | ||
}, 0, 20); | ||
} | ||
|
||
public void onDisable() { | ||
players.clear(); | ||
} | ||
|
||
public ArrayList<UUID> getPlayers() { | ||
ArrayList<UUID> result = new ArrayList<UUID>(); | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
ZabriPlayer zp = HungerGames.getInstance().getPlayer(p.getUniqueId()); | ||
if (zp.isPlaying()) { | ||
result.add(p.getUniqueId()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public void verifNext() { | ||
int number = getPlayers().size(); | ||
if (number == 0) { | ||
PlugNAPI.getInstance().stop(null); | ||
} else if (number == 1) { | ||
PlugNAPI.getInstance().stop(Bukkit.getPlayer(getPlayers().get(0))); | ||
} | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
HungerGames/src/fr/zabricraft/hungergames/events/BlockBreak.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2018 FALLET Nathan | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
package fr.zabricraft.hungergames.events; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import fr.zabricraft.hungergames.HungerGames; | ||
import fr.zabricraft.hungergames.utils.Kit; | ||
import fr.zabricraft.hungergames.utils.ZabriPlayer; | ||
|
||
public class BlockBreak implements Listener { | ||
|
||
@EventHandler | ||
public void onBlockBreak(BlockBreakEvent e) { | ||
ZabriPlayer zp = HungerGames.getInstance().getPlayer(e.getPlayer().getUniqueId()); | ||
if (zp != null) { | ||
if (zp.getKit().equals(Kit.BUCHERON)) { | ||
breakTree(e.getBlock()); | ||
} else if (zp.getKit().equals(Kit.MINEUR)) { | ||
int multiplicateur = 1; | ||
if (e.getPlayer().getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) { | ||
multiplicateur = e.getPlayer().getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS); | ||
} | ||
if (e.getBlock().getType().equals(Material.COAL_ORE)) { | ||
e.setCancelled(true); | ||
e.getBlock().setType(Material.AIR); | ||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), | ||
new ItemStack(Material.COAL, 5 * multiplicateur)); | ||
} else if (e.getBlock().getType().equals(Material.IRON_ORE)) { | ||
e.setCancelled(true); | ||
e.getBlock().setType(Material.AIR); | ||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), | ||
new ItemStack(Material.IRON_INGOT, 3 * multiplicateur)); | ||
} else if (e.getBlock().getType().equals(Material.GOLD_ORE)) { | ||
e.setCancelled(true); | ||
e.getBlock().setType(Material.AIR); | ||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), | ||
new ItemStack(Material.GOLD_INGOT, 2 * multiplicateur)); | ||
} else if (e.getBlock().getType().equals(Material.DIAMOND_ORE)) { | ||
e.setCancelled(true); | ||
e.getBlock().setType(Material.AIR); | ||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), | ||
new ItemStack(Material.DIAMOND, 2 * multiplicateur)); | ||
} else if (e.getBlock().getType().equals(Material.EMERALD_ORE)) { | ||
e.setCancelled(true); | ||
e.getBlock().setType(Material.AIR); | ||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), | ||
new ItemStack(Material.EMERALD, 2 * multiplicateur)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void breakTree(Block block) { | ||
if (block.getType().equals(Material.LOG) || block.getType().equals(Material.LOG_2) | ||
|| block.getType().equals(Material.LEAVES)) { | ||
block.breakNaturally(); | ||
for (BlockFace f : BlockFace.values()) { | ||
Block b2 = block.getRelative(f); | ||
breakTree(b2); | ||
} | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
HungerGames/src/fr/zabricraft/hungergames/events/EntityDamage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2018 FALLET Nathan | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
package fr.zabricraft.hungergames.events; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
|
||
import fr.zabricraft.hungergames.HungerGames; | ||
|
||
public class EntityDamage implements Listener { | ||
|
||
@EventHandler | ||
public void onEntityDamage(EntityDamageEvent e) { | ||
if (e.getEntity() instanceof Player && HungerGames.getInstance().getCountdown() > 0) { | ||
e.setCancelled(true); | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
HungerGames/src/fr/zabricraft/hungergames/events/GameStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2018 FALLET Nathan | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
*/ | ||
|
||
package fr.zabricraft.hungergames.events; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import fr.zabricraft.hungergames.HungerGames; | ||
import fr.zabricraft.hungergames.utils.Kit; | ||
import fr.zabricraft.hungergames.utils.ZabriPlayer; | ||
import fr.zabricraft.plugnapi.utils.GameStartEvent; | ||
|
||
public class GameStart implements Listener { | ||
|
||
@EventHandler | ||
public void onGameStart(GameStartEvent e) { | ||
Location l = Bukkit.getWorlds().get(0).getHighestBlockAt(0, 0).getLocation().add(0, 10, 0); | ||
for (Player p : Bukkit.getOnlinePlayers()) { | ||
ZabriPlayer zp = HungerGames.getInstance().getPlayer(p.getUniqueId()); | ||
p.getInventory().clear(); | ||
p.getInventory().addItem(new ItemStack(Material.COMPASS)); | ||
Kit kit = zp.getKit(); | ||
if (kit != null) { | ||
p.getInventory().addItem(kit.getItems()); | ||
} | ||
p.updateInventory(); | ||
p.teleport(l); | ||
zp.setPlaying(true); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.