Skip to content

Commit

Permalink
+config
Browse files Browse the repository at this point in the history
  • Loading branch information
7isenko committed Jun 25, 2020
0 parents commit 7088849
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 7isenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### EphemeralBlocks
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.github.7isenko</groupId>
<artifactId>EphemeralBlocks</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.github._7isenko.ephemeralblocks;

import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class BlockPlaceListener implements Listener {
private List<Material> safeList = parseConfigList();
private long ticksToBreak = EphemeralBlocks.config.getLong("timeToBreak") * 20;

@EventHandler
public void onPlace(BlockPlaceEvent event) {
if (safeList.contains(event.getBlockPlaced().getType()))
return;
Bukkit.getScheduler().runTaskLater(EphemeralBlocks.plugin, () -> {
try {
if (event.getBlockPlaced().getType() == Material.AIR)
return;
Block block = CraftMagicNumbers.getBlock(event.getBlockPlaced().getType());
SoundEffectType set = block.getBlockData().r();
Field f = set.getClass().getDeclaredField("z");
f.setAccessible(true);
SoundEffect se = (SoundEffect) f.get(set);
Location location = event.getBlockPlaced().getLocation();
BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
((CraftWorld) event.getPlayer().getWorld()).getHandle().playSound(null, bp, se, SoundCategory.BLOCKS, 1f, 1f);

} catch (Exception e) {
// ok fuck it
}
event.getBlockPlaced().breakNaturally();
}, ticksToBreak);
}

private List<Material> parseConfigList() {
List<String> strings = EphemeralBlocks.config.getStringList("unbreakableBlocks");
List<Material> materials = new ArrayList<>();
strings.forEach((s -> materials.add(Material.valueOf(s.toUpperCase()))));
return materials;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github._7isenko.ephemeralblocks;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public class EphemeralBlocks extends JavaPlugin {
// How to build: Maven/EphemeralBlocks/Lifecycle/package
public static Plugin plugin;
public static FileConfiguration config;

@Override
public void onEnable() {
this.saveDefaultConfig();
plugin = this;
config = this.getConfig();
this.getServer().getPluginManager().registerEvents(new BlockPlaceListener(), this);
}

@Override
public void onDisable() {
getLogger().info("Visit my github page https://github.com/7isenko");
}
}
14 changes: 14 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Values aren't validate, so any mistakes may cause crashes.
# Значения не проверяются, поэтому ошибки в них могут крашнуть плагин.

# Время, по прошествию которого блоки ломаются (в секундах)
# seconds
timeToBreak: 10

# Неломаемые блоки:
unbreakableBlocks:
- FURNACE
- CAMPFIRE
- BLAST_FURNACE
- SMOKER
- OBSIDIAN
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: EphemeralBlocks
version: "1.0"
api-version: "1.15"
author: 7isenko
main: io.github._7isenko.ephemeralblocks.EphemeralBlocks

0 comments on commit 7088849

Please sign in to comment.