-
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.
Change map saving (untested for now)
Add longrifle and throwingjuice
- Loading branch information
1 parent
9cf1e9b
commit d49afba
Showing
5 changed files
with
393 additions
and
10 deletions.
There are no files selected for viewing
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
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
96 changes: 96 additions & 0 deletions
96
src/main/java/me/stephenminer/redvblue/arena/ArenaSaver.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,96 @@ | ||
package me.stephenminer.redvblue.arena; | ||
|
||
import me.stephenminer.redvblue.RedBlue; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ArenaSaver { | ||
private final RedBlue plugin; | ||
private final Arena arena; | ||
private List<BlockState> states; | ||
|
||
private final Location loc1,loc2; | ||
private boolean saving; | ||
private boolean loading; | ||
|
||
public ArenaSaver(Arena arena){ | ||
this.plugin = RedBlue.getPlugin(RedBlue.class); | ||
this.arena = arena; | ||
this.loc1 = arena.getLoc1(); | ||
this.loc2 = arena.getLoc2(); | ||
states = new ArrayList<>(); | ||
loading = false; | ||
} | ||
|
||
|
||
|
||
|
||
public void saveMap(){ | ||
saving = true; | ||
int maxX = maxX(); | ||
int maxY = maxY(); | ||
int maxZ = maxZ(); | ||
int minX = minX(); | ||
int minY = minY(); | ||
int minZ = minZ(); | ||
World world = loc1.getWorld(); | ||
for (int x = minX; x<= maxX; x++){ | ||
for (int y = minY; y<= maxY; y++){ | ||
for (int z = minZ; z <= maxZ; z++){ | ||
Block block = world.getBlockAt(x,y,z); | ||
states.add(block.getState()); | ||
} | ||
} | ||
} | ||
saving = false; | ||
} | ||
|
||
public void loadMap(){ | ||
int rate = 3000; | ||
loading = true; | ||
new BukkitRunnable(){ | ||
private int index = 0; | ||
private int countTo = getCountTo(index, rate); | ||
@Override | ||
public void run(){ | ||
for (int i = index; i <= countTo; i++){ | ||
BlockState state = states.get(index); | ||
state.update(true, false); | ||
} | ||
if (index >= states.size()-1){ | ||
arena.broadcast(ChatColor.GOLD + "" + ChatColor.BOLD + "Arena Finished Loading"); | ||
loading = false; | ||
this.cancel(); | ||
return; | ||
} | ||
index = countTo; | ||
countTo = Math.min(countTo+ rate, states.size()-1); | ||
} | ||
}.runTaskTimer(plugin, 1,1); | ||
} | ||
|
||
private int getCountTo(int index, int rate){ | ||
return Math.min(index + rate, states.size()-1); | ||
} | ||
|
||
public boolean isLoading(){ return loading; } | ||
public boolean isSaving(){ return saving; } | ||
|
||
|
||
public int maxX(){ return Math.max(loc1.getBlockX(), loc2.getBlockX()); } | ||
public int maxY(){ return Math.max(loc1.getBlockY(),loc2.getBlockY()); } | ||
public int maxZ(){ return Math.max(loc1.getBlockZ(), loc2.getBlockZ()); } | ||
|
||
public int minX(){ return Math.min(loc1.getBlockX(), loc2.getBlockX()); } | ||
public int minY(){ return Math.min(loc1.getBlockY(),loc2.getBlockY()); } | ||
public int minZ(){ return Math.min(loc1.getBlockZ(), loc2.getBlockZ()); } | ||
} |
124 changes: 124 additions & 0 deletions
124
src/main/java/me/stephenminer/redvblue/events/LongRifleUse.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,124 @@ | ||
package me.stephenminer.redvblue.events; | ||
|
||
import me.stephenminer.redvblue.RedBlue; | ||
import net.md_5.bungee.api.ChatMessageType; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import org.bukkit.*; | ||
import org.bukkit.entity.Arrow; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerChangedWorldEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
import org.bukkit.util.Vector; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class LongRifleUse implements Listener { | ||
private final RedBlue plugin; | ||
private final Set<UUID> cooldown; | ||
|
||
public LongRifleUse(RedBlue plugin){ | ||
this.plugin = plugin; | ||
cooldown = new HashSet<>(); | ||
} | ||
|
||
|
||
@EventHandler | ||
public void shootRifle(PlayerInteractEvent event){ | ||
if (!event.hasItem()) return; | ||
ItemStack item = event.getItem(); | ||
Player player = event.getPlayer(); | ||
if (cooldown.contains(player.getUniqueId())) { | ||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(net.md_5.bungee.api.ChatColor.AQUA + "Ability on Cooldown!")); | ||
return; | ||
} | ||
if (plugin.checkLore(item,"longrifle")){ | ||
boolean shoot = checkAndTakeAmmo(player); | ||
if (shoot) { | ||
fire(player); | ||
|
||
}else { | ||
player.sendMessage(ChatColor.RED + "You are missing mana-powder or arrows!"); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onQuit(PlayerQuitEvent event){ | ||
cooldown.remove(event.getPlayer().getUniqueId()); | ||
} | ||
@EventHandler | ||
public void onWorldChange(PlayerChangedWorldEvent event){ | ||
cooldown.remove(event.getPlayer().getUniqueId()); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
private boolean checkAndTakeAmmo(Player player){ | ||
ItemStack powder = null; | ||
ItemStack arrow = null; | ||
ItemStack[] items = player.getInventory().getContents(); | ||
for (ItemStack item : items){ | ||
if (plugin.checkLore(item,"manapowder")) { | ||
powder = item; | ||
continue; | ||
} | ||
Material mat = item.getType(); | ||
if (mat == Material.ARROW || mat == Material.TIPPED_ARROW || mat == Material.SPECTRAL_ARROW){ | ||
arrow = item; | ||
continue; | ||
} | ||
} | ||
if (powder == null || arrow == null) return false; | ||
powder.setAmount(powder.getAmount()-1); | ||
arrow.setAmount(arrow.getAmount()-1); | ||
return true; | ||
} | ||
|
||
private void fire(Player shooter){ | ||
Vector dir = shooter.getLocation().getDirection(); | ||
Arrow arrow = shooter.launchProjectile(Arrow.class,dir.clone().multiply(4)); | ||
arrow.setKnockbackStrength(3); | ||
World world = shooter.getWorld(); | ||
world.spawnParticle(Particle.ASH,shooter.getLocation().clone().add(dir),10); | ||
world.playSound(shooter.getLocation(), Sound.ENTITY_GENERIC_EXPLODE,2,1); | ||
} | ||
|
||
/** | ||
* | ||
* @param player | ||
* @param duration - time in ticks | ||
*/ | ||
private void runCooldown(Player player, int duration){ | ||
cooldown.add(player.getUniqueId()); | ||
float exp = player.getExp(); | ||
new BukkitRunnable(){ | ||
int count; | ||
@Override | ||
public void run(){ | ||
if (!player.isOnline() || player.isDead()){ | ||
this.cancel(); | ||
return; | ||
} | ||
if (count >= duration){ | ||
player.playSound(player,Sound.BLOCK_IRON_TRAPDOOR_CLOSE,1,1); | ||
player.setExp(exp); | ||
cooldown.remove(player.getUniqueId()); | ||
this.cancel(); | ||
return; | ||
} | ||
float ratio = ((float) count) / duration; | ||
player.setExp(ratio); | ||
count++; | ||
} | ||
}.runTaskTimer(plugin, 0, 1); | ||
} | ||
} |
Oops, something went wrong.