Skip to content

Commit

Permalink
Merge pull request #2 from GreenSurvivors/keepInv
Browse files Browse the repository at this point in the history
Severall Bugfixes for gui and game elements;
Adding some new Game Elements like, potionFriendlyFire and gameTickTriggers.
  • Loading branch information
joshi1999 authored Oct 30, 2022
2 parents c87ed8e + 891bdb6 commit a41fc9b
Show file tree
Hide file tree
Showing 75 changed files with 827 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 17
- name: Build with Maven
run: mvn -B package --file pom.xml
18 changes: 16 additions & 2 deletions Minigames/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>au.com.mineauz</groupId>
<artifactId>MinigamesProject</artifactId>
<version>1.16-SNAPSHOT</version>
<version>1.19-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>Minigames</artifactId>
Expand Down Expand Up @@ -109,6 +109,12 @@
<artifactId>paste-gg-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down Expand Up @@ -141,7 +147,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.4.0</version>
<configuration>
<filters>
<filter>
Expand Down Expand Up @@ -221,6 +227,14 @@
<artifactId>versions-maven-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
67 changes: 63 additions & 4 deletions Minigames/src/main/java/au/com/mineauz/minigames/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.Predicate;

public class Events implements Listener {
private static Minigames plugin = Minigames.getPlugin();
Expand Down Expand Up @@ -86,6 +86,14 @@ public void onPlayerDeath(PlayerDeathEvent event) {
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (!mgm.hasDeathDrops()) {
if (mgm.keepInventory()) {
List<ItemStack> drops = Arrays.asList(ply.getPlayer().getInventory().getContents());
PlayerLoadout l = new PlayerLoadout("deathDrops");
for (int i = 0; i < drops.size(); i++) {
l.addItem(drops.get(i), i);
}
ply.setLoadout(l);
}
event.getDrops().clear();
}
String msg = "";
Expand Down Expand Up @@ -761,4 +769,55 @@ private void breakScoreboard(BlockBreakEvent event) {
}
}
}

@EventHandler(ignoreCancelled = true)
private void potionAffectsPlayer(PotionSplashEvent event) {
if (!(event.getPotion().getShooter() instanceof Player)) return;
MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getPotion().getShooter());
if (ply == null) return;
if (!ply.isInMinigame()) return;
if (ply.getMinigame().friendlyFireSplashPotions()) return;
List<Player> list = event.getAffectedEntities().stream()
.filter(p -> p instanceof Player)
.filter(p -> pdata.getMinigamePlayer((Player) p) != null)
.filter(p -> pdata.getMinigamePlayer((Player) p).isInMinigame())
.filter(p -> pdata.getMinigamePlayer((Player) p).getMinigame() == ply.getMinigame())
.map(p -> (Player) p)
.toList();
if (list.isEmpty()) return;
List<PotionEffectType> effects = event.getPotion().getEffects().stream().map(PotionEffect::getType).toList();
list.stream().filter(Predicate.not(p -> isEffectApplicable(effects, ply, pdata.getMinigamePlayer(p)))).forEach(p -> event.setIntensity(p, 0.0));
}

@EventHandler(ignoreCancelled = true)
private void effectAreaAffectsPlayer(AreaEffectCloudApplyEvent event) {
if (!(event.getEntity().getSource() instanceof Player)) return;
MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getEntity().getSource());
if (ply == null) return;
if (!ply.isInMinigame()) return;
if (ply.getMinigame().friendlyFireLingeringPotions()) return;
List<Player> list = event.getAffectedEntities().stream()
.filter(p -> p instanceof Player)
.filter(p -> pdata.getMinigamePlayer((Player) p) != null)
.filter(p -> pdata.getMinigamePlayer((Player) p).isInMinigame())
.filter(p -> pdata.getMinigamePlayer((Player) p).getMinigame() == ply.getMinigame())
.map(p -> (Player) p)
.toList();
if (list.isEmpty()) return;
List<PotionEffectType> effects = List.of(event.getEntity().getBasePotionData().getType().getEffectType());
event.getAffectedEntities().removeAll(list.stream().filter(Predicate.not(p -> isEffectApplicable(effects, ply, pdata.getMinigamePlayer(p)))).toList());
}

private boolean isEffectApplicable(Collection<PotionEffectType> effectTypes, MinigamePlayer ply, MinigamePlayer rPly) {
if (!ply.getMinigame().isTeamGame()) {
if (ply == rPly) {
return !MinigameTag.NEGATIVE_POTION.isTagged(effectTypes);
}
return !MinigameTag.POSITIVE_POTION.isTagged(effectTypes);
}
if (ply.getTeam() == rPly.getTeam()) {
return !MinigameTag.NEGATIVE_POTION.isTagged(effectTypes);
}
return !MinigameTag.POSITIVE_POTION.isTagged(effectTypes);
}
}
113 changes: 113 additions & 0 deletions Minigames/src/main/java/au/com/mineauz/minigames/MinigameTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package au.com.mineauz.minigames;

import org.bukkit.potion.PotionEffectType;

import java.util.Collection;
import java.util.List;

public interface MinigameTag<T> {

/**
* MinigameTag representing vanilla potions with negative effect(s).
* Also represents all potions with exclusive negative effects, which aren't in the value list.
*/
MinigameTag<Collection<PotionEffectType>> NEGATIVE_POTION = new MinigameTag() {

@Override
public boolean isTagged(Object item) {
List<PotionEffectType> list = getValues().stream().flatMap(Collection::stream).toList();
return ((Collection) item).stream().allMatch(list::contains);
}

@Override
public List<Collection<PotionEffectType>> getValues() {
List<Collection<PotionEffectType>> list = List.of(
List.of(PotionEffectType.SLOW),
List.of(PotionEffectType.HARM),
List.of(PotionEffectType.WEAKNESS),
List.of(PotionEffectType.POISON),
List.of(PotionEffectType.BLINDNESS),
List.of(PotionEffectType.BAD_OMEN),
List.of(PotionEffectType.CONFUSION),
List.of(PotionEffectType.DARKNESS),
List.of(PotionEffectType.GLOWING),
List.of(PotionEffectType.HUNGER),
List.of(PotionEffectType.LEVITATION),
List.of(PotionEffectType.SLOW_DIGGING),
List.of(PotionEffectType.UNLUCK),
List.of(PotionEffectType.WITHER)
);
return list;
}
};

/**
* MinigameTag representing vanilla potions with positive effect(s)
* Also represents all potions with exclusive positive effects, which aren't in the value list.
*/
MinigameTag<Collection<PotionEffectType>> POSITIVE_POTION = new MinigameTag<>() {
@Override
public boolean isTagged(Collection<PotionEffectType> item) {
List<PotionEffectType> list = getValues().stream().flatMap(Collection::stream).toList();
return ((Collection) item).stream().allMatch(list::contains);
}

@Override
public List<Collection<PotionEffectType>> getValues() {
List<Collection<PotionEffectType>> list = List.of(
List.of(PotionEffectType.FIRE_RESISTANCE),
List.of(PotionEffectType.LUCK),
List.of(PotionEffectType.HEAL),
List.of(PotionEffectType.NIGHT_VISION),
List.of(PotionEffectType.REGENERATION),
List.of(PotionEffectType.SLOW_FALLING),
List.of(PotionEffectType.SPEED),
List.of(PotionEffectType.JUMP),
List.of(PotionEffectType.INCREASE_DAMAGE),
List.of(PotionEffectType.INVISIBILITY),
List.of(PotionEffectType.WATER_BREATHING),
List.of(PotionEffectType.ABSORPTION),
List.of(PotionEffectType.DAMAGE_RESISTANCE),
List.of(PotionEffectType.CONDUIT_POWER),
List.of(PotionEffectType.DOLPHINS_GRACE),
List.of(PotionEffectType.FAST_DIGGING),
List.of(PotionEffectType.HEALTH_BOOST),
List.of(PotionEffectType.HERO_OF_THE_VILLAGE),
List.of(PotionEffectType.SATURATION)
);
return list;
}
};

/**
* MinigameTag representing vanilla potions with both, positive and negative, effects
*/
MinigameTag<Collection<PotionEffectType>> MIXED_POTION = new MinigameTag() {

@Override
public boolean isTagged(Object item) {
return getValues().contains(item);
}

@Override
public List<Collection<PotionEffectType>> getValues() {
List<Collection<PotionEffectType>> list = List.of(
List.of(PotionEffectType.SLOW, PotionEffectType.DAMAGE_RESISTANCE)
);
return list;
}
};

/**
* Returns whether this tag has an entry for the specified object
* @param item to check
* @return if it is tagged
*/
boolean isTagged(T item);

/**
* Returns a list of all tagged objects
* @return
*/
List<T> getValues();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.List;
import java.util.logging.Level;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

public class BackendCommand implements ICommand {
@Override
public String getName() {
Expand Down Expand Up @@ -77,7 +79,7 @@ public void onFailure(Throwable t) {
@Override
public void onSuccess(Void result) {
}
});
}, directExecutor());
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
}
Expand All @@ -97,7 +99,7 @@ public void onSuccess(Void result) {
sender.sendMessage(ChatColor.GOLD + "The backend has been successfully switched");
sender.sendMessage(ChatColor.GOLD + "!!! This change is " + ChatColor.BOLD + "temporary" + ChatColor.GOLD + ". Please update the config !!!");
}
});
}, directExecutor());
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Arrays;
import java.util.List;

import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

public class ScoreboardCommand implements ICommand {
private Minigames plugin = Minigames.getPlugin();

Expand Down Expand Up @@ -166,7 +168,7 @@ public void onFailure(Throwable t) {
sender.sendMessage(ChatColor.RED + "An internal error occured while loading the statistics");
t.printStackTrace();
}
});
}, directExecutor());

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import au.com.mineauz.minigames.display.IDisplayCubiod;
import au.com.mineauz.minigames.display.INonPersistantDisplay;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Player;
Expand All @@ -16,6 +17,8 @@ public class SpigotDisplayCuboid extends AbstractDisplayObject implements IDispl
private Vector minCorner;
private Vector maxCorner;

private int lastBarrier = 41;

public SpigotDisplayCuboid(DisplayManager manager, World world, Vector minCorner, Vector maxCorner) {
super(manager, world);
this.minCorner = minCorner;
Expand Down Expand Up @@ -72,15 +75,20 @@ public void refresh() {
}

private void placeEffectAt(double x, double y, double z) {
lastBarrier++;
if (lastBarrier < 41) {
return;
}
lastBarrier = 0;
temp.setX(x);
temp.setY(y);
temp.setZ(z);
temp.setWorld(getWorld());

if (player == null) {
getWorld().spawnParticle(Particle.BARRIER, temp, 1);
getWorld().spawnParticle(Particle.BLOCK_MARKER, temp, 1, 0, 0, 0, 0, Material.BARRIER.createBlockData());
} else {
player.spawnParticle(Particle.BARRIER, temp, 1);
player.spawnParticle(Particle.BLOCK_MARKER, temp, 1, 0, 0, 0, 0, Material.BARRIER.createBlockData());
}
}
}
Loading

0 comments on commit a41fc9b

Please sign in to comment.