Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/biel/lobby/GestorMapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ void checkNecessary(Joc map){
if(map.getEditMode())return;

if (map.getWorld().getPlayers().size() == 0){
if (map.JocEnMarxa()) map.JocFinalitzat();
removeMap(map);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/biel/lobby/lobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void onEnable(){

@Override
public void onDisable() {
// TODO Insert logic to be performed when the plugin is disabled
if (dataAPI != null) dataAPI.closeConnection();
HologramFacade.deleteAll();
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(cmd.getName().equalsIgnoreCase("prova")){
Expand Down
34 changes: 25 additions & 9 deletions src/main/java/com/biel/lobby/mapes/Joc.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,31 @@ public int segonsTranscorreguts(){
public void JocFinalitzat(){
if (!JocIniciat){Bukkit.broadcastMessage("S'ha intentat finalitzar una partida que no havia començat."); return;}
if (JocFinalitzat){Bukkit.broadcastMessage("S'ha intentat finalitzar una partida que ja havia acabat."); return;}
//---
world.setPVP(false);
customJocFinalitzat();
clearExternals();
if(!won)matchData.registerEnd(-1); //Tie / no winner
registerTimestamps(true);
//---
// Fence gameplay first. Cleanup and persistence failures must not leave a
// logically completed match running forever.
JocFinalitzat = true;
updateScoreBoards();
try {
if (world != null) world.setPVP(false);
customJocFinalitzat();
} catch (RuntimeException exception) {
Com.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
"Game-specific finalization failed for " + getGameName(), exception);
} finally {
clearExternals();
}
try {
if(!won && matchData != null) matchData.registerEnd(-1); //Tie / no winner
registerTimestamps(true);
} catch (RuntimeException exception) {
Com.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
"Could not persist final match state for " + getGameName(), exception);
}
try {
updateScoreBoards();
} catch (RuntimeException exception) {
Com.getPlugin().getLogger().log(java.util.logging.Level.WARNING,
"Could not update final scoreboards for " + getGameName(), exception);
}
}
public void winGame(Player p){ //TODO
if(won)return;
Expand Down Expand Up @@ -581,7 +597,7 @@ public ItemStack getSnowLauncher(int amount){
isSnowLauncherEnabled = true;
ItemStack ball = new ItemStack(Material.SNOWBALL);
ball.addUnsafeEnchantment(Enchantment.SILK_TOUCH, 1);
ball.setAmount(amount);
ball.setAmount(Math.max(1, amount));
return Utils.setItemNameAndLore(ball, "Llançador de neu", "Et transporta a l'enemic que impacti");
}
public boolean giveSnowLauncherOnKill(){
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/biel/lobby/mapes/MapaResetejable.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void cleanupStaleRuntimeWorlds() {
File dimensionsRoot = new File(new File(new File(worldContainer, "world"), "dimensions"), "minecraft");
for (File metadataDirectory : metadataDirectories) {
String worldName = metadataDirectory.getName();
if (!worldName.matches("[A-Za-z][A-Za-z0-9_-]*\\d+")) {
if (!worldName.matches("[A-Za-z][A-Za-z0-9 _-]*\\d+")) {
Com.getPlugin().getLogger().warning("Skipping unexpected live metadata directory: " + worldName);
continue;
}
Expand Down
67 changes: 66 additions & 1 deletion src/main/java/com/biel/lobby/mapes/jocs/Arena4.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,89 @@
package com.biel.lobby.mapes.jocs;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;

import com.biel.lobby.mapes.JocEquips;
import com.biel.lobby.utilities.ScoreBoardUpdater;

public class Arena4 extends JocEquips {
private static final long WRONG_TARGET_MESSAGE_COOLDOWN_MILLIS = 5_000L;
private final Map<UUID, Long> lastWrongTargetMessage = new HashMap<>();

@Override
protected void customJocIniciat() {
// TODO Auto-generated method stub
super.customJocIniciat();
setBlockBreakPlace(false);
sendGlobalMessage(ChatColor.GOLD + "Arena 4: each team hunts one marked target team.");
sendGlobalMessage(ChatColor.YELLOW + "RED hunts YELLOW, YELLOW hunts GREEN, GREEN hunts BLUE, and BLUE hunts RED.");
sendGlobalMessage(ChatColor.AQUA + "You deal 2x damage and earn 3 points against your target. You cannot damage the team hunting you; other kills earn 1 point.");
for (Player player : getPlayers()) {
Arena4Equip team = (Arena4Equip) obtenirEquip(player);
if (team == null) continue;
Arena4Equip target = (Arena4Equip) team.equipObjectiu();
Arena4Equip hunter = getHunterOf(team);
sendPlayerMessage(player, ChatColor.GREEN + "Your target: " + formatTeam(target)
+ ChatColor.GRAY + " | " + ChatColor.RED + "Your hunter: " + formatTeam(hunter));
}
}

@Override
protected void onPlayerDamageByPlayer(EntityDamageByEntityEvent evt, Player damaged, Player damager, boolean ranged) {
super.onPlayerDamageByPlayer(evt, damaged, damager, ranged);
if (evt.isCancelled()) return;
Arena4Equip attackerTeam = (Arena4Equip) obtenirEquip(damager);
Arena4Equip defenderTeam = (Arena4Equip) obtenirEquip(damaged);
if (attackerTeam == null || defenderTeam == null || attackerTeam == defenderTeam) return;

if (defenderTeam.equipObjectiu() == attackerTeam) {
evt.setCancelled(true);
sendWrongTargetMessage(damager, ChatColor.RED + "You cannot attack " + formatTeam(defenderTeam)
+ ChatColor.RED + "; they are hunting your team. Your target is "
+ formatTeam((Arena4Equip) attackerTeam.equipObjectiu()) + ChatColor.RED + ".");
return;
}
if (attackerTeam.equipObjectiu() == defenderTeam) {
evt.setDamage(evt.getDamage() * 2.0);
return;
}
sendWrongTargetMessage(damager, ChatColor.YELLOW + "Wrong target: " + formatTeam(defenderTeam)
+ ChatColor.YELLOW + " takes normal damage. Hunt "
+ formatTeam((Arena4Equip) attackerTeam.equipObjectiu())
+ ChatColor.YELLOW + " for 2x damage and 3 points.");
}

private Arena4Equip getHunterOf(Arena4Equip huntedTeam) {
for (Equip team : Equips) {
Arena4Equip arenaTeam = (Arena4Equip) team;
if (arenaTeam.equipObjectiu() == huntedTeam) return arenaTeam;
}
return null;
}

private String formatTeam(Arena4Equip team) {
if (team == null) return "unknown team";
return team.getChatColor() + team.getColor().name().toLowerCase(Locale.ROOT) + " team";
}

private void sendWrongTargetMessage(Player player, String message) {
long now = System.currentTimeMillis();
long lastMessage = lastWrongTargetMessage.getOrDefault(player.getUniqueId(), 0L);
if (now - lastMessage < WRONG_TARGET_MESSAGE_COOLDOWN_MILLIS) return;
lastWrongTargetMessage.put(player.getUniqueId(), now);
sendPlayerMessage(player, message);
}
@Override
public String getGameName() {
Expand Down Expand Up @@ -78,9 +142,10 @@ protected synchronized void gameEvent(Event event) {
PlayerDeathEvent evt = (PlayerDeathEvent)event;
Player killed = evt.getEntity();
Player killer = killed.getKiller();
if (killer == null){return;}
Arena4Equip eqKilled = (Arena4Equip) obtenirEquip(killed);
Arena4Equip eqKiller = (Arena4Equip) obtenirEquip(killer);
if (killer == null){return;}
if (eqKilled == null || eqKiller == null){return;}
if (areEnemies(killed, killer)){
int suma = 0;
int resta = 1;
Expand Down
56 changes: 43 additions & 13 deletions src/main/java/com/biel/lobby/mapes/jocs/InkWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -402,6 +403,9 @@ public void tick(){
public double getWeaponSpeedModifier(){
return 0;
}
public double getMaxHealth(){
return 20;
}
public int neededReloadTicks(){
return 50;
}
Expand Down Expand Up @@ -560,7 +564,6 @@ class MachinegunInkWeapon extends ProjectileInkWeapon{

public MachinegunInkWeapon(Player ply) {
super(ply);
ply.setMaxHealth(20);
}
@Override
public int getMaxLoad() {
Expand Down Expand Up @@ -613,10 +616,13 @@ protected void onPlayerDamageByPlayer(EntityDamageByEntityEvent evt,
class EnderInkWeapon extends ProjectileInkWeapon{
Player targeted;
int chargeTicks = 0;
int toolTicks = 0;
int toolTicks = -1;
public EnderInkWeapon(Player ply) {
super(ply);
ply.setMaxHealth(10);
}
@Override
public double getMaxHealth() {
return 10;
}
@Override
public int getMaxLoad() {
Expand Down Expand Up @@ -701,9 +707,9 @@ public void tick() {
super.tick();
if(toolTicks == 0){
getPlayer().getInventory().addItem(getToolMaterial());
toolTicks = 200000;
toolTicks = -1;
}
toolTicks--;
if(toolTicks > 0)toolTicks--;
if(chargeTicks > 0 && targeted != null){
rollerLinePaint(1.5 + (getWeaponLevel() / 3) + chargeTicks / (20 * 4), 1.2, targeted);

Expand Down Expand Up @@ -749,7 +755,10 @@ protected void onPlayerDeathByPlayer(PlayerDeathEvent evt,
class RollerInkWeapon extends InkWeapon{
public RollerInkWeapon(Player ply) {
super(ply);
ply.setMaxHealth(18);
}
@Override
public double getMaxHealth() {
return 18;
}
@Override
protected void onPlayerMove(PlayerMoveEvent evt, Player p) {
Expand Down Expand Up @@ -785,7 +794,10 @@ class BrushInkWeapon extends InkWeapon{
int charges = 0;
public BrushInkWeapon(Player ply) {
super(ply);
ply.setMaxHealth(18);
}
@Override
public double getMaxHealth() {
return 18;
}
@Override
protected void onPlayerMove(PlayerMoveEvent evt, Player p) {
Expand Down Expand Up @@ -826,6 +838,7 @@ public void tick() {
protected void onPlayerDamageByPlayer(EntityDamageByEntityEvent evt,
Player damaged, Player damager, boolean ranged) {
super.onPlayerDamageByPlayer(evt, damaged, damager, ranged);
if(damager != getPlayer())return;
if(!ranged && damager == getPlayer() && !damaged.hasPotionEffect(PotionEffectType.WITHER) && !evt.isCancelled()){
if(targeted == null)targeted = damaged;
if(targeted != damaged){
Expand All @@ -842,7 +855,7 @@ protected void onPlayerDamageByPlayer(EntityDamageByEntityEvent evt,
damaged.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, (int) Math.round(20 * (5 + 0.6 * getWeaponLevel())), Math.round(getWeaponLevel() + 2 / 5)), true);
getWorld().playSound(damaged.getEyeLocation(), Sound.ENTITY_GENERIC_SWIM, 1, 1.25F);
}
}else{evt.setCancelled(true);}
}else if(!evt.isCancelled()){evt.setCancelled(true);}
}
}

Expand Down Expand Up @@ -875,14 +888,19 @@ public void registerWeaponAlert(){
public int getWeaponAlerts() {
return weaponAlerts;
}
public boolean isShileded(){
public boolean isShielded(){
return getShieldTicks() > 0;
}
public int getShieldTicks() {
return shieldTicks;
}
public void setShieldTicks(int shieldTicks) {
this.shieldTicks = shieldTicks;
boolean shieldWasInactive = this.shieldTicks <= 0;
this.shieldTicks = Math.max(0, shieldTicks);
if(shieldWasInactive && this.shieldTicks > 0){
getWorld().spawnParticle(Particle.END_ROD, getPlayer().getLocation().add(0, 1, 0), 18, 0.5, 0.8, 0.5, 0.02);
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 0.7F, 1.6F);
}
}
@Override
public void ultraTick() {
Expand All @@ -900,7 +918,7 @@ public void ultraTick() {
setSpeedModifier(0);
}
if(b != null && teamOwningBlock != null){
boolean isOnItsColor = (teamOwningBlock == e) || isShileded();
boolean isOnItsColor = (teamOwningBlock == e) || isShielded();
boolean isHighInk = highInkBlocks.containsKey(b);
double speedMod = 0;
if(isOnItsColor){speedMod += 5;}else{speedMod += -5;}
Expand All @@ -926,7 +944,16 @@ public void ultraTick() {
dmgTicks = 0;
}
}
shieldTicks--;
if(shieldTicks > 0){
if(shieldTicks % 5 == 0){
getWorld().spawnParticle(Particle.END_ROD, getPlayer().getLocation().add(0, 1, 0), 3, 0.45, 0.65, 0.45, 0);
}
shieldTicks--;
if(shieldTicks == 0){
getWorld().spawnParticle(Particle.SMOKE, getPlayer().getLocation().add(0, 1, 0), 10, 0.4, 0.6, 0.4, 0.02);
getPlayer().playSound(getPlayer().getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.6F, 1.8F);
}
}
super.tick();
}
public void registerBlockPaint(EquipInkWars oldOwner){
Expand All @@ -950,7 +977,10 @@ public void setActiveWeapon(InkWeapon newWeapon) {
if (pW != null) {
pW.destroy();
}
double healthBeforeSwitch = getPlayer().getHealth();
getPlayer().setMaxHealth(newWeapon.getMaxHealth());
donarItemsInicials(getPlayer()); //Clears and gives starting (colored) armor
getPlayer().setHealth(Math.min(healthBeforeSwitch, getPlayer().getMaxHealth()));
this.activeWeapon = newWeapon;
this.activeWeapon.giveTool();
}
Expand Down Expand Up @@ -1003,7 +1033,7 @@ public void setOwnedBlocks(int ownedBlocks) {
this.ownedBlocks = ownedBlocks;
}
public void incrementOwnedBlocks(int increase){
setOwnedBlocks(getOwnedBlocks() + increase);
setOwnedBlocks(Math.max(0, getOwnedBlocks() + increase));
}
public double getOwnedPercent(){
if(getTotalPaintedBlocks() == 0)return 0;
Expand Down
Loading
Loading