Skip to content

Commit

Permalink
Add configurable permission
Browse files Browse the repository at this point in the history
  • Loading branch information
cerus committed Mar 13, 2022
1 parent 36b4a96 commit 3941b4a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bukkit-16R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bukkit-17R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bukkit-18R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bukkit-18R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>dev.cerus.visualcrafting</groupId>
<version>1.0.1</version>
<version>1.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import dev.cerus.visualcrafting.v18r2.VersionAdapter18R2;
import java.io.File;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.permissions.Permissible;
import org.bukkit.plugin.java.JavaPlugin;

public class VisualCraftingPlugin extends JavaPlugin implements Config {
Expand Down Expand Up @@ -54,13 +56,22 @@ public void onEnable() {

final VisualizationController visualizationController = new VisualizationController(versionAdapter, textureCache);

this.getServer().getPluginManager().registerEvents(new CraftingListener(visualizationController), this);
this.getServer().getPluginManager().registerEvents(new CraftingListener(this, visualizationController), this);

this.getLogger().info("Visual Crafting was enabled!");
this.getLogger().info("Using version adapter '" + versionAdapter.getClass().getSimpleName() + "'");

// bStats
new Metrics(this, 14561);
final Metrics metrics = new Metrics(this, 14561);
metrics.addCustomChart(new SimplePie("enable_permission", () ->
this.getConfig().getBoolean("permission.enable", false) ? "True" : "False"));
metrics.addCustomChart(new SimplePie("enable_hitbox", () ->
this.getConfig().getBoolean("adjust-hitbox", false) ? "True" : "False"));
}

public boolean canUse(final Permissible permissible) {
return !this.getConfig().getBoolean("permission.enable", false)
|| permissible.hasPermission(this.getConfig().getString("permission.perm", ""));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.cerus.visualcrafting.plugin.listener;

import dev.cerus.visualcrafting.plugin.VisualCraftingPlugin;
import dev.cerus.visualcrafting.plugin.visualizer.VisualizationController;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -11,9 +12,11 @@

public class CraftingListener implements Listener {

private final VisualCraftingPlugin plugin;
private final VisualizationController visualizationController;

public CraftingListener(final VisualizationController visualizationController) {
public CraftingListener(final VisualCraftingPlugin plugin, final VisualizationController visualizationController) {
this.plugin = plugin;
this.visualizationController = visualizationController;
}

Expand All @@ -28,14 +31,15 @@ public void onPrepareCraft(final PrepareItemCraftEvent event) {
return;
}

final Player player = (Player) event.getView().getPlayer();
if (event.getRecipe() == null) {
// No recipe selected? Cancel crafting
this.visualizationController.craftingCancelled((Player) event.getView().getPlayer(), inv.getLocation().getBlock());
} else {
this.visualizationController.craftingCancelled(player, inv.getLocation().getBlock());
} else if (this.plugin.canUse(player)) {
// Recipe selected? Show item matrix
this.visualizationController.recipeSelected(inv.getMatrix(),
inv.getResult(),
(Player) event.getView().getPlayer(),
player,
inv.getLocation().getBlock());
}
}
Expand Down
6 changes: 5 additions & 1 deletion plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ map-id:
# Will move the frame's hitbox out of the way to allow players to
# access the crafting table from the top. This will only work on
# 1.16.5, unfortunately.
adjust-hitbox: false
adjust-hitbox: false

permission:
enable: false
perm: "my.cool.permission"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>dev.cerus.visualcrafting</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.1</version>
<version>1.0.2</version>
<modules>
<module>plugin</module>
<module>api</module>
Expand Down

0 comments on commit 3941b4a

Please sign in to comment.