Skip to content

Commit

Permalink
✨ add spawn protections
Browse files Browse the repository at this point in the history
  • Loading branch information
jerembdn committed Jan 17, 2024
1 parent 7d1844c commit 3a48fa1
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 12 deletions.
9 changes: 7 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="src" path="bin/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/default"/>
</classpath>
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>folia-survival</name>
<name>viewing-party</name>
<comment>Project folia-survival created by Buildship.</comment>
<projects>
</projects>
Expand Down
10 changes: 5 additions & 5 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
arguments=--init-script /home/jijon/.vscode-server/data/User/globalStorage/stripe.vscode-stripe/2.0.14/config_linux/org.eclipse.osgi/51/0/.cp/gradle/init/init.gradle --init-script /home/jijon/.vscode-server/data/User/globalStorage/stripe.vscode-stripe/2.0.14/config_linux/org.eclipse.osgi/51/0/.cp/gradle/protobuf/init.gradle
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-17-openjdk-amd64
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
override.workspace.settings=false
show.console.view=false
show.executions.view=false
4 changes: 4 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=bin/generated-sources/annotations
org.eclipse.jdt.apt.genTestSrcDir=bin/generated-test-sources/annotations
6 changes: 6 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.source=17
Binary file modified bin/main/fr/thegreensuits/viewing_party/Main.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/java/fr/thegreensuits/viewing_party/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.bukkit.plugin.java.JavaPlugin;

import fr.thegreensuits.viewing_party.listener.AsyncPlayerChatListener;
import fr.thegreensuits.viewing_party.listener.EntityDamageListener;
import fr.thegreensuits.viewing_party.listener.PlayerInteractAtEntityListener;
import fr.thegreensuits.viewing_party.listener.PlayerJoinListener;
import fr.thegreensuits.viewing_party.listener.PlayerQuitListener;

Expand All @@ -20,6 +22,8 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new AsyncPlayerChatListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new EntityDamageListener(), INSTANCE);
getServer().getPluginManager().registerEvents(new PlayerInteractAtEntityListener(), INSTANCE);

getLogger().info("ViewingParty plugin enabled");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fr.thegreensuits.viewing_party.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;

public class EntityDamageListener implements Listener {
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
if(event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();

if(event.getCause() == EntityDamageEvent.DamageCause.VOID)
//Teleport to spawn when the player is too low
event.getEntity().teleport(event.getEntity().getWorld().getSpawnLocation());

if(!player.isOp()) {
event.setCancelled(true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.thegreensuits.viewing_party.listener;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;

public class PlayerInteractAtEntityListener implements Listener {
@EventHandler
public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) {
Player player = event.getPlayer();

if(!player.isOp()) {
event.setCancelled(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.thegreensuits.viewing_party.listener;

import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -8,11 +10,24 @@
public class PlayerJoinListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
event.setJoinMessage("§8[§b+§8] §b" + event.getPlayer().getDisplayName() + "§7 a rejoint le serveur !");
Player player = event.getPlayer();
Boolean isOp = player.isOp();

String color = event.getPlayer().isOp() ? c" : "§7";
event.setJoinMessage("§8[§b+§8] §b" + player.getDisplayName() + 7 a rejoint le serveur !");

event.getPlayer().setDisplayName(String.format("%s%s", color, event.getPlayer().getName()));
event.getPlayer().setPlayerListName(String.format("%s%s", color, event.getPlayer().getName()));
String color = isOp ? "§c" : "§7";

player.setDisplayName(String.format("%s%s", color, player.getName()));
player.setPlayerListName(String.format("%s%s", color, player.getName()));

player.setHealth(2.0);
player.setFoodLevel(20);
player.setExp(0);

if(!isOp) {
player.setGameMode(GameMode.ADVENTURE);
}

//TODO: TP to spawn on command
}
}

0 comments on commit 3a48fa1

Please sign in to comment.