Skip to content

Commit

Permalink
Wand item
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyDertan committed Aug 10, 2019
1 parent 46fb0bf commit 0876801
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>sergeydertan.sregionprotector</groupId>
<artifactId>SRegionProtector</artifactId>
<version>20.0</version>
<version>20.1</version>
<name>SRegionProtector</name>
<description>Flexible region protection plugin for nukkit</description>
<url>https://github.com/SergeyDertan/SRegionProtector</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerQuitEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemAxeWood;
import cn.nukkit.level.Position;

@SuppressWarnings("unused")
public final class SelectorEventsHandler implements Listener {

private final RegionSelector regionSelector;
private final Item wandItem;

public SelectorEventsHandler(RegionSelector selector) {
public SelectorEventsHandler(RegionSelector selector, Item wandItem) {
this.regionSelector = selector;
this.wandItem = wandItem;
}

@EventHandler
Expand All @@ -42,7 +43,7 @@ public void blockBreak(BlockBreakEvent e) {
}

private boolean selectPosition(Player player, Block pos, Item item) {
if (pos instanceof BlockAir || !(item instanceof ItemAxeWood)) return false;
if (item == null || pos instanceof BlockAir || !item.equals(this.wandItem, true, false)) return false;
if (!player.hasPermission("sregionprotector.wand")) return false;
SelectorSession session = this.regionSelector.getSession(player);
if (!session.setNextPos(Position.fromObject(pos, pos.level))) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void initChunks() {

private void initEventsHandlers() {
this.getServer().getPluginManager().registerEvents(new RegionEventsHandler(this.chunkManager, this.settings.regionSettings.flagsStatus, this.settings.regionSettings.needMessage, this.settings.prioritySystem, this.settings.protectedMessageType, this.settings.showParticle), this);
this.getServer().getPluginManager().registerEvents(new SelectorEventsHandler(this.regionSelector), this);
this.getServer().getPluginManager().registerEvents(new SelectorEventsHandler(this.regionSelector, this.settings.wandItem), this);
this.getServer().getPluginManager().registerEvents(new UIEventsHandler(this.settings.uiType), this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Sergey_Dertan.SRegionProtector.Provider.DataProvider;
import Sergey_Dertan.SRegionProtector.UI.UIType;
import cn.nukkit.block.Block;
import cn.nukkit.item.Item;
import cn.nukkit.utils.Config;

import java.util.Map;
Expand Down Expand Up @@ -54,6 +55,8 @@ public final class Settings {

public final boolean showParticle;

public final Item wandItem;

public Settings() throws Exception {
copyResource("config.yml", "resources/", MAIN_FOLDER, SRegionProtectorMain.class);
copyResource("mysql.yml", "resources/db", DB_FOLDER, SRegionProtectorMain.class);
Expand Down Expand Up @@ -108,6 +111,24 @@ public Settings() throws Exception {

this.provider = DataProvider.Type.fromString((String) config.get("provider"));

Object wand = config.get("wand-item");
if (wand instanceof String) {
if (border.split(":").length == 2) {
id = Integer.parseInt(border.split(":")[0]);
meta = Integer.parseInt(border.split(":")[1]);
} else {
id = Integer.parseInt(border);
meta = 0;
}
} else if (wand instanceof Number) {
meta = 0;
id = ((Number) wand).intValue();
} else {
throw new RuntimeException("Wrong wand item");
}

this.wandItem = Item.get(id, meta);

this.mySQLSettings = new MySQLSettings(new Config(DB_FOLDER + "mysql.yml", Config.YAML).getAll());
this.postgreSQLSettings = new PostgreSQLSettings(new Config(DB_FOLDER + "postgresql.yml", Config.YAML).getAll());
this.sqliteSettngs = new SQLiteSettings(new Config(DB_FOLDER + "sqlite.yml", Config.YAML).getString("database-file"));
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ priority-system: false

update-notifier: true

wand-item: "271:0"

#multithreaded regions loading
multithreaded-loading: true
multithreaded-loading-threads: -1
Expand Down

0 comments on commit 0876801

Please sign in to comment.