forked from PaperMC/paperweight-test-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18ebfdf
commit 7a419f2
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...main/java/net/slqmy/template_paper_plugin/custom_multiblock/AbstractCustomMultiblock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.slqmy.template_paper_plugin.custom_multiblock; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.metadata.FixedMetadataValue; | ||
import org.bukkit.metadata.MetadataValue; | ||
|
||
import net.slqmy.template_paper_plugin.TemplatePaperPlugin; | ||
|
||
public abstract class AbstractCustomMultiblock implements Listener { | ||
|
||
private final TemplatePaperPlugin plugin; | ||
|
||
private final CustomMultiblock multiblockId; | ||
|
||
public AbstractCustomMultiblock(TemplatePaperPlugin plugin, CustomMultiblockManager customMultiblockManager, CustomMultiblock multiblockId) { | ||
this.plugin = plugin; | ||
|
||
this.multiblockId = multiblockId; | ||
|
||
Bukkit.getPluginManager().registerEvents(this, plugin); | ||
|
||
customMultiblockManager.addCustomMultiblock(multiblockId, this); | ||
} | ||
|
||
protected abstract List<Block> generateCustomMultiblock(Location placeLocation); | ||
|
||
public List<Block> getCustomMultiblock(Location placeLocation) { | ||
List<Block> multiblock = generateCustomMultiblock(placeLocation); | ||
|
||
for (Block block : multiblock) { | ||
block.setMetadata(plugin.getCustomMultiblockIdKey(), new FixedMetadataValue(plugin, multiblockId.name())); | ||
} | ||
|
||
return multiblock; | ||
} | ||
|
||
public boolean isBlock(Block block) { | ||
List<MetadataValue> values = block.getMetadata(plugin.getCustomMultiblockIdKey()); | ||
|
||
if (values.size() == 0) { | ||
return false; | ||
} | ||
|
||
return multiblockId.name().equals(values.get(0).asString()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.slqmy.template_paper_plugin.custom_multiblock; | ||
|
||
public enum CustomMultiblock { | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/net/slqmy/template_paper_plugin/custom_multiblock/CustomMultiblockManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.slqmy.template_paper_plugin.custom_multiblock; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.bukkit.Location; | ||
|
||
import net.slqmy.template_paper_plugin.custom_multiblock.AbstractCustomMultiblock; | ||
import net.slqmy.template_paper_plugin.custom_multiblock.CustomMultiblock; | ||
import net.slqmy.template_paper_plugin.TemplatePaperPlugin; | ||
|
||
public class CustomMultiblockManager { | ||
|
||
private final TemplatePaperPlugin plugin; | ||
|
||
private final Map<CustomMultiblock, AbstractCustomMultiblock> customMultiblockMap = new HashMap<>(); | ||
|
||
public CustomMultiblockManager(TemplatePaperPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void addCustomMultiblock(CustomMultiblock multiblockId, AbstractCustomMultiblock abstractCustomMultiblock) { | ||
customMultiblockMap.put(multiblockId, abstractCustomMultiblock); | ||
} | ||
|
||
public AbstractCustomMultiblock getAbstractCustomMultiblock(CustomMultiblock multiblockId) { | ||
return customMultiblockMap.get(multiblockId); | ||
} | ||
|
||
public void placeCustomMultiblock(CustomMultiblock multiblockId, Location location) { | ||
customMultiblockMap.get(multiblockId).getCustomMultiblock(location); | ||
} | ||
} |