Skip to content

Commit

Permalink
feat: moved tweak events to split file
Browse files Browse the repository at this point in the history
chore: moved from intellij idea to vscode
chore: commented all tweaks in config.yml
build: removed paperweight since it's not being used
build: added run-paper plugin for debugging purposes
  • Loading branch information
shockpast committed Jul 25, 2024
1 parent c547d3a commit 3fa4614
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true
charset = utf-8

[*.java]
indent_style = space
indent_size = 4
tab_width = 4
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ nb-configuration.xml
.nb-gradle/

### MacOS ###
.DS_Store
.DS_Store


###
run/
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.compile.nullAnalysis.mode": "automatic"
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "automatic"
}
21 changes: 14 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id("java")
id("io.papermc.paperweight.userdev") version "1.7.1"
// id("io.papermc.paperweight.userdev") version "1.7.1"
id("xyz.jpenilla.run-paper") version "2.3.0"
}

group = 'me.shockpast'
version = '1.0-SNAPSHOT'
group = "me.shockpast"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
Expand All @@ -21,7 +22,7 @@ repositories {
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")

paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
// paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
}

def targetJavaVersion = 21
Expand All @@ -36,8 +37,14 @@ java {
}
}

tasks {
runServer {
minecraftVersion("1.21")
}
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.encoding = "UTF-8"

if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
Expand All @@ -47,8 +54,8 @@ tasks.withType(JavaCompile).configureEach {
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('paper-plugin.yml') {
filteringCharset "UTF-8"
filesMatching("paper-plugin.yml") {
expand props
}
}
6 changes: 1 addition & 5 deletions src/main/java/me/shockpast/roflan/Roflan.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.shockpast.roflan.commands.*;
import me.shockpast.roflan.listeners.*;
import org.bukkit.Server;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -22,6 +21,7 @@ public void onEnable() {
//
pluginManager.registerEvents(new PlayerListener(this, data), this);
pluginManager.registerEvents(new EntityListener(this), this);
pluginManager.registerEvents(new TweakListener(this), this);

//
getCommand("vanish").setExecutor(new Vanish(this, data));
Expand All @@ -30,9 +30,5 @@ public void onEnable() {
getCommand("report").setExecutor(new Report(data));
getCommand("item").setExecutor(new Item());
getCommand("tweak").setExecutor(new Tweak(this));

// Additional Permissions
pluginManager.addPermission(new Permission("roflan.command.report.send"));
pluginManager.addPermission(new Permission("roflan.command.report.close"));
}
}
1 change: 1 addition & 0 deletions src/main/java/me/shockpast/roflan/commands/Tweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.shockpast.roflan.constants.Colors;
import net.kyori.adventure.text.Component;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/me/shockpast/roflan/listeners/TweakListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package me.shockpast.roflan.listeners;

import java.util.List;

import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;

import io.papermc.paper.event.player.PlayerItemCooldownEvent;

public class TweakListener implements Listener {
private final JavaPlugin plugin;
private final FileConfiguration config;

public TweakListener(JavaPlugin plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();
}

@EventHandler
public void creativeNetherWaterPlacement(PlayerBucketEmptyEvent event) {
if (!config.getBoolean("tweaks.creativeNetherWaterPlacement"))
return;

World world = event.getBlock().getWorld();
if (world.getEnvironment() != Environment.NETHER)
return;

Block block = event.getBlockClicked();
BlockFace blockFace = event.getBlockFace();

block.getRelative(blockFace)
.setType(Material.WATER);
}

@EventHandler
public void creativeNoItemCooldown(PlayerItemCooldownEvent event) {
if (!config.getBoolean("tweaks.creativeNoItemCooldown"))
return;

Player player = event.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE)
return;

event.setCooldown(0);
}

@EventHandler
public void creativeOpenContainerForcibly(PlayerInteractEvent event) {
if (!config.getBoolean("tweaks.creativeOpenContainerForcibly"))
return;

Player player = event.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE)
return;

Block block = event.getClickedBlock();
if (block == null)
return;
if (!(block.getState() instanceof Chest))
return;

Chest chest = (Chest)block.getState();
if (chest.isBlocked() || chest.isLocked()) {
player.openInventory(chest.getInventory());
player.setMetadata("creativeOpenContainerForcibly", new FixedMetadataValue(plugin, chest));

chest.open();
}
}

@EventHandler
public void creativeOpenContainerForcibly_InventoryClose(InventoryCloseEvent event) {
Player player = (Player)event.getPlayer();
if (player == null)
return;

List<MetadataValue> meta = player.getMetadata("creativeOpenContainerForcibly");
if (meta.isEmpty())
return;

Chest chest = (Chest)meta.getFirst().value();
chest.close();
}
}
14 changes: 13 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# fabric-carpet but made as paper plugin
tweaks:
explosionNoBlockDamage: false
# explosions will be cancelled at last tick
# so it won't actually explode anything
explosionNoBlockDamage: false
# water can be placed if player is in creative
# (in nether)
creativeNetherWaterPlacement: false
# removes any cooldown from items for players
# that are in creative
creativeNoItemCooldown: false
# players in creative will open containers
# regardless of it's block/lock state
creativeOpenContainerForcibly: false

0 comments on commit 3fa4614

Please sign in to comment.